From b7f22183d2568bc1d81c655d064174f25c4241f0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 10 Nov 2011 11:34:18 +0530 Subject: [PATCH] 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. --- src/calibre/library/database2.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 122e8c627f..bc503aef08 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -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])