on main help sign in
feat: add `fsext` function to get owner of directory
commit897796e2029c886864e3d855e7056dc5404ac2d7 authorAndrey Nering <andreynering@users.noreply.github.com> dateWed 20 Aug 2025, 10:20 (1 year ago) parentf3a8061
2 files changed+33
internal/fsext/owner_others.go+24 internal/fsext/owner_windows.go+9
internal/fsext/owner_others.gonew file+24
@@ -0,0 +1,24 @@
1+//go:build !windows
2+
3+package fsext
4+
5+import (
6+ "os"
7+ "syscall"
8+)
9+
10+// Owner retrieves the user ID of the owner of the file or directory at the
11+// specified path.
12+func Owner(path string) (int, error) {
13+ info, err := os.Stat(path)
14+ if err != nil {
15+ return 0, err
16+ }
17+ var uid int
18+ if stat, ok := info.Sys().(*syscall.Stat_t); ok {
19+ uid = int(stat.Uid)
20+ } else {
21+ uid = os.Getuid()
22+ }
23+ return uid, nil
24+}
internal/fsext/owner_windows.gonew file+9
@@ -0,0 +1,9 @@
1+//go:build windows
2+
3+package fsext
4+
5+// Owner retrieves the user ID of the owner of the file or directory at the
6+// specified path.
7+func Owner(path string) (int, error) {
8+ return -1, nil
9+}