5
5
package fdfs
6
6
7
7
import (
8
+ "fmt"
8
9
"io/fs"
9
10
"os"
10
11
@@ -43,15 +44,17 @@ func (s *FS) Open(path string) (fs.File, error) {
43
44
Resolve : resolveFlags ,
44
45
})
45
46
if err != nil {
46
- return nil , err
47
+ return nil , fmt . Errorf ( "openat2(%d, %q): %w" , s . file . Fd (), path , err )
47
48
}
48
- f := os .NewFile (uintptr (fd ), path )
49
- return f , nil
49
+ return os .NewFile (uintptr (fd ), path ), nil
50
50
}
51
51
52
52
// Lchown wraps fchownat(2) (with AT_SYMLINK_NOFOLLOW).
53
53
func (s * FS ) Lchown (path string , uid , gid int ) error {
54
- return unix .Fchownat (int (s .file .Fd ()), path , uid , gid , unix .AT_SYMLINK_NOFOLLOW )
54
+ if err := unix .Fchownat (int (s .file .Fd ()), path , uid , gid , unix .AT_SYMLINK_NOFOLLOW ); err != nil {
55
+ return fmt .Errorf ("fchownat(%d, %q, %d, %d): %w" , s .file .Fd (), path , uid , gid , err )
56
+ }
57
+ return nil
55
58
}
56
59
57
60
// Sub wraps openat2(2) (with O_RDONLY+O_DIRECTORY+O_NOFOLLOW+O_CLOEXEC), and
@@ -63,7 +66,7 @@ func (s *FS) Sub(dir string) (*FS, error) {
63
66
Resolve : resolveFlags ,
64
67
})
65
68
if err != nil {
66
- return nil , err
69
+ return nil , fmt . Errorf ( "openat2(%d, %q): %w" , s . file . Fd (), dir , err )
67
70
}
68
71
return & FS {os .NewFile (uintptr (fd ), dir )}, nil
69
72
}
@@ -105,7 +108,8 @@ func (s *FS) RecursiveChown(uid, gid int) error {
105
108
continue
106
109
}
107
110
108
- // Make sure we're not about to recurse on a symlink.
111
+ // Defensively check we're not about to recurse on a symlink.
112
+ // (The openat2 call in s.Sub will block it anyway.)
109
113
if d .Type ()& fs .ModeSymlink != 0 {
110
114
continue
111
115
}
0 commit comments