574862fd89
Add diff comparison with support for double walking two trees for comparison or single walking a diff tree. Single walking requires further implementation for specific mount types. Add directory copy function which is intended to provide fastest possible local copy of file system directories without hardlinking. Add test package to make creating filesystems for test easy and comparisons deep and informative. Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
33 lines
513 B
Go
33 lines
513 B
Go
// +build !windows
|
|
|
|
package fs
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
func getHardLink(name string, fi os.FileInfo, inodes map[uint64]string) (string, error) {
|
|
if fi.IsDir() {
|
|
return "", nil
|
|
}
|
|
|
|
s, ok := fi.Sys().(*syscall.Stat_t)
|
|
if !ok {
|
|
return "", errors.New("unsupported stat type")
|
|
}
|
|
|
|
// If inode is not hardlinked, no reason to lookup or save inode
|
|
if s.Nlink == 1 {
|
|
return "", nil
|
|
}
|
|
|
|
inode := uint64(s.Ino)
|
|
|
|
path, ok := inodes[inode]
|
|
if !ok {
|
|
inodes[inode] = name
|
|
}
|
|
return path, nil
|
|
}
|