diff --git a/oml/item/api.py b/oml/item/api.py index 0fd7a6a..4493233 100644 --- a/oml/item/api.py +++ b/oml/item/api.py @@ -168,6 +168,7 @@ def remove(data): ''' if 'ids' in data and data['ids']: for i in models.Item.query.filter(models.Item.id.in_(data['ids'])): + logger.info('remove item %s', i) i.remove_file() state.cache.clear('group:') return { diff --git a/oml/item/handlers.py b/oml/item/handlers.py index aabeff2..36ca61a 100644 --- a/oml/item/handlers.py +++ b/oml/item/handlers.py @@ -172,7 +172,8 @@ class UploadHandler(tornado.web.RequestHandler): id = get_id(data=upload.body) ids.append(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_imported = os.path.join(prefix_books, '.import' + os.sep) ox.makedirs(prefix_imported) @@ -190,7 +191,13 @@ class UploadHandler(tornado.web.RequestHandler): file.move() else: 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: l = List.get(settings.USER_ID, listname) if l: diff --git a/oml/item/models.py b/oml/item/models.py index 27e4191..9448260 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -800,6 +800,7 @@ class File(db.Model): if os.path.exists(path) and os.path.exists(current_path): os.unlink(path) return + logger.debug('mv "%s" "%s"', self.path, new_path) self.path = new_path self.save() for folder in set(os.path.dirname(p) for p in [current_path, path]): diff --git a/oml/item/scan.py b/oml/item/scan.py index d9c4bb1..aa96bdc 100644 --- a/oml/item/scan.py +++ b/oml/item/scan.py @@ -7,6 +7,7 @@ import os import shutil import stat import time +import unicodedata import ox @@ -31,6 +32,7 @@ def remove_missing(books=None): prefix = get_prefix() if books is None: books = collect_books(prefix) + books = [unicodedata.normalize('NFD', path) for path in books] with db.session(): if os.path.exists(prefix): logger.debug('scan for removed files') @@ -40,6 +42,7 @@ def remove_missing(books=None): if state.shutdown: return path = f.fullpath() + path = unicodedata.normalize('NFD', path) db_paths.append(path) if f.item: items[path] = f.sha1 @@ -172,7 +175,6 @@ def run_scan(): elif user not in file.item.users: item = file.item item.add_user(user) - logger.debug('add %s to local user', id) add_record('additem', item.id, file.info) add_record('edititem', item.id, item.meta) @@ -194,11 +196,10 @@ def run_scan(): library_items = set([str(i) for i in user.library.items]) gone = library_items - ids if gone: - logger.debug('cleaning up %s deleted records', len(gone)) for id in gone: i = Item.get(id) 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) i.remove_file() missing = ids - library_items diff --git a/oml/library.py b/oml/library.py index d61398f..54902d1 100644 --- a/oml/library.py +++ b/oml/library.py @@ -288,7 +288,7 @@ class Peer(object): l.remove_items(lremove, commit=False) if ladd or lremove: logger.debug('update list %s', l.name) - else: + elif self.info['lists'][l.name]: l.add_items(self.info['lists'][l.name], commit=False) update_items = list(set(update_items) - set(self.info['lists'][l.name])) logger.debug('update list %s', l.name) diff --git a/static/js/utils.js b/static/js/utils.js index fc7186f..388c453 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1028,7 +1028,7 @@ oml.updateDebugMenu = function() { oml.user.ui.showDebugMenu ? menu.show() : menu.hide(); }; -oml.supportedExtensions = ['pdf', 'epub', 'kepub', 'cbr', 'cbz']; +oml.supportedExtensions = ['pdf', 'epub', 'kepub', 'cbr', 'cbz', 'txt']; oml.upload = function(fileslist, callback) { var files = [], ids = [];