summaryrefslogtreecommitdiffhomepage
path: root/libs/fcache
diff options
context:
space:
mode:
authorLouis Vézina <[email protected]>2019-11-28 06:52:06 -0500
committerLouis Vézina <[email protected]>2019-11-28 06:52:06 -0500
commit0f04e8a47394390bce3d9e4a5c6259e91ae1d64f (patch)
tree3484e4f3d987ce9c6b0ee35b91c499b2565ef3e3 /libs/fcache
parent8cd2224cb6b4844874c60f07b2c817f1b2161650 (diff)
downloadbazarr-0f04e8a47394390bce3d9e4a5c6259e91ae1d64f.tar.gz
bazarr-0f04e8a47394390bce3d9e4a5c6259e91ae1d64f.zip
Patched fcache to support real move with shutil instead of os.rename. This way can move from one drive to another.
Diffstat (limited to 'libs/fcache')
-rw-r--r--libs/fcache/cache.py2
-rw-r--r--libs/fcache/posixemulation.py29
2 files changed, 8 insertions, 23 deletions
diff --git a/libs/fcache/cache.py b/libs/fcache/cache.py
index e1510c233..f6f1d9cb2 100644
--- a/libs/fcache/cache.py
+++ b/libs/fcache/cache.py
@@ -256,7 +256,7 @@ class FileCache(MutableMapping):
return self._loads(f.read())
except (IOError, OSError):
logger.warning('Error opening file: {}'.format(filename))
- return None
+ raise
def __setitem__(self, key, value):
ekey = self._encode_key(key)
diff --git a/libs/fcache/posixemulation.py b/libs/fcache/posixemulation.py
index 03d6982c3..cf9ac63b7 100644
--- a/libs/fcache/posixemulation.py
+++ b/libs/fcache/posixemulation.py
@@ -46,15 +46,7 @@ if os.name == 'nt': # pragma: no cover
dst = unicode(dst, sys.getfilesystemencoding())
if _rename_atomic(src, dst):
return True
- retry = 0
- 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
+ return _MoveFileEx(src, dst, _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH)
# new in Vista and Windows Server 2008
_CreateTransaction = ctypes.windll.ktmw32.CreateTransaction
@@ -68,18 +60,11 @@ if os.name == 'nt': # pragma: no cover
if ta == -1:
return False
try:
- retry = 0
- rv = False
- while not rv and retry < 100:
- rv = _MoveFileTransacted(src, dst, None, None,
- _MOVEFILE_REPLACE_EXISTING |
- _MOVEFILE_WRITE_THROUGH, ta)
- if rv:
- rv = _CommitTransaction(ta)
- break
- else:
- time.sleep(0.001)
- retry += 1
+ rv = _MoveFileTransacted(src, dst, None, None,
+ _MOVEFILE_REPLACE_EXISTING |
+ _MOVEFILE_WRITE_THROUGH, ta)
+ if rv:
+ rv = _CommitTransaction(ta)
return rv
finally:
_CloseHandle(ta)
@@ -92,7 +77,7 @@ if os.name == 'nt': # pragma: no cover
return
# Fall back to "move away and replace"
try:
- os.rename(src, dst)
+ shutil.move(src, dst)
except OSError as e:
if e.errno != errno.EEXIST:
raise