music-library/utils.go

39 lines
635 B
Go
Raw Normal View History

2025-01-15 12:48:20 +01:00
package main
import (
"crypto/sha512"
"io"
"os"
2025-01-15 21:06:45 +01:00
"strings"
2025-01-15 12:48:20 +01:00
)
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
}
2025-01-15 21:06:45 +01:00
func PathIsExcluded(path string) bool {
path = AbsPath(path)
for _, excludedPath := range FlagExcludeFiles {
if strings.HasPrefix(path, AbsPath(excludedPath)) {
return true
}
}
return false
}