Only remember last file

This commit is contained in:
Jan Bader 2020-11-22 01:09:02 +01:00
parent e33d7e2ca0
commit ff2d4daeda

View File

@ -11,7 +11,7 @@ import (
// FilesMap is a struct for listing files by Size and Hash to search for duplicates // FilesMap is a struct for listing files by Size and Hash to search for duplicates
type FilesMap struct { type FilesMap struct {
FilesBySize map[int64][]string FilesBySize map[int64]string
FilesByHash map[string][]string FilesByHash map[string][]string
@ -26,7 +26,7 @@ type FilesMap struct {
func newFilesMap() *FilesMap { func newFilesMap() *FilesMap {
return &FilesMap{ return &FilesMap{
FilesBySize: map[int64][]string{}, FilesBySize: map[int64]string{},
FilesByHash: map[string][]string{}, FilesByHash: map[string][]string{},
FilesHashed: make(chan fileEntry), FilesHashed: make(chan fileEntry),
FilesIncoming: make(chan fileEntry), FilesIncoming: make(chan fileEntry),
@ -40,17 +40,18 @@ func (fm *FilesMap) IncomingWorker() {
fmt.Println("Incoming", file.path) fmt.Println("Incoming", file.path)
} }
files, ok := fm.FilesBySize[file.size] prevFile, ok := fm.FilesBySize[file.size]
if !ok { if !ok {
files = []string{file.path} fm.FilesBySize[file.size] = file.path
fm.FilesBySize[file.size] = files
continue continue
} }
if len(files) == 1 { if prevFile != "" {
fm.FilesHashing <- fileEntry{files[0], file.size, ""} fm.FilesHashing <- fileEntry{prevFile, file.size, ""}
} }
fm.FilesBySize[file.size] = ""
fm.FilesHashing <- file fm.FilesHashing <- file
} }
close(fm.FilesHashing) close(fm.FilesHashing)