mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When changing the title/author of a book, use hard links instead of copying the file, for a large speedup.
This commit is contained in:
parent
0d532dd522
commit
5d3418f22c
@ -646,7 +646,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
spath = os.path.join(self.library_path, *current_path.split('/'))
|
||||
tpath = os.path.join(self.library_path, *path.split('/'))
|
||||
|
||||
wam = WindowsAtomicFolderMove(spath) if iswindows else None
|
||||
wam = WindowsAtomicFolderMove(spath) if iswindows and current_path else None
|
||||
try:
|
||||
if not os.path.exists(tpath):
|
||||
os.makedirs(tpath)
|
||||
@ -1375,6 +1375,11 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
if hasattr(dest, 'flush'):
|
||||
dest.flush()
|
||||
elif dest and not samefile(dest, path):
|
||||
try:
|
||||
os.link(path, dest)
|
||||
return
|
||||
except:
|
||||
pass
|
||||
with lopen(path, 'rb') as f, lopen(dest, 'wb') as d:
|
||||
shutil.copyfileobj(f, d)
|
||||
|
||||
|
@ -300,6 +300,11 @@ class WindowsAtomicFolderMove(object):
|
||||
if handle is None:
|
||||
raise ValueError(u'The file %r did not exist when this move'
|
||||
' operation was started'%path)
|
||||
try:
|
||||
win32file.CreateHardLink(dest, path)
|
||||
return
|
||||
except:
|
||||
pass
|
||||
with lopen(dest, 'wb') as f:
|
||||
while True:
|
||||
hr, raw = win32file.ReadFile(handle, 1024*1024)
|
||||
|
Loading…
x
Reference in New Issue
Block a user