1//+build !windows 2 3package main 4 5import ( 6 "fmt" 7 "io" 8 "io/ioutil" 9 "os" 10 "path/filepath" 11 "syscall" 12) 13 14func (e *dirEntry) equals(out io.Writer, other *dirEntry) bool { 15 if e.path != other.path { 16 fmt.Fprintf(out, "%v: path does not match (%v != %v)\n", e.path, e.path, other.path) 17 return false 18 } 19 20 if e.fi.Mode() != other.fi.Mode() { 21 fmt.Fprintf(out, "%v: mode does not match (%v != %v)\n", e.path, e.fi.Mode(), other.fi.Mode()) 22 return false 23 } 24 25 if !sameModTime(e.fi, other.fi) { 26 fmt.Fprintf(out, "%v: ModTime does not match (%v != %v)\n", e.path, e.fi.ModTime(), other.fi.ModTime()) 27 return false 28 } 29 30 stat, _ := e.fi.Sys().(*syscall.Stat_t) 31 stat2, _ := other.fi.Sys().(*syscall.Stat_t) 32 33 if stat.Uid != stat2.Uid { 34 fmt.Fprintf(out, "%v: UID does not match (%v != %v)\n", e.path, stat.Uid, stat2.Uid) 35 return false 36 } 37 38 if stat.Gid != stat2.Gid { 39 fmt.Fprintf(out, "%v: GID does not match (%v != %v)\n", e.path, stat.Gid, stat2.Gid) 40 return false 41 } 42 43 if stat.Nlink != stat2.Nlink { 44 fmt.Fprintf(out, "%v: Number of links do not match (%v != %v)\n", e.path, stat.Nlink, stat2.Nlink) 45 return false 46 } 47 48 return true 49} 50 51func nlink(info os.FileInfo) uint64 { 52 stat, _ := info.Sys().(*syscall.Stat_t) 53 return uint64(stat.Nlink) 54} 55 56func createFileSetPerHardlink(dir string) map[uint64][]string { 57 var stat syscall.Stat_t 58 linkTests := make(map[uint64][]string) 59 files, err := ioutil.ReadDir(dir) 60 if err != nil { 61 return nil 62 } 63 for _, f := range files { 64 65 if err := syscall.Stat(filepath.Join(dir, f.Name()), &stat); err != nil { 66 return nil 67 } 68 linkTests[uint64(stat.Ino)] = append(linkTests[uint64(stat.Ino)], f.Name()) 69 } 70 return linkTests 71} 72