1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-14 14:12:17 +00:00

Fixed scanner for deleted folders

This commit is contained in:
spl0k 2019-06-01 15:57:45 +02:00
parent bb36b38d52
commit 09138897b9

View File

@ -7,6 +7,7 @@
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
import logging
import os, os.path import os, os.path
import mimetypes import mimetypes
import mutagen import mutagen
@ -22,6 +23,8 @@ from .db import StarredFolder, StarredArtist, StarredAlbum, StarredTrack
from .db import RatingFolder, RatingTrack from .db import RatingFolder, RatingTrack
from .py23 import strtype, Queue, QueueEmpty from .py23 import strtype, Queue, QueueEmpty
logger = logging.getLogger(__name__)
class StatsDetails(object): class StatsDetails(object):
def __init__(self): def __init__(self):
self.artists = 0 self.artists = 0
@ -105,6 +108,8 @@ class Scanner(Thread):
self.__stopped.set() self.__stopped.set()
def __scan_folder(self, folder): def __scan_folder(self, folder):
logger.info('Scanning folder %s', folder.name)
if self.__on_folder_start is not None: if self.__on_folder_start is not None:
self.__on_folder_start(folder) self.__on_folder_start(folder)
@ -150,14 +155,15 @@ class Scanner(Thread):
while not self.__stopped.is_set() and folders: while not self.__stopped.is_set() and folders:
f = folders.pop() f = folders.pop()
if not f.root and not os.path.isdir(f.path):
with db_session: with db_session:
f = Folder[f.id] # f has been fetched from another session, refetch or Pony will complain
if not f.root and not os.path.isdir(f.path):
f.delete() # Pony will cascade f.delete() # Pony will cascade
continue continue
self.find_cover(f.path) self.find_cover(f.path)
with db_session: folders += f.children
folders += Folder[f.id].children # f has been fetched from another session, refetch or Pony will complain
if not self.__stopped.is_set(): if not self.__stopped.is_set():
with db_session: with db_session: