diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-07-08 19:45:51 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-07-08 20:05:55 +0300 |
commit | 0791557014f06d8658e207f783a9fa3ce8c8aa7c (patch) | |
tree | 32e44978190379992e0f0789a66deabad247b61f /obnamlib/fmt_ga/tree.py | |
parent | e5c8a76da66daf28a94996e796a20397f62dd41d (diff) | |
download | obnam-0791557014f06d8658e207f783a9fa3ce8c8aa7c.tar.gz |
Add GATree.remove_directory
Diffstat (limited to 'obnamlib/fmt_ga/tree.py')
-rw-r--r-- | obnamlib/fmt_ga/tree.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/obnamlib/fmt_ga/tree.py b/obnamlib/fmt_ga/tree.py index 45b3e2bc..8e5e01f2 100644 --- a/obnamlib/fmt_ga/tree.py +++ b/obnamlib/fmt_ga/tree.py @@ -96,6 +96,30 @@ class GATree(object): parent_obj.add_subdir(basename, None) self.set_directory(parent_path, parent_obj) + def remove_directory(self, pathname): + if pathname == '/': + self._remove_root_dir() + else: + self._remove_from_parent(pathname) + + def _remove_root_dir(self): + self._root_dir_id = None + self._cache.clear() + + def _remove_from_parent(self, pathname): + self._cache.remove(pathname) + basename = os.path.basename(pathname) + parent_path = os.path.dirname(pathname) + parent_obj = self._cache.get(parent_path) + if not parent_obj: + parent_obj = self.get_directory(parent_path) + if parent_obj: + parent_obj = obnamlib.create_gadirectory_from_dict( + parent_obj.as_dict()) + if parent_obj: + parent_obj.remove_subdir(basename) + self.set_directory(parent_path, parent_obj) + def flush(self): self._root_dir_id = self._fixup_subdir_refs('/') self._blob_store.flush() @@ -133,3 +157,7 @@ class DirectoryObjectCache(object): def __contains__(self, pathname): return pathname in self._objs + + def remove(self, pathname): + if pathname in self._objs: + del self._objs[pathname] |