diff --git a/src/calibre/utils/filenames.py b/src/calibre/utils/filenames.py index 5c31c92c33..3a327b214c 100644 --- a/src/calibre/utils/filenames.py +++ b/src/calibre/utils/filenames.py @@ -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)