This commit is contained in:
Kovid Goyal 2012-10-26 09:49:56 +05:30
parent 1c62e0c3ba
commit 71b76765eb
2 changed files with 15 additions and 3 deletions

View File

@ -646,12 +646,13 @@ 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 and current_path else None
source_ok = current_path and os.path.exists(spath)
wam = WindowsAtomicFolderMove(spath) if iswindows and source_ok else None
try:
if not os.path.exists(tpath):
os.makedirs(tpath)
if current_path and os.path.exists(spath): # Migrate existing files
if source_ok: # Migrate existing files
self.copy_cover_to(id, os.path.join(tpath, 'cover.jpg'),
index_is_id=True, windows_atomic_move=wam,
use_hardlink=True)
@ -669,7 +670,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
self.conn.commit()
self.data.set(id, self.FIELD_MAP['path'], path, row_is_id=True)
# Delete not needed directories
if current_path and os.path.exists(spath):
if source_ok:
if not samefile(spath, tpath):
if wam is not None:
wam.delete_originals()

View File

@ -314,6 +314,17 @@ class WindowsAtomicFolderMove(object):
break
f.write(raw)
def release_file(self, path):
key = None
for p, h in self.handle_map.iteritems():
if samefile_windows(path, p):
key = (p, h)
break
if key is not None:
import win32file
win32file.CloseHandle(key[1])
self.handle_map.pop(key[0])
def close_handles(self):
import win32file
for h in self.handle_map.itervalues():