|
|
@ -46,15 +46,7 @@ if os.name == 'nt': # pragma: no cover
|
|
|
|
dst = unicode(dst, sys.getfilesystemencoding())
|
|
|
|
dst = unicode(dst, sys.getfilesystemencoding())
|
|
|
|
if _rename_atomic(src, dst):
|
|
|
|
if _rename_atomic(src, dst):
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
retry = 0
|
|
|
|
return _MoveFileEx(src, dst, _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH)
|
|
|
|
rv = False
|
|
|
|
|
|
|
|
while not rv and retry < 100:
|
|
|
|
|
|
|
|
rv = _MoveFileEx(src, dst, _MOVEFILE_REPLACE_EXISTING |
|
|
|
|
|
|
|
|
_MOVEFILE_WRITE_THROUGH)
|
|
|
|
|
|
|
|
if not rv:
|
|
|
|
|
|
|
|
time.sleep(0.001)
|
|
|
|
|
|
|
|
retry += 1
|
|
|
|
|
|
|
|
return rv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# new in Vista and Windows Server 2008
|
|
|
|
# new in Vista and Windows Server 2008
|
|
|
|
_CreateTransaction = ctypes.windll.ktmw32.CreateTransaction
|
|
|
|
_CreateTransaction = ctypes.windll.ktmw32.CreateTransaction
|
|
|
@ -68,18 +60,11 @@ if os.name == 'nt': # pragma: no cover
|
|
|
|
if ta == -1:
|
|
|
|
if ta == -1:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
retry = 0
|
|
|
|
|
|
|
|
rv = False
|
|
|
|
|
|
|
|
while not rv and retry < 100:
|
|
|
|
|
|
|
|
rv = _MoveFileTransacted(src, dst, None, None,
|
|
|
|
rv = _MoveFileTransacted(src, dst, None, None,
|
|
|
|
_MOVEFILE_REPLACE_EXISTING |
|
|
|
|
_MOVEFILE_REPLACE_EXISTING |
|
|
|
|
_MOVEFILE_WRITE_THROUGH, ta)
|
|
|
|
_MOVEFILE_WRITE_THROUGH, ta)
|
|
|
|
if rv:
|
|
|
|
if rv:
|
|
|
|
rv = _CommitTransaction(ta)
|
|
|
|
rv = _CommitTransaction(ta)
|
|
|
|
break
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
time.sleep(0.001)
|
|
|
|
|
|
|
|
retry += 1
|
|
|
|
|
|
|
|
return rv
|
|
|
|
return rv
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
_CloseHandle(ta)
|
|
|
|
_CloseHandle(ta)
|
|
|
@ -92,7 +77,7 @@ if os.name == 'nt': # pragma: no cover
|
|
|
|
return
|
|
|
|
return
|
|
|
|
# Fall back to "move away and replace"
|
|
|
|
# Fall back to "move away and replace"
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
os.rename(src, dst)
|
|
|
|
shutil.move(src, dst)
|
|
|
|
except OSError as e:
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
raise
|
|
|
|
raise
|
|
|
|