Add fs package
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)
This commit is contained in:
parent
5f08e609c0
commit
574862fd89
16 changed files with 1672 additions and 0 deletions
33
fs/hardlink_unix.go
Normal file
33
fs/hardlink_unix.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
// +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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue