mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
When adding a format to an existing book record, ensure that no changes are made to the database until after the file operations have succeeded.
This commit is contained in:
parent
24562cc6a4
commit
b7f22183d2
@ -1320,7 +1320,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
if name:
|
||||
if not replace:
|
||||
return False
|
||||
self.conn.execute('DELETE FROM data WHERE book=? AND format=?', (id, format))
|
||||
name = self.construct_file_name(id)
|
||||
ext = ('.' + format.lower()) if format else ''
|
||||
dest = os.path.join(path, name+ext)
|
||||
@ -1333,7 +1332,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
shutil.copyfileobj(stream, f)
|
||||
stream.seek(0, 2)
|
||||
size=stream.tell()
|
||||
self.conn.execute('INSERT INTO data (book,format,uncompressed_size,name) VALUES (?,?,?,?)',
|
||||
self.conn.execute('INSERT OR REPLACE INTO data (book,format,uncompressed_size,name) VALUES (?,?,?,?)',
|
||||
(id, format.upper(), size, name))
|
||||
self.conn.commit()
|
||||
self.refresh_ids([id])
|
||||
|
Loading…
x
Reference in New Issue
Block a user