# HG changeset patch # User Mikael Berthe # Date 1404047656 -7200 # Node ID 15e3580cfb8db6938c38cb7f43d5b6ff58522a3a # Parent 47e45453b705282226894b4d4f2519e20d26e691 Fix hard link detection The previous algorithm was assuming all files of a size group, or none of them, would be hard links. For size groups with both hard links and regular files, the detection could fail. diff -r 47e45453b705 -r 15e3580cfb8d goduf.go --- a/goduf.go Sun Jun 29 15:07:04 2014 +0200 +++ b/goduf.go Sun Jun 29 15:14:16 2014 +0200 @@ -422,20 +422,21 @@ // "Unique" of the fileObj to mark them to be discarded // and remove them all at the end. for { + type devinode struct { dev, ino uint64 } + devinodes := make(map[devinode]bool) var hardLinkIndex int - fo := sizeGroup.files[0] - prevDev, prevIno := GetDevIno(fo) - for i, fo := range sizeGroup.files[1:] { + for i, fo := range sizeGroup.files { dev, ino := GetDevIno(fo) - if dev == prevDev && ino == prevIno { - hardLinkIndex = i + 1 + di := devinode{ dev, ino} + if _, hlink := devinodes[di]; hlink { + hardLinkIndex = i hardLinkCount++ hardlinksFound = true break + } else { + devinodes[di] = true } - prevDev = dev - prevIno = ino } if hardLinkIndex == 0 {