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:
Kovid Goyal 2011-03-23 12:07:46 -06:00
parent 1ccddbf41e
commit f59c8d8a47

View File

@ -1121,6 +1121,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
pdir = os.path.dirname(dest)
if not os.path.exists(pdir):
os.makedirs(pdir)
if not getattr(stream, 'name', False) or \
os.path.abspath(dest) != os.path.abspath(stream.name):
with lopen(dest, 'wb') as f:
shutil.copyfileobj(stream, f)
stream.seek(0, 2)