Skip to content

Commit

Permalink
Implement a no_delete flag
Browse files Browse the repository at this point in the history
See: #1090
  • Loading branch information
KaiHerlemann authored and WhyNotHugo committed Nov 29, 2023
1 parent d1f93ea commit ebaeeb8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ In alphabetical order:
- Christian Geier
- Clément Mondon
- Corey Hinshaw
- Kai Herlemann
- Hugo Osvaldo Barrera
- Julian Mehne
- Malte Kiefer
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ may want to subscribe to `GitHub's tag feed
Version 0.19.3
==============

- Added a no_delete option to the storage configuration. :gh:`1090`
- Fix crash when running ``vdirsyncer repair`` on a collection. :gh:`1019`
- Add an option to request vCard v4.0. :gh:`1066`

Expand Down
2 changes: 1 addition & 1 deletion tests/system/utils/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_get_storage_init_args():
from vdirsyncer.storage.memory import MemoryStorage

all, required = utils.get_storage_init_args(MemoryStorage)
assert all == {"fileext", "collection", "read_only", "instance_name"}
assert all == {"fileext", "collection", "read_only", "instance_name", "no_delete"}
assert not required


Expand Down
12 changes: 11 additions & 1 deletion vdirsyncer/storage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class Storage(metaclass=StorageMeta):
# The machine-readable name of this collection.
collection = None

#A value of False means storage does not support delete requests. A
#value of True mean the storage supports it.
no_delete = False

# A value of True means the storage does not support write-methods such as
# upload, update and delete. A value of False means the storage does
# support those methods.
Expand All @@ -75,13 +79,19 @@ class Storage(metaclass=StorageMeta):
# The attribute values to show in the representation of the storage.
_repr_attributes: list[str] = []

def __init__(self, instance_name=None, read_only=None, collection=None):
def __init__(self, instance_name=None, read_only=None, no_delete=None, collection=None):
if read_only is None:
read_only = self.read_only
if self.read_only and not read_only:
raise exceptions.UserError("This storage can only be read-only.")
self.read_only = bool(read_only)

if no_delete is None:
no_delete = self.no_delete
if self.no_delete and not no_delete:
raise exceptions.UserError("Nothing can be deleted in this storage.")
self.no_delete = bool(no_delete)

if collection and instance_name:
instance_name = f"{instance_name}/{collection}"
self.instance_name = instance_name
Expand Down
4 changes: 3 additions & 1 deletion vdirsyncer/sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def __init__(self, ident, dest):

async def _run_impl(self, a, b):
meta = self.dest.status.get_new(self.ident)
if not self.dest.storage.read_only:
if self.dest.storage.read_only or self.dest.storage.no_delete:
sync_logger.debug(f"Skipping deletion of item {self.ident} from {self.dest.storage}")
else:
sync_logger.info(f"Deleting item {self.ident} from {self.dest.storage}")
await self.dest.storage.delete(meta.href, meta.etag)

Expand Down

0 comments on commit ebaeeb8

Please sign in to comment.