🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Don't abort scan if all audio files are in the MediaFolder's root. Fix #868 (#893)
Garvit Galgat676de79fb370
diff --git a/scanner/tag_scanner.go b/scanner/tag_scanner.goindex 6bd654ece..43df122da 100644--- a/scanner/tag_scanner.go+++ b/scanner/tag_scanner.go@@ -75,6 +75,16 @@ func (s *TagScanner) Scan(ctx context.Context, lastModifiedSince time.Time, prog// Special case: if lastModifiedSince is zero, re-import all filesfullScan := lastModifiedSince.IsZero()+ // If the media folder is empty (no music and no subfolders), abort to avoid deleting all data from DB+ empty, err := isDirEmpty(ctx, s.rootFolder)+ if err != nil {+ return 0, err+ }+ if empty && !fullScan {+ log.Error(ctx, "Media Folder is empty. Aborting scan.", "folder", s.rootFolder)+ return 0, nil+ }+allDBDirs, err := s.getDBDirTree(ctx)if err != nil {return 0, err@@ -110,12 +120,6 @@ func (s *TagScanner) Scan(ctx context.Context, lastModifiedSince time.Time, progreturn 0, err}- // If the media folder is empty, abort to avoid deleting all data- if len(allFSDirs) <= 1 {- log.Error(ctx, "Media Folder is empty. Aborting scan.", "folder", s.rootFolder)- return 0, nil- }-deletedDirs := s.getDeletedDirs(ctx, allFSDirs, allDBDirs)if len(deletedDirs)+len(changedDirs) == 0 {log.Debug(ctx, "No changes found in Music Folder", "folder", s.rootFolder, "elapsed", time.Since(start))@@ -155,6 +159,11 @@ func (s *TagScanner) Scan(ctx context.Context, lastModifiedSince time.Time, progreturn s.cnt.total(), err}+func isDirEmpty(ctx context.Context, dir string) (bool, error) {+ children, stats, err := loadDir(ctx, dir)+ return len(children) == 0 && stats.AudioFilesCount == 0, err+}+func (s *TagScanner) getRootFolderWalker(ctx context.Context) (walkResults, chan error) {start := time.Now()log.Trace(ctx, "Loading directory tree from music folder", "folder", s.rootFolder)