summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2014-02-27 09:01:14 -0500
committerColin Walters <walters@verbum.org>2014-04-01 07:35:26 -0400
commit5b105135d27ea2f06e8863de813112611955290d (patch)
tree0254679373c60f75345fd771582b76fee241e907
parent4cbba801af505b3bc36dbfae1c518091fb4ec9df (diff)
downloadgobject-introspection-5b105135d27ea2f06e8863de813112611955290d.tar.gz
cachestore: Use "write new, then rename" pattern, not "write in place"
This should fix race conditions when multiple processes attempt to access the cache concurrently. https://bugzilla.gnome.org/show_bug.cgi?id=724886
-rw-r--r--giscanner/cachestore.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py
index ad4c7a36..27b260f5 100644
--- a/giscanner/cachestore.py
+++ b/giscanner/cachestore.py
@@ -100,9 +100,11 @@ class CacheStore(object):
if current_hash == cache_hash:
return
+ versiontmp = version + '.tmp'
+
self._clean()
try:
- fp = open(version, 'w')
+ fp = open(versiontmp, 'w')
except IOError as e:
# Permission denied
if e.errno == errno.EACCES:
@@ -111,6 +113,10 @@ class CacheStore(object):
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