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 @@ class DB(object):
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 @@ class MetadataBackup(Thread):
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)