Skip to content

Commit

Permalink
Improved OPEN_NOFOLLOW.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Sep 27, 2024
1 parent 4e0b8ae commit 08f7764
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ type Conn struct {
handle uint32
}

// Open calls [OpenFlags] with [OPEN_READWRITE], [OPEN_CREATE], [OPEN_URI] and [OPEN_NOFOLLOW].
// Open calls [OpenFlags] with [OPEN_READWRITE], [OPEN_CREATE] and [OPEN_URI].
func Open(filename string) (*Conn, error) {
return newConn(filename, OPEN_READWRITE|OPEN_CREATE|OPEN_URI|OPEN_NOFOLLOW)
return newConn(filename, OPEN_READWRITE|OPEN_CREATE|OPEN_URI)
}

// OpenFlags opens an SQLite database file as specified by the filename argument.
Expand Down
2 changes: 1 addition & 1 deletion util/osutil/open_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error) {
if name == "" {
return nil, &os.PathError{Op: "open", Path: name, Err: ENOENT}
}
r, e := syscallOpen(name, flag, uint32(perm.Perm()))
r, e := syscallOpen(name, flag|O_CLOEXEC, uint32(perm.Perm()))
if e != nil {
return nil, &os.PathError{Op: "open", Path: name, Err: e}
}
Expand Down
19 changes: 10 additions & 9 deletions vfs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ func (vfsOS) FullPathname(path string) (string, error) {
if err != nil {
return "", err
}
fi, err := os.Lstat(path)
return path, testSymlinks(filepath.Dir(path))
}

func testSymlinks(path string) error {
p, err := filepath.EvalSymlinks(path)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return path, nil
}
return "", err
return err
}
if fi.Mode()&fs.ModeSymlink != 0 {
err = _OK_SYMLINK
if p != path {
return _OK_SYMLINK
}
return path, err
return nil
}

func (vfsOS) Delete(path string, syncDir bool) error {
Expand Down Expand Up @@ -74,7 +75,7 @@ func (vfsOS) Open(name string, flags OpenFlag) (File, OpenFlag, error) {
}

func (vfsOS) OpenFilename(name *Filename, flags OpenFlag) (File, OpenFlag, error) {
var oflags int
oflags := _O_NOFOLLOW
if flags&OPEN_EXCLUSIVE != 0 {
oflags |= os.O_EXCL
}
Expand Down
11 changes: 11 additions & 0 deletions vfs/os_std_access.go → vfs/os_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
)

const _O_NOFOLLOW = 0

func osAccess(path string, flags AccessFlag) error {
fi, err := os.Stat(path)
if err != nil {
Expand Down Expand Up @@ -34,3 +36,12 @@ func osAccess(path string, flags AccessFlag) error {
}
return nil
}

func osSetMode(file *os.File, modeof string) error {
fi, err := os.Stat(modeof)
if err != nil {
return err
}
file.Chmod(fi.Mode())
return nil
}
14 changes: 0 additions & 14 deletions vfs/os_std_mode.go

This file was deleted.

2 changes: 2 additions & 0 deletions vfs/os_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"golang.org/x/sys/unix"
)

const _O_NOFOLLOW = unix.O_NOFOLLOW

func osAccess(path string, flags AccessFlag) error {
var access uint32 // unix.F_OK
switch flags {
Expand Down

0 comments on commit 08f7764

Please sign in to comment.