summaryrefslogtreecommitdiff
path: root/obnamlib/fmt_ga/tree.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-07-08 18:35:11 +0300
committerLars Wirzenius <liw@liw.fi>2015-07-08 18:35:11 +0300
commiteefe94bb32e7bb9371c78fb1067d9c618088d17a (patch)
tree6bb1c04486bcb1f65c9218eb8d26f34b0119a994 /obnamlib/fmt_ga/tree.py
parent2bfbd208f91511a103fdb65d3af39aa4b5f386de (diff)
downloadobnam-eefe94bb32e7bb9371c78fb1067d9c618088d17a.tar.gz
Refactor get_directory for clarity
Diffstat (limited to 'obnamlib/fmt_ga/tree.py')
-rw-r--r--obnamlib/fmt_ga/tree.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/obnamlib/fmt_ga/tree.py b/obnamlib/fmt_ga/tree.py
index a1d66c71..f750f52e 100644
--- a/obnamlib/fmt_ga/tree.py
+++ b/obnamlib/fmt_ga/tree.py
@@ -58,15 +58,14 @@ class GATree(object):
if pathname == '/':
return self._get_dir_obj(self._root_dir_id)
-
- parent_path = os.path.dirname(pathname)
- parent_obj = self.get_directory(parent_path)
- if parent_obj is None: # pragma: no cover
- return None
- obj_id = parent_obj.get_subdir_object_id(os.path.basename(pathname))
- if obj_id is None: # pragma: no cover
- return None
- return self._get_dir_obj(obj_id)
+ else:
+ parent_obj = self._get_containing_dir_obj(pathname)
+ if parent_obj is not None:
+ basename = os.path.basename(pathname)
+ obj_id = parent_obj.get_subdir_object_id(basename)
+ if obj_id is not None:
+ return self._get_dir_obj(obj_id)
+ return None # pragma: no cover
def _get_dir_obj(self, dir_id):
blob = self._blob_store.get_blob(dir_id)
@@ -77,6 +76,10 @@ class GATree(object):
dir_obj.set_immutable()
return dir_obj
+ def _get_containing_dir_obj(self, pathname):
+ parent_path = os.path.dirname(pathname)
+ return self.get_directory(parent_path)
+
def set_directory(self, pathname, dir_obj):
self._cache.set(pathname, dir_obj)
if pathname != '/':