diff options
author | Dieter Verfaillie <dieterv@optionexplicit.be> | 2015-07-04 20:32:21 +0200 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2015-08-21 13:03:00 +0100 |
commit | 23e5dd8d6821e269feec3346c5f95c390a4ff009 (patch) | |
tree | f01e7940279a8022355c29f5e278804193a32622 /giscanner | |
parent | 6ac310a3379baa34f4614f03fbd573e2ec4549f4 (diff) | |
download | gobject-introspection-23e5dd8d6821e269feec3346c5f95c390a4ff009.tar.gz |
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
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/cachestore.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py index d6120706..7b465d85 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 |