1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 01:16:18 +00:00

More checks on folder add

Fixes #49
This commit is contained in:
spl0k 2016-11-11 16:31:44 +01:00
parent 2e8d57b9d0
commit 783e9b5465

View File

@ -29,6 +29,7 @@ class FolderManager:
INVALID_PATH = 3 INVALID_PATH = 3
PATH_EXISTS = 4 PATH_EXISTS = 4
NO_SUCH_FOLDER = 5 NO_SUCH_FOLDER = 5
SUBPATH_EXISTS = 6
@staticmethod @staticmethod
def get(store, uid): def get(store, uid):
@ -53,11 +54,15 @@ class FolderManager:
if not store.find(Folder, Folder.name == name, Folder.root == True).is_empty(): if not store.find(Folder, Folder.name == name, Folder.root == True).is_empty():
return FolderManager.NAME_EXISTS return FolderManager.NAME_EXISTS
path = os.path.abspath(path) path = unicode(os.path.abspath(path))
if not os.path.isdir(path): if not os.path.isdir(path):
return FolderManager.INVALID_PATH return FolderManager.INVALID_PATH
if not store.find(Folder, Folder.path == path).is_empty(): if not store.find(Folder, Folder.path == path).is_empty():
return FolderManager.PATH_EXISTS return FolderManager.PATH_EXISTS
if any(path.startswith(p) for p in store.find(Folder).values(Folder.path)):
return FolderManager.PATH_EXISTS
if not store.find(Folder, Folder.path.startswith(path)).is_empty():
return FolderManager.SUBPATH_EXISTS
folder = Folder() folder = Folder()
folder.root = True folder.root = True
@ -108,5 +113,7 @@ class FolderManager:
return 'This path is already registered' return 'This path is already registered'
elif err == FolderManager.NO_SUCH_FOLDER: elif err == FolderManager.NO_SUCH_FOLDER:
return 'No such folder' return 'No such folder'
elif err == FolderManager.SUBPATH_EXISTS:
return 'This path contains a folder that is already registered'
return 'Unknown error' return 'Unknown error'