mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Windows: Workaround for error while changing title/author with calibre library on a network share. Also explicitly close file handles in samefile() instead of relying on garbage collection.
This commit is contained in:
parent
faea33fc56
commit
2bfc897266
@ -208,17 +208,22 @@ def samefile_windows(src, dst):
|
||||
if samestring:
|
||||
return True
|
||||
|
||||
handles = []
|
||||
|
||||
def get_fileid(x):
|
||||
if isbytestring(x): x = x.decode(filesystem_encoding)
|
||||
try:
|
||||
h = win32file.CreateFile(x, 0, 0, None, win32file.OPEN_EXISTING,
|
||||
win32file.FILE_FLAG_BACKUP_SEMANTICS, 0)
|
||||
handles.append(h)
|
||||
data = win32file.GetFileInformationByHandle(h)
|
||||
except (error, EnvironmentError):
|
||||
return None
|
||||
return (data[4], data[8], data[9])
|
||||
|
||||
a, b = get_fileid(src), get_fileid(dst)
|
||||
for h in handles:
|
||||
win32file.CloseHandle(h)
|
||||
if a is None and b is None:
|
||||
return False
|
||||
return a == b
|
||||
@ -302,6 +307,8 @@ class WindowsAtomicFolderMove(object):
|
||||
' operation was started'%path)
|
||||
try:
|
||||
win32file.CreateHardLink(dest, path)
|
||||
if not os.path.exists(dest):
|
||||
raise Exception('This apparently can happen on network shares. Sigh.')
|
||||
return
|
||||
except:
|
||||
pass
|
||||
@ -341,6 +348,8 @@ def hardlink_file(src, dest):
|
||||
if iswindows:
|
||||
import win32file
|
||||
win32file.CreateHardLink(dest, src)
|
||||
if not os.path.exists(dest):
|
||||
raise Exception('This apparently can happen on network shares. Sigh.')
|
||||
return
|
||||
os.link(src, dest)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user