aboutsummaryrefslogtreecommitdiff
path: root/tools/cache.py
diff options
context:
space:
mode:
authorAndreas Bergmeier <abergmeier@gmx.net>2013-12-01 19:52:11 +0100
committerAndreas Bergmeier <abergmeier@gmx.net>2013-12-01 19:56:38 +0100
commit0f5135e436a80b8d13c61da87c943ec1238b42c7 (patch)
tree847418137252180383a9e76cdb71d4da780f0a0a /tools/cache.py
parentc2077a787657f59623961437a5c604e34a2fb799 (diff)
Introduce safe_ensure_dirs as a safe os.makedirs replacement.
It only uses os.makedirs call, which is more atomic than calling 2 procs. Thus exception due to already existent directory should not longer occur.
Diffstat (limited to 'tools/cache.py')
-rw-r--r--tools/cache.py15
1 files changed, 3 insertions, 12 deletions
diff --git a/tools/cache.py b/tools/cache.py
index ed4fcd24..8883a740 100644
--- a/tools/cache.py
+++ b/tools/cache.py
@@ -1,6 +1,7 @@
import os.path, sys, shutil, hashlib, cPickle, zlib, time
import tempfiles
+import shared
# Permanent cache for dlmalloc and stdlibc++
class Cache:
@@ -13,13 +14,7 @@ class Cache:
self.debug = debug
def ensure(self):
- try:
- # Use makedirs here, so creating the path is as atomic as possible
- os.makedirs(self.dirname)
- except os.error, e:
- # Ignore error for already existing dirname
- if not os.path.exists(self.dirname):
- raise e
+ shared.safe_ensure_dirs(self.dirname)
def erase(self):
tempfiles.try_delete(self.dirname)
@@ -53,11 +48,7 @@ class JCache:
def ensure(self):
self.cache.ensure()
- if not os.path.exists(self.dirname):
- try:
- os.makedirs(self.dirname)
- except (IOError, OSError):
- pass
+ shared.safe_ensure_dirs(self.dirname)
def get_shortkey(self, keys):
if type(keys) not in [list, tuple]: