diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-06-11 21:20:16 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-06-11 21:20:16 +0300 |
commit | 5ffd09cbb557c76a0f4909b4c8b001b0101f94b2 (patch) | |
tree | 924be7bbbdf76f918e1cdab1c2c5b7ac5b40de40 | |
parent | d02abb6adbc3378fa7e683980dcf24f9f81b63cb (diff) | |
download | obnam-5ffd09cbb557c76a0f4909b4c8b001b0101f94b2.tar.gz |
Add: LeafStore.remove_leaf method
-rw-r--r-- | obnamlib/fmt_ga/leaf_store.py | 13 | ||||
-rw-r--r-- | obnamlib/fmt_ga/leaf_store_tests.py | 6 |
2 files changed, 19 insertions, 0 deletions
diff --git a/obnamlib/fmt_ga/leaf_store.py b/obnamlib/fmt_ga/leaf_store.py index 5d488e96..bd356847 100644 --- a/obnamlib/fmt_ga/leaf_store.py +++ b/obnamlib/fmt_ga/leaf_store.py @@ -27,6 +27,9 @@ class LeafStoreInterface(object): # pragma: no cover def get_leaf(self, leaf_id): raise NotImplementedError() + def remove_leaf(self, leaf_id): + raise NotImplementedError() + def flush(self): raise NotImplementedError() @@ -45,6 +48,10 @@ class InMemoryLeafStore(LeafStoreInterface): def get_leaf(self, leaf_id): return self._leaves.get(leaf_id, None) + def remove_leaf(self, leaf_id): + if leaf_id in self._leaves: + del self._leaves[leaf_id] + def flush(self): pass @@ -65,5 +72,11 @@ class LeafStore(LeafStoreInterface): # pragma: no cover leaf.from_dict(self._blob_store.get_blob(leaf_id)) return leaf + def remove_leaf(self, leaf_id): + # FIXME: This is a bit ugly, since we need to break the + # bag/blob store abstraction. + bag_id, _ = obnamlib.parse_object_id(leaf_id) + self._blob_store._bag_store.remove_bag(bag_id) + def flush(self): self._blob_store.flush() diff --git a/obnamlib/fmt_ga/leaf_store_tests.py b/obnamlib/fmt_ga/leaf_store_tests.py index 9d1a8f71..92f6a01b 100644 --- a/obnamlib/fmt_ga/leaf_store_tests.py +++ b/obnamlib/fmt_ga/leaf_store_tests.py @@ -40,6 +40,12 @@ class LeafStoreTests(object): def test_returns_None_if_leaf_is_missing(self): self.assertEqual(self.ls.get_leaf(42), None) + def test_removes_leaf(self): + leaf = {'foo': 'bar'} + leaf_id = self.ls.put_leaf(leaf) + self.ls.remove_leaf(leaf_id) + self.assertEqual(self.ls.get_leaf(leaf_id), None) + def test_has_flush(self): self.assertEqual(self.ls.flush(), None) |