diff options
author | Dieter Verfaillie <dieterv@optionexplicit.be> | 2015-07-05 10:54:16 +0200 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2015-08-21 13:03:01 +0100 |
commit | ebe658542217c510f186dfc68956d51528d81fd6 (patch) | |
tree | c55847c5418430a9b4e509713bb487f358545820 /giscanner/cachestore.py | |
parent | 23e5dd8d6821e269feec3346c5f95c390a4ff009 (diff) | |
download | gobject-introspection-ebe658542217c510f186dfc68956d51528d81fd6.tar.gz |
scanner: use open() as os.fdopen as context managers
Ensures files are correctly and immediately closed.
https://bugzilla.gnome.org/show_bug.cgi?id=751926
Diffstat (limited to 'giscanner/cachestore.py')
-rw-r--r-- | giscanner/cachestore.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py index 7b465d85..bc5443d5 100644 --- a/giscanner/cachestore.py +++ b/giscanner/cachestore.py @@ -64,7 +64,8 @@ class CacheStore(object): current_hash = _get_versionhash() version = os.path.join(self._directory, _CACHE_VERSION_FILENAME) try: - cache_hash = open(version).read() + with open(version, 'r') as version_file: + cache_hash = version_file.read() except IOError as e: # File does not exist if e.errno == errno.ENOENT: @@ -137,7 +138,8 @@ class CacheStore(object): tmp_fd, tmp_filename = tempfile.mkstemp(prefix='g-ir-scanner-cache-') try: - cPickle.dump(data, os.fdopen(tmp_fd, 'w')) + with os.fdopen(tmp_fd, 'w') as tmp_file: + cPickle.dump(data, tmp_file) except IOError as e: # No space left on device if e.errno == errno.ENOSPC: |