mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When adding formats do not corrupt the added file if the user tries to add an existing format to itself
This commit is contained in:
parent
1ccddbf41e
commit
f59c8d8a47
@ -1121,8 +1121,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
pdir = os.path.dirname(dest)
|
pdir = os.path.dirname(dest)
|
||||||
if not os.path.exists(pdir):
|
if not os.path.exists(pdir):
|
||||||
os.makedirs(pdir)
|
os.makedirs(pdir)
|
||||||
with lopen(dest, 'wb') as f:
|
if not getattr(stream, 'name', False) or \
|
||||||
shutil.copyfileobj(stream, f)
|
os.path.abspath(dest) != os.path.abspath(stream.name):
|
||||||
|
with lopen(dest, 'wb') as f:
|
||||||
|
shutil.copyfileobj(stream, f)
|
||||||
stream.seek(0, 2)
|
stream.seek(0, 2)
|
||||||
size=stream.tell()
|
size=stream.tell()
|
||||||
self.conn.execute('INSERT INTO data (book,format,uncompressed_size,name) VALUES (?,?,?,?)',
|
self.conn.execute('INSERT INTO data (book,format,uncompressed_size,name) VALUES (?,?,?,?)',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user