Only image hash on file hash collision

This commit is contained in:
Jan Bader committed 2026-08-08 12:01:32 +02:00
1 parent e40c3c8560
commit 1106701374
2 files changed
+86 -34

No files matched your search

+49 -9
View File
@@ -86,22 +86,62 @@ func main() {
decor.CurrentKibiByte("%5d"),
),
)
done := make(chan bool)
wg := sync.WaitGroup{}
// Stage 2: compute the file hash of every file found.
fileHashingDone := make(chan bool)
fileWG := sync.WaitGroup{}
for i := 0; i < runtime.GOMAXPROCS(0); i++ {
wg.Add(2)
go filesMap.ImageHashingWorker(&wg)
go filesMap.FileHashingWorker(&wg)
fileWG.Add(1)
go filesMap.FileHashingWorker(&fileWG)
}
go filesMap.HashedWorker(done)
go filesMap.fileHashMergeWorker(fileHashingDone)
countFiles = filesMap.WalkDirectories()
wg.Wait()
fileWG.Wait()
close(filesMap.FilesHashed)
<-fileHashingDone
// Stage 3: image hashes are only needed for files with no file-hash
// collision: either they were never file-hashed (unique size) or their
// file hash did not match any other file.
var imageCandidates []*imageEntry
// Files whose size is unique were never file-hashed, so they have no
// collision but may still be visually similar images.
for size, file := range filesMap.FilesBySize {
if file == "" {
continue
}
imageCandidates = append(imageCandidates, &imageEntry{path: file, size: size})
}
// Files that were file-hashed without colliding also need an image hash.
for _, files := range filesMap.FilesByHash {
if len(files) != 1 {
continue
}
imageCandidates = append(imageCandidates, &imageEntry{path: files[0], size: filesMap.fileSizes[files[0]]})
}
// Stage 4: compute the image hash of every candidate.
go func() {
for _, candidate := range imageCandidates {
filesMap.ImagesHashing <- candidate
}
close(filesMap.ImagesHashing)
}()
imageWG := sync.WaitGroup{}
imageHashingDone := make(chan bool)
for i := 0; i < runtime.GOMAXPROCS(0); i++ {
imageWG.Add(1)
go filesMap.ImageHashingWorker(&imageWG)
}
go filesMap.imageHashMergeWorker(imageHashingDone)
imageWG.Wait()
close(filesMap.ImagesHashed)
<-done
<-imageHashingDone
}
if *toFile != "" && *fromFile == "" {