introduced excluded directories
This commit is contained in:
parent
0681c6891b
commit
85436a47e7
5
main.go
5
main.go
@ -20,6 +20,7 @@ var ( // flags
|
||||
FlagSourceDir = envvars.String("SOURCE_PATH", "/video")
|
||||
FlagTargetDir = envvars.String("TARGET_PATH", "/audio")
|
||||
FlagCacheFile = envvars.String("CACHE_FILE", "/hashes.bin")
|
||||
FlagExcludeFiles = envvars.StringSlice("EXCLUDE_FILES", ":", []string{".songs"})
|
||||
FlagUpdateCacheFileInterval = envvars.Duration("UPDATE_CACHE_FILE_INTERVAL", 10*time.Second)
|
||||
)
|
||||
|
||||
@ -33,6 +34,10 @@ func main() {
|
||||
FlagTargetDir = AbsPath(FlagTargetDir)
|
||||
FlagCacheFile = AbsPath(FlagCacheFile)
|
||||
|
||||
for i := 0; i < len(FlagExcludeFiles); i++ {
|
||||
FlagExcludeFiles[i] = filepath.Join(FlagSourceDir, FlagExcludeFiles[i])
|
||||
}
|
||||
|
||||
InitCache()
|
||||
|
||||
ops := []fsnotify.Op{
|
||||
|
13
utils.go
13
utils.go
@ -4,6 +4,7 @@ import (
|
||||
"crypto/sha512"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func HashFile(path string) ([sha512.Size]byte, error) {
|
||||
@ -23,3 +24,15 @@ func HashFile(path string) ([sha512.Size]byte, error) {
|
||||
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
|
||||
}
|
||||
|
@ -44,6 +44,11 @@ func WatchDirectory(ctx context.Context, path string, op ...fsnotify.Op) (<-chan
|
||||
|
||||
for _, file := range files {
|
||||
path := filepath.Join(path, file.Name())
|
||||
|
||||
if PathIsExcluded(path) {
|
||||
continue
|
||||
}
|
||||
|
||||
if file.IsDir() {
|
||||
//fmt.Println("watching directory", path)
|
||||
watcher.Add(path)
|
||||
@ -66,6 +71,10 @@ func WatchDirectory(ctx context.Context, path string, op ...fsnotify.Op) (<-chan
|
||||
return
|
||||
}
|
||||
|
||||
if PathIsExcluded(event.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
if fi, err := os.Stat(event.Name); err == nil && fi.IsDir() {
|
||||
if event.Op&fsnotify.Create == fsnotify.Create {
|
||||
//fmt.Println("watching directory", event.Name)
|
||||
|
Loading…
Reference in New Issue
Block a user