more cleanup fallbacks

This commit is contained in:
j 2019-01-13 18:35:01 +05:30
parent 709e067e14
commit 3a1b3a5c3c
2 changed files with 10 additions and 3 deletions

View File

@ -172,7 +172,8 @@ class UploadHandler(tornado.web.RequestHandler):
id = get_id(data=upload.body) id = get_id(data=upload.body)
ids.append(id) ids.append(id)
file = File.get(id) file = File.get(id)
if not file: if not file or not os.path.exists(file.fullpath()):
logger.debug('add %s to library', id)
prefix_books = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books' + os.sep) prefix_books = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books' + os.sep)
prefix_imported = os.path.join(prefix_books, '.import' + os.sep) prefix_imported = os.path.join(prefix_books, '.import' + os.sep)
ox.makedirs(prefix_imported) ox.makedirs(prefix_imported)
@ -190,7 +191,13 @@ class UploadHandler(tornado.web.RequestHandler):
file.move() file.move()
else: else:
user = state.user() user = state.user()
file.item.add_user(user) item = file.item
if user not in item.users:
logger.debug('add %s to local user', id)
item.add_user(user)
add_record('additem', item.id, file.info)
add_record('edititem', item.id, item.meta)
item.update()
if listname and ids: if listname and ids:
l = List.get(settings.USER_ID, listname) l = List.get(settings.USER_ID, listname)
if l: if l:

View File

@ -198,7 +198,7 @@ def run_scan():
for id in gone: for id in gone:
i = Item.get(id) i = Item.get(id)
path = i.get_path() path = i.get_path()
if path and not os.path.exists(path): if not path or not os.path.exists(path):
logger.debug('cleaning orphaned record %s %s', i, path) logger.debug('cleaning orphaned record %s %s', i, path)
i.remove_file() i.remove_file()
missing = ids - library_items missing = ids - library_items