Skip system directories (like recycle) in the filesystem scan (#401)
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 8 Jul 2022 13:09:08 +0000 (15:09 +0200)
committerGitHub <noreply@github.com>
Fri, 8 Jul 2022 13:09:08 +0000 (15:09 +0200)
music_assistant/music_providers/filesystem.py

index b347dda5467fc996ce6627568df9ca39ccb834d4..09384db631248a5f2ebb07b16d22d8196937dd24 100644 (file)
@@ -56,16 +56,17 @@ async def scantree(path: str) -> AsyncGenerator[os.DirEntry, None]:
         return entry.is_dir(follow_symlinks=False)
 
     loop = asyncio.get_running_loop()
-    try:
-        for entry in await loop.run_in_executor(None, os.scandir, path):
-            if await loop.run_in_executor(None, is_dir, entry):
+    for entry in await loop.run_in_executor(None, os.scandir, path):
+        if entry.name.startswith("."):
+            continue
+        if await loop.run_in_executor(None, is_dir, entry):
+            try:
                 async for subitem in scantree(entry.path):
                     yield subitem
-            else:
-                yield entry
-    except (OSError, PermissionError) as err:
-        LOGGER.warning("Skip folder %s: %s", path, str(err))
-        return
+            except (OSError, PermissionError) as err:
+                LOGGER.warning("Skip folder %s: %s", entry.path, str(err))
+        else:
+            yield entry
 
 
 def get_parentdir(base_path: str, name: str) -> str | None: