From 482990dd031ae247e433f503cee50a044d7c6180 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 26 Sep 2010 09:40:34 -0600 Subject: [PATCH] Ensure application_id from OPF matched id in dir name and actually fix path too long error --- src/calibre/library/restore.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/calibre/library/restore.py b/src/calibre/library/restore.py index ec50a39aa0..89c7fe8395 100644 --- a/src/calibre/library/restore.py +++ b/src/calibre/library/restore.py @@ -119,6 +119,7 @@ class Restore(Thread): return True def process_dir(self, dirpath, filenames, book_id): + book_id = int(book_id) formats = filter(self.is_ebook_file, filenames) fmts = [os.path.splitext(x)[1][1:].upper() for x in formats] sizes = [os.path.getsize(os.path.join(dirpath, x)) for x in formats] @@ -129,14 +130,17 @@ class Restore(Thread): path = os.path.relpath(dirpath, self.src_library_path).replace(os.sep, '/') - self.books.append({ - 'mi': mi, - 'timestamp': timestamp, - 'formats': list(zip(fmts, sizes, names)), - 'id': int(book_id), - 'dirpath': dirpath, - 'path': path, - }) + if int(mi.application_id) == book_id: + self.books.append({ + 'mi': mi, + 'timestamp': timestamp, + 'formats': list(zip(fmts, sizes, names)), + 'id': book_id, + 'dirpath': dirpath, + 'path': path, + }) + else: + self.ignored_dirs.append(dirpath) def create_cc_metadata(self): self.books.sort(key=itemgetter('timestamp')) @@ -157,7 +161,7 @@ class Restore(Thread): self.conflicting_custom_cols[label].add(args) m[b['label']] = args - db = LibraryDatabase2(self.library_path) + db = RestoreDatabase(self.library_path) for args in m.values(): db.create_custom_column(*args) db.conn.close()