[jhbuild/desrt/master: 16/21] fileutils: add safe mkdir_with_parents() helper
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jhbuild/desrt/master: 16/21] fileutils: add safe mkdir_with_parents() helper
- Date: Sun, 18 Jan 2015 15:44:57 +0000 (UTC)
commit 7bb6479f4dd5b059fae79afc4bc1c15e387217a8
Author: Ryan Lortie <desrt desrt ca>
Date: Sun Jan 18 10:11:41 2015 -0500
fileutils: add safe mkdir_with_parents() helper
Add a GLib-style mkdir_with_parents() helper that doesn't throw
exceptions in the case that the directory already existed.
Replace some racy code in packagedb with a call to it.
https://bugzilla.gnome.org/show_bug.cgi?id=743127
jhbuild/utils/fileutils.py | 8 ++++++++
jhbuild/utils/packagedb.py | 3 +--
2 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/jhbuild/utils/fileutils.py b/jhbuild/utils/fileutils.py
index eb66f18..7842d29 100644
--- a/jhbuild/utils/fileutils.py
+++ b/jhbuild/utils/fileutils.py
@@ -114,6 +114,14 @@ def ensure_unlinked(filename):
except OSError as e:
if e.errno != os.errno.ENOENT:
raise
+
+def mkdir_with_parents(filename):
+ try:
+ os.makedirs(filename)
+ except EnvironmentError as e:
+ if e.errno != errno.EEXIST or not os.path.isdir(filename):
+ raise
+
class SafeWriter(object):
def __init__(self, filename):
self.filename = filename
diff --git a/jhbuild/utils/packagedb.py b/jhbuild/utils/packagedb.py
index e7160cb..c46874c 100644
--- a/jhbuild/utils/packagedb.py
+++ b/jhbuild/utils/packagedb.py
@@ -118,8 +118,7 @@ class PackageDB:
self.dbfile = dbfile
dirname = os.path.dirname(dbfile)
self.manifests_dir = os.path.join(dirname, 'manifests')
- if not os.path.exists(self.manifests_dir):
- os.makedirs(self.manifests_dir)
+ fileutils.mkdir_with_parents(self.manifests_dir)
self.config = config
self._lock = lockfile.LockFile.get(os.path.join(dirname, 'packagedb.xml.lock'))
self._entries = None # hash
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]