music-library/utils.go

39 lines
635 B
Go

package main
import (
"crypto/sha512"
"io"
"os"
"strings"
)
func HashFile(path string) ([sha512.Size]byte, error) {
file, err := os.Open(path)
if err != nil {
return [sha512.Size]byte{}, err
}
defer file.Close()
hasher := sha512.New()
if _, err := io.Copy(hasher, file); err != nil {
return [sha512.Size]byte{}, err
}
res := [sha512.Size]byte{}
hash := hasher.Sum(nil)
copy(res[:], hash)
return res, nil
}
func PathIsExcluded(path string) bool {
path = AbsPath(path)
for _, excludedPath := range FlagExcludeFiles {
if strings.HasPrefix(path, AbsPath(excludedPath)) {
return true
}
}
return false
}