diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index 4ce8cce1e..5863f1fe3 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -245,7 +245,6 @@ var _ = Describe("Scanner", Ordered, func() { }) It("should update the album", func() { - tests.SkipOnWindows("path separator bug (#TBD-path-sep-scanner)") Expect(runScanner(ctx, true)).To(Succeed()) albums, err := ds.Album().GetAll(ctx, model.QueryOptions{Filters: squirrel.Eq{"album.name": "Help!"}}) @@ -533,7 +532,6 @@ var _ = Describe("Scanner", Ordered, func() { var beatlesMBID = uuid.NewString() BeforeEach(func() { - tests.SkipOnWindows("path separator bug (#TBD-path-sep-scanner)") By("Having two MP3 albums") beatles := _t{ "artist": "The Beatles", diff --git a/scanner/watcher.go b/scanner/watcher.go index 1ac5468f0..8c1b3f558 100644 --- a/scanner/watcher.go +++ b/scanner/watcher.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io/fs" + "path" "path/filepath" "strings" "sync" @@ -250,6 +251,10 @@ func (w *watcher) processLibraryEvents(ctx context.Context, lib *model.Library, log.Error(ctx, "Error getting relative path", "libraryID", lib.ID, "absolutePath", absLibPath, "path", path, err) continue } + // fs.FS paths always use "/", but filepath.Rel returns OS separators, + // so normalize before feeding the value to fs lookups and downstream + // notifications (otherwise back-slashes break matching on Windows). + path = filepath.ToSlash(path) if isIgnoredPath(ctx, fsys, path) { log.Trace(ctx, "Ignoring change", "libraryID", lib.ID, "path", path) @@ -282,13 +287,13 @@ func (w *watcher) processLibraryEvents(ctx context.Context, lib *model.Library, // resolveFolderPath takes a path (which may be a file or directory) and returns // the folder path to scan. If the path is a file, it walks up to find the parent // directory. Returns empty string if the path should scan the library root. -func resolveFolderPath(fsys fs.FS, path string) string { +func resolveFolderPath(fsys fs.FS, p string) string { // Handle root paths immediately - if path == "." || path == "" { + if p == "." || p == "" { return "" } - folderPath := path + folderPath := p for { info, err := fs.Stat(fsys, folderPath) if err == nil && info.IsDir() { @@ -299,13 +304,13 @@ func resolveFolderPath(fsys fs.FS, path string) string { // Reached root, scan entire library return "" } - // Walk up the tree - dir, _ := filepath.Split(folderPath) - if dir == "" || dir == "." { + // Walk up the tree. fs.FS paths always use "/", so use path.Dir + // (filepath would emit "\" on Windows and never match the slash keys). + parent := path.Dir(folderPath) + if parent == "." || parent == folderPath { return "" } - // Remove trailing slash - folderPath = filepath.Clean(dir) + folderPath = parent } } diff --git a/scanner/watcher_test.go b/scanner/watcher_test.go index 12c94602c..0a35958dd 100644 --- a/scanner/watcher_test.go +++ b/scanner/watcher_test.go @@ -382,7 +382,6 @@ var _ = Describe("Watcher", func() { }) It("should NOT send notification when nested ignored folder is deleted", func() { - tests.SkipOnWindows("path separator bug (#TBD-path-sep-scanner)") startEventProcessing() // Simulate deletion of music/rock/artist/temp (matches **/temp) @@ -396,7 +395,6 @@ var _ = Describe("Watcher", func() { }) It("should send notification for non-ignored nested folder", func() { - tests.SkipOnWindows("path separator bug (#TBD-path-sep-scanner)") startEventProcessing() // Simulate change in music/rock/artist (doesn't match any pattern) @@ -421,7 +419,6 @@ var _ = Describe("Watcher", func() { }) It("should NOT send notification for file changes in ignored folders", func() { - tests.SkipOnWindows("path separator bug (#TBD-path-sep-scanner)") startEventProcessing() // Simulate file change in rock/_TEMP/file.mp3 @@ -504,13 +501,11 @@ var _ = Describe("resolveFolderPath", func() { }) It("walks up to parent directory when given a file path", func() { - tests.SkipOnWindows("path separator bug (#TBD-path-sep-scanner)") result := resolveFolderPath(mockFS, "artist1/album1/track1.mp3") Expect(result).To(Equal("artist1/album1")) }) It("walks up multiple levels if needed", func() { - tests.SkipOnWindows("path separator bug (#TBD-path-sep-scanner)") result := resolveFolderPath(mockFS, "artist1/album1/nonexistent/file.mp3") Expect(result).To(Equal("artist1/album1")) }) @@ -531,7 +526,6 @@ var _ = Describe("resolveFolderPath", func() { }) It("handles nested file paths correctly", func() { - tests.SkipOnWindows("path separator bug (#TBD-path-sep-scanner)") result := resolveFolderPath(mockFS, "artist1/album2/song.flac") Expect(result).To(Equal("artist1/album2")) })