From cdb4089f19adf8cf8e7f5c66b9e3c28c4051d74f Mon Sep 17 00:00:00 2001 From: viktorstrate Date: Wed, 12 Aug 2020 12:31:13 +0200 Subject: [PATCH] Ignore hidden media files This closes #57 --- api/scanner/media_type.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/api/scanner/media_type.go b/api/scanner/media_type.go index c41103b1..08819611 100644 --- a/api/scanner/media_type.go +++ b/api/scanner/media_type.go @@ -4,6 +4,7 @@ import ( "io" "log" "os" + "path" "path/filepath" "strings" @@ -265,16 +266,21 @@ func getMediaType(path string) (*MediaType, error) { return nil, nil } -func isPathMedia(path string, cache *AlbumScannerCache) bool { - mediaType, err := cache.GetMediaType(path) +func isPathMedia(mediaPath string, cache *AlbumScannerCache) bool { + mediaType, err := cache.GetMediaType(mediaPath) if err != nil { - ScannerError("%s (%s)", err, path) + ScannerError("%s (%s)", err, mediaPath) + return false + } + + // Ignore hidden files + if path.Base(mediaPath)[0:1] == "." { return false } if mediaType != nil { // Make sure file isn't empty - fileStats, err := os.Stat(path) + fileStats, err := os.Stat(mediaPath) if err != nil || fileStats.Size() == 0 { return false } @@ -282,6 +288,6 @@ func isPathMedia(path string, cache *AlbumScannerCache) bool { return true } - log.Printf("File is not a supported media %s\n", path) + log.Printf("File is not a supported media %s\n", mediaPath) return false }