Fix metadata backup not being written if book directory does not exist

This commit is contained in:
Kovid Goyal 2013-07-22 13:37:52 +05:30
parent e105493d78
commit 98924814ad
2 changed files with 9 additions and 2 deletions

View file

@ -1390,8 +1390,13 @@ def update_path(self, book_id, title, author, path_field, formats_field):
def write_backup(self, path, raw):
path = os.path.abspath(os.path.join(self.library_path, path, 'metadata.opf'))
with lopen(path, 'wb') as f:
f.write(raw)
try:
with lopen(path, 'wb') as f:
f.write(raw)
except EnvironmentError:
os.makedirs(os.path.dirname(path))
with lopen(path, 'wb') as f:
f.write(raw)
def read_backup(self, path):
path = os.path.abspath(os.path.join(self.library_path, path, 'metadata.opf'))

View file

@ -100,11 +100,13 @@ def do_one(self):
self.db.write_backup(book_id, raw)
except:
prints('Failed to write backup metadata for id:', book_id, 'once')
traceback.print_exc()
self.wait(self.interval)
try:
self.db.write_backup(book_id, raw)
except:
prints('Failed to write backup metadata for id:', book_id, 'again, giving up')
traceback.print_exc()
return
self.db.clear_dirtied(book_id, sequence)