File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 1+ //go:build !plan9 && !windows && !wasm
2+
3+ package chroot
4+
5+ type FileDescriptor interface {
6+ Fd () (uintptr , bool )
7+ }
8+
9+ // Fd exposes the underlying [os.File.Fd] func, which returns the
10+ // system file descriptor or handle referencing the open file.
11+ // If the underlying Filesystem does not expose this func,
12+ // the return will always be (0, false).
13+ func (f * file ) Fd () (uintptr , bool ) {
14+ fd , ok := f .File .(FileDescriptor )
15+ if ok {
16+ return fd .Fd ()
17+ }
18+ return 0 , false
19+ }
Original file line number Diff line number Diff line change @@ -13,14 +13,14 @@ func (f *file) Lock() error {
1313 f .m .Lock ()
1414 defer f .m .Unlock ()
1515
16- return unix .Flock (int (f .Fd ()), unix .LOCK_EX )
16+ return unix .Flock (int (f .File . Fd ()), unix .LOCK_EX )
1717}
1818
1919func (f * file ) Unlock () error {
2020 f .m .Lock ()
2121 defer f .m .Unlock ()
2222
23- return unix .Flock (int (f .Fd ()), unix .LOCK_UN )
23+ return unix .Flock (int (f .File . Fd ()), unix .LOCK_UN )
2424}
2525
2626func (f * file ) Sync () error {
@@ -39,3 +39,9 @@ func umask(m int) func() {
3939 syscall .Umask (old )
4040 }
4141}
42+
43+ // Fd exposes the underlying [os.File.Fd] func, which returns the
44+ // system file descriptor or handle referencing the open file.
45+ func (f * file ) Fd () (uintptr , bool ) {
46+ return f .File .Fd (), true
47+ }
You can’t perform that action at this time.
0 commit comments