| 1 | //go:build darwin |
| 2 | |
| 3 | package pathidentity |
| 4 | |
| 5 | import ( |
| 6 | "os" |
| 7 | "path/filepath" |
| 8 | "strings" |
| 9 | "syscall" |
| 10 | |
| 11 | "golang.org/x/sys/unix" |
| 12 | ) |
| 13 | |
| 14 | const pathconfCaseSensitive = 11 |
| 15 | |
| 16 | var systemVolume = darwinVolume{ |
| 17 | fsType: func(dir string) (string, error) { |
| 18 | var stat unix.Statfs_t |
| 19 | if err := unix.Statfs(dir, &stat); err != nil { |
| 20 | return "", err |
| 21 | } |
| 22 | return strings.TrimRight(string(stat.Fstypename[:]), "\x00"), nil |
| 23 | }, |
| 24 | caseSensitive: func(dir string) (int, error) { |
| 25 | return syscall.Pathconf(dir, pathconfCaseSensitive) |
| 26 | }, |
| 27 | } |
| 28 | |
| 29 | func platformIdentityKey(path string) (string, error) { |
| 30 | parent, err := closestExistingDirectory(path) |
| 31 | if err != nil { |
| 32 | return "", err |
| 33 | } |
| 34 | return darwinIdentityKeyBy(path, parent, systemVolume) |
| 35 | } |
| 36 | |
| 37 | func closestExistingDirectory(path string) (string, error) { |
| 38 | for current := path; ; current = filepath.Dir(current) { |
| 39 | info, err := os.Stat(current) |
| 40 | if err == nil && info.IsDir() { |
| 41 | return current, nil |
| 42 | } |
| 43 | if err != nil && !os.IsNotExist(err) { |
| 44 | return "", err |
| 45 | } |
| 46 | if filepath.Dir(current) == current { |
| 47 | return "", os.ErrNotExist |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 |