返回 DeepSeek-Reasonix
directory_identity_unix.go
根目录 / internal / fileutil / directory_identity_unix.go
1 //go:build !windows && !plan9
2
3 package fileutil
4
5 import (
6 "fmt"
7 "os"
8 "syscall"
9 )
10
11 // DirectoryIdentity remains stable across rename and changes on replacement.
12 func DirectoryIdentity(path string) (string, error) {
13 info, err := os.Lstat(path)
14 if err != nil {
15 return "", err
16 }
17 if !info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
18 return "", fmt.Errorf("not a directory")
19 }
20 stat, ok := info.Sys().(*syscall.Stat_t)
21 if !ok {
22 return "", fmt.Errorf("directory identity unavailable")
23 }
24 return fmt.Sprintf("%x:%x", stat.Dev, stat.Ino), nil
25 }
26
26 lines GO