[gobject-introspection] scanner: fix cachestore race
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] scanner: fix cachestore race
- Date: Fri, 21 Aug 2015 12:10:09 +0000 (UTC)
commit 23e5dd8d6821e269feec3346c5f95c390a4ff009
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date: Sat Jul 4 20:32:21 2015 +0200
scanner: fix cachestore race
Using tempfile.mkstemp should prevent the temp file
from being cleaned while it might still be used by
another process.
https://bugzilla.gnome.org/show_bug.cgi?id=751926
giscanner/cachestore.py | 17 ++++++++---------
1 files changed, 8 insertions(+), 9 deletions(-)
---
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py
index d612070..7b465d8 100644
--- a/giscanner/cachestore.py
+++ b/giscanner/cachestore.py
@@ -75,11 +75,16 @@ class CacheStore(object):
if current_hash == cache_hash:
return
- versiontmp = version + '.tmp'
-
self._clean()
+
+ tmp_fd, tmp_filename = tempfile.mkstemp(prefix='g-ir-scanner-cache-version-')
try:
- fp = open(versiontmp, 'w')
+ with os.fdopen(tmp_fd, 'w') as tmp_file:
+ tmp_file.write(current_hash)
+
+ # On Unix, this would just be os.rename() but Windows
+ # doesn't allow that.
+ shutil.move(tmp_filename, version)
except IOError as e:
# Permission denied
if e.errno == errno.EACCES:
@@ -87,12 +92,6 @@ class CacheStore(object):
else:
raise
- fp.write(current_hash)
- fp.close()
- # On Unix, this would just be os.rename() but Windows
- # doesn't allow that.
- shutil.move(versiontmp, version)
-
def _get_filename(self, filename):
# If we couldn't create the directory we're probably
# on a read only home directory where we just disable
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]