1
0
Fork 0
mirror of https://github.com/vbatts/dedupe-linker.git synced 2025-07-27 12:30:28 +00:00

*.go: firm up whether it is the same file

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2023-04-11 14:31:28 -04:00
parent 022dad64e7
commit 2835d1a77d
3 changed files with 23 additions and 16 deletions

View file

@ -83,6 +83,27 @@ func GetDev(path string) (uint64, error) {
return stat.Dev, nil
}
// SameFile checks whether the two paths are same device and inode
func SameFile(fpath1, fpath2 string) bool {
bStat, err := GetStat(fpath1)
if err != nil {
return false
}
dStat, err := GetStat(fpath2)
if err != nil {
return false
}
if bStat.Dev != dStat.Dev {
return false
}
if bStat.Ino != dStat.Ino {
return false
}
// if we made it here, we must be ok
return true
}
// GetNlink returns the number of links for path. For directories, that is
// number of entries. For regular files, that is number of hardlinks.
func GetNlink(path string) (uint64, error) {