mirror of
https://github.com/JaCoB1123/dupe-finder.git
synced 2025-05-18 06:01:56 +02:00
Save files to map
This commit is contained in:
parent
ccb42c7e29
commit
3df950f483
36
main.go
36
main.go
@ -6,22 +6,54 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func main() {
|
||||
filesMap := newFilesMap()
|
||||
for _, path := range os.Args[1:] {
|
||||
filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
|
||||
filesMap.Add(path, info)
|
||||
return nil
|
||||
})
|
||||
fmt.Println(path)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type filesMap struct {
|
||||
Files map[int]map[[32]byte]*fileEntry
|
||||
Files map[int64]map[string]*fileEntry
|
||||
}
|
||||
|
||||
func (fm *filesMap) Add(path string, info os.FileInfo) {
|
||||
fileInfo := &fileEntry{
|
||||
Path: path,
|
||||
Size: info.Size(),
|
||||
}
|
||||
|
||||
existing := fm.Files[fileInfo.Size]
|
||||
if existing == nil {
|
||||
existing = map[string]*fileEntry{}
|
||||
fm.Files[fileInfo.Size] = existing
|
||||
existing[""] = fileInfo
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Dupes: " + path)
|
||||
fmt.Println(existing[""])
|
||||
fm.Files[fileInfo.Size] = nil
|
||||
|
||||
}
|
||||
|
||||
func newFilesMap() filesMap {
|
||||
return filesMap{
|
||||
Files: map[int64]map[string]*fileEntry{},
|
||||
}
|
||||
}
|
||||
|
||||
type fileEntry struct {
|
||||
Path string
|
||||
Size int
|
||||
Size int64
|
||||
}
|
||||
|
||||
func calculateHash(path string) (string, error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user