summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstuertz <js@contact.de>2017-03-26 15:48:07 +0200
committerstuertz <js@contact.de>2017-03-26 15:48:07 +0200
commit57c3a4fc59b6babe71859b2bf92b2b2fc909ce2a (patch)
treea88b52694a95b01ffa487c0c64cd8277816c79f7
parent30329354b370ed6bfac74290ce0c5d2ab17307d1 (diff)
downloadgitdb-57c3a4fc59b6babe71859b2bf92b2b2fc909ce2a.tar.gz
Fixed Tests / Code for Windows.
Sometimes the OS or some other process has the handle to file a bit longer, and the file could not be deleted immediatly. Retry 10 Times with 100ms distance.
-rw-r--r--gitdb/test/performance/test_stream.py4
-rw-r--r--gitdb/util.py27
2 files changed, 25 insertions, 6 deletions
diff --git a/gitdb/test/performance/test_stream.py b/gitdb/test/performance/test_stream.py
index 704f4d0..bd8953e 100644
--- a/gitdb/test/performance/test_stream.py
+++ b/gitdb/test/performance/test_stream.py
@@ -9,7 +9,7 @@ from gitdb.test.performance.lib import TestBigRepoR
from gitdb.db import LooseObjectDB
from gitdb import IStream
-from gitdb.util import bin_to_hex
+from gitdb.util import bin_to_hex, remove
from gitdb.fun import chunk_size
from time import time
@@ -104,5 +104,5 @@ class TestObjDBPerformance(TestBigRepoR):
(size_kib, desc, cs_kib, elapsed_readchunks, size_kib / (elapsed_readchunks or 1)), file=sys.stderr)
# del db file so we keep something to do
- os.remove(db_file)
+ remove(db_file)
# END for each randomization factor
diff --git a/gitdb/util.py b/gitdb/util.py
index 242be44..95ab9b2 100644
--- a/gitdb/util.py
+++ b/gitdb/util.py
@@ -6,6 +6,7 @@ import binascii
import os
import mmap
import sys
+import time
import errno
from io import BytesIO
@@ -58,7 +59,6 @@ chmod = os.chmod
isdir = os.path.isdir
isfile = os.path.isfile
rename = os.rename
-remove = os.remove
dirname = os.path.dirname
basename = os.path.basename
join = os.path.join
@@ -67,6 +67,25 @@ write = os.write
close = os.close
fsync = os.fsync
+
+def _retry(func, *args, **kwargs):
+ # Wrapper around functions, that are problematic on "Windows". Sometimes
+ # the OS or someone else has still a handle to the file
+ if sys.platform == "win32":
+ for _ in xrange(10):
+ try:
+ return func(*args, **kwargs)
+ except Exception:
+ time.sleep(0.1)
+ return func(*args, **kwargs)
+ else:
+ return func(*args, **kwargs)
+
+
+def remove(*args, **kwargs):
+ return _retry(os.remove, *args, **kwargs)
+
+
# Backwards compatibility imports
from gitdb.const import (
NULL_BIN_SHA,
@@ -321,7 +340,7 @@ class LockedFD(object):
self._fd = os.open(self._filepath, os.O_RDONLY | binary)
except:
# assure we release our lockfile
- os.remove(self._lockfilepath())
+ remove(self._lockfilepath())
raise
# END handle lockfile
# END open descriptor for reading
@@ -365,7 +384,7 @@ class LockedFD(object):
# on windows, rename does not silently overwrite the existing one
if sys.platform == "win32":
if isfile(self._filepath):
- os.remove(self._filepath)
+ remove(self._filepath)
# END remove if exists
# END win32 special handling
os.rename(lockfile, self._filepath)
@@ -376,7 +395,7 @@ class LockedFD(object):
chmod(self._filepath, int("644", 8))
else:
# just delete the file so far, we failed
- os.remove(lockfile)
+ remove(lockfile)
# END successful handling
#} END utilities