Skip to content

Commit

Permalink
Merge pull request #88 from ThomasWaldmann/list-deleted-behaviour
Browse files Browse the repository at this point in the history
Store.list: deleted=True semantics, fixes #83
  • Loading branch information
ThomasWaldmann authored Dec 2, 2024
2 parents 90a44f3 + c51dfbd commit fce35b5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ soft deletion, so the caller doesn't have to care much for that and the Backend
API can be much simpler:

- create/destroy: initialize or remove the whole store.
- list: flat list of the items in the given namespace, with or without soft
deleted items.
- list: flat list of the items in the given namespace (by default only not
soft deleted items, optionally only soft deleted items).
- store: write a new item into the store (giving its key/value pair)
- load: read a value from the store (giving its key), partial loads giving
offset and/or size are supported.
Expand Down
2 changes: 1 addition & 1 deletion src/borgstore/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def id_key(data: bytes):
store.move(key2, delete=True)

print(f"Listing data namespace contents: {list(store.list('data', deleted=False))}")
print(f"Listing data namespace contents, incl. deleted: {list(store.list('data', deleted=True))}")
print(f"Listing data namespace contents (only deleted): {list(store.list('data', deleted=True))}")

print(f"Stats: {store.stats}")

Expand Down
6 changes: 3 additions & 3 deletions src/borgstore/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def list(self, name: str, deleted: bool = False) -> Iterator[ItemInfo]:
"""
List all names in the namespace <name>.
If deleted is True and soft deleted items are encountered, they are yielded
as if they were not deleted. Otherwise, they are ignored.
If deleted is False (default), only normal (not soft deleted) items are yielded.
If deleted is True, only soft deleted items are yielded.
backend.list giving us sorted names implies store.list is also sorted, if all items are stored on same level.
"""
Expand Down Expand Up @@ -290,5 +290,5 @@ def _list(self, name: str, deleted: bool = False) -> Iterator[ItemInfo]:
is_deleted = info.name.endswith(DEL_SUFFIX)
if deleted and is_deleted:
yield info._replace(name=info.name.removesuffix(DEL_SUFFIX))
elif not is_deleted:
elif not deleted and not is_deleted:
yield info
4 changes: 2 additions & 2 deletions tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ def test_move_delete_undelete(posixfs_store_created):
# delete
store.move(nsk0, delete=True) # soft delete
assert list_store_names(store, ns, deleted=False) == [k1]
assert list_store_names(store, ns, deleted=True) == [k0, k1]
assert list_store_names(store, ns, deleted=True) == [k0]
# undelete
store.move(nsk0, undelete=True) # undelete previously soft deleted item
assert list_store_names(store, ns, deleted=False) == [k0, k1]
assert list_store_names(store, ns, deleted=True) == [k0, k1]
assert list_store_names(store, ns, deleted=True) == []


def test_move_change_level(posixfs_store_created):
Expand Down

0 comments on commit fce35b5

Please sign in to comment.