summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--giscanner/dumper.py5
-rw-r--r--giscanner/gdumpparser.py3
-rw-r--r--giscanner/utils.py25
3 files changed, 28 insertions, 5 deletions
diff --git a/giscanner/dumper.py b/giscanner/dumper.py
index 06737188..d6956da2 100644
--- a/giscanner/dumper.py
+++ b/giscanner/dumper.py
@@ -28,7 +28,6 @@ import os
import sys
import shlex
import subprocess
-import shutil
import tempfile
from distutils.errors import LinkError
@@ -171,14 +170,14 @@ class DumpCompiler(object):
introspection_obj = self._compile(c_path)
except CompilerError as e:
if not utils.have_debug_flag('save-temps'):
- shutil.rmtree(tmpdir)
+ utils.rmtree(tmpdir)
raise SystemExit('compilation of temporary binary failed:' + str(e))
try:
self._link(bin_path, introspection_obj)
except LinkerError as e:
if not utils.have_debug_flag('save-temps'):
- shutil.rmtree(tmpdir)
+ utils.rmtree(tmpdir)
raise SystemExit('linking of temporary binary failed: ' + str(e))
return IntrospectionBinary([bin_path], tmpdir)
diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
index bd4d233a..cd9d94d2 100644
--- a/giscanner/gdumpparser.py
+++ b/giscanner/gdumpparser.py
@@ -26,7 +26,6 @@ from __future__ import unicode_literals
import os
import sys
import tempfile
-import shutil
import subprocess
from xml.etree.cElementTree import parse
@@ -181,7 +180,7 @@ blob containing data gleaned from GObject's primitive introspection."""
return parse(out_path)
finally:
if not utils.have_debug_flag('save-temps'):
- shutil.rmtree(self._binary.tmpdir)
+ utils.rmtree(self._binary.tmpdir)
# Parser
diff --git a/giscanner/utils.py b/giscanner/utils.py
index 09132b2d..f6cd0b4f 100644
--- a/giscanner/utils.py
+++ b/giscanner/utils.py
@@ -27,6 +27,8 @@ import re
import os
import subprocess
import platform
+import shutil
+import time
_debugflags = None
@@ -291,3 +293,26 @@ def get_system_data_dirs():
xdg_data_dirs.append('/usr/share')
return xdg_data_dirs
+
+
+def rmtree(*args, **kwargs):
+ '''
+ A variant of shutil.rmtree() which waits and tries again in case one of
+ the files in the directory tree can't be deleted.
+
+ This can be the case if a file is still in use by some process,
+ for example a Virus scanner on Windows scanning .exe files when they are
+ created.
+ '''
+
+ tries = 3
+ for i in range(1, tries + 1):
+ try:
+ shutil.rmtree(*args, **kwargs)
+ except OSError:
+ if i == tries:
+ raise
+ time.sleep(i)
+ continue
+ else:
+ return