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"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
filesMap := newFilesMap()
|
||||||
for _, path := range os.Args[1:] {
|
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)
|
fmt.Println(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type filesMap struct {
|
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 {
|
type fileEntry struct {
|
||||||
Path string
|
Path string
|
||||||
Size int
|
Size int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateHash(path string) (string, error) {
|
func calculateHash(path string) (string, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user