[gobject-introspection] cachestore: Use "write new, then rename" pattern, not "write in place"
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] cachestore: Use "write new, then rename" pattern, not "write in place"
- Date: Tue, 1 Apr 2014 11:35:41 +0000 (UTC)
commit 5b105135d27ea2f06e8863de813112611955290d
Author: Colin Walters <walters verbum org>
Date: Thu Feb 27 09:01:14 2014 -0500
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
giscanner/cachestore.py | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py
index ad4c7a3..27b260f 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]