Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions helper/chroot/chroot_posix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build !plan9 && !windows && !wasm

package chroot

type FileDescriptor interface {
Fd() (uintptr, bool)
}

// Fd exposes the underlying [os.File.Fd] func, which returns the
// system file descriptor or handle referencing the open file.
// If the underlying Filesystem does not expose this func,
// the return will always be (0, false).
func (f *file) Fd() (uintptr, bool) {
fd, ok := f.File.(FileDescriptor)
if ok {
return fd.Fd()
}
return 0, false
}
10 changes: 8 additions & 2 deletions osfs/os_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ func (f *file) Lock() error {
f.m.Lock()
defer f.m.Unlock()

return unix.Flock(int(f.Fd()), unix.LOCK_EX)
return unix.Flock(int(f.File.Fd()), unix.LOCK_EX)
}

func (f *file) Unlock() error {
f.m.Lock()
defer f.m.Unlock()

return unix.Flock(int(f.Fd()), unix.LOCK_UN)
return unix.Flock(int(f.File.Fd()), unix.LOCK_UN)
}

func (f *file) Sync() error {
Expand All @@ -39,3 +39,9 @@ func umask(m int) func() {
syscall.Umask(old)
}
}

// Fd exposes the underlying [os.File.Fd] func, which returns the
// system file descriptor or handle referencing the open file.
func (f *file) Fd() (uintptr, bool) {
return f.File.Fd(), true
}