Skip to content

Commit b1f5145

Browse files
committed
Better error values, extra comment
1 parent d7280ce commit b1f5145

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

internal/fixperms/fdfs/fdfs.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package fdfs
66

77
import (
8+
"fmt"
89
"io/fs"
910
"os"
1011

@@ -43,15 +44,17 @@ func (s *FS) Open(path string) (fs.File, error) {
4344
Resolve: resolveFlags,
4445
})
4546
if err != nil {
46-
return nil, err
47+
return nil, fmt.Errorf("openat2(%d, %q): %w", s.file.Fd(), path, err)
4748
}
48-
f := os.NewFile(uintptr(fd), path)
49-
return f, nil
49+
return os.NewFile(uintptr(fd), path), nil
5050
}
5151

5252
// Lchown wraps fchownat(2) (with AT_SYMLINK_NOFOLLOW).
5353
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
5558
}
5659

5760
// 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) {
6366
Resolve: resolveFlags,
6467
})
6568
if err != nil {
66-
return nil, err
69+
return nil, fmt.Errorf("openat2(%d, %q): %w", s.file.Fd(), dir, err)
6770
}
6871
return &FS{os.NewFile(uintptr(fd), dir)}, nil
6972
}
@@ -105,7 +108,8 @@ func (s *FS) RecursiveChown(uid, gid int) error {
105108
continue
106109
}
107110

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.)
109113
if d.Type()&fs.ModeSymlink != 0 {
110114
continue
111115
}

0 commit comments

Comments
 (0)