Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "crypto/sha512"
- "fmt"
- "io"
- "log"
- "os"
- "path/filepath"
- "sync"
- )
- type DubCandid struct {
- os.FileInfo
- Path string
- Hash string
- IsDeleted bool
- }
- func main() {
- var wg sync.WaitGroup
- path := os.Args[1]
- files := readRDir(path)
- fmt.Printf("Searhing %s for dubs in %d files\n", path, len(files))
- i := 0
- wg.Add(1)
- go (func() {
- for _, file := range files {
- wg.Add(1)
- go func() {
- h := sha512.New()
- f, _ := os.Open(file.Path)
- if _, err := io.Copy(h, f); err != nil {
- log.Fatal(err)
- }
- file.Hash = fmt.Sprintf("%x", h.Sum(nil))
- fmt.Printf("%s : %s\n", file.Path, file.Hash)
- i++
- wg.Done()
- }()
- }
- wg.Done()
- })()
- wg.Wait()
- fmt.Println(i)
- }
- func readRDir(path string) (res []DubCandid) {
- filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
- if err != nil {
- return err
- }
- if info.IsDir() == false {
- res = append(res, DubCandid{
- FileInfo: info,
- Path: path,
- })
- }
- return nil
- })
- return res
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement