Skip to content

Commit 889e1f9

Browse files
KaiHerlemannWhyNotHugo
authored andcommitted
Implement a no_delete flag
See: #1090
1 parent d1f93ea commit 889e1f9

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

AUTHORS.rst

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ In alphabetical order:
77
- Christian Geier
88
- Clément Mondon
99
- Corey Hinshaw
10+
- Kai Herlemann
1011
- Hugo Osvaldo Barrera
1112
- Julian Mehne
1213
- Malte Kiefer

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ may want to subscribe to `GitHub's tag feed
1212
Version 0.19.3
1313
==============
1414

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

tests/system/utils/test_main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_get_storage_init_args():
2222
from vdirsyncer.storage.memory import MemoryStorage
2323

2424
all, required = utils.get_storage_init_args(MemoryStorage)
25-
assert all == {"fileext", "collection", "read_only", "instance_name"}
25+
assert all == {"fileext", "collection", "read_only", "instance_name", "no_delete"}
2626
assert not required
2727

2828

vdirsyncer/storage/base.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class Storage(metaclass=StorageMeta):
6767
# The machine-readable name of this collection.
6868
collection = None
6969

70+
#A value of False means storage does not support delete requests. A
71+
#value of True mean the storage supports it.
72+
no_delete = False
73+
7074
# A value of True means the storage does not support write-methods such as
7175
# upload, update and delete. A value of False means the storage does
7276
# support those methods.
@@ -75,13 +79,19 @@ class Storage(metaclass=StorageMeta):
7579
# The attribute values to show in the representation of the storage.
7680
_repr_attributes: list[str] = []
7781

78-
def __init__(self, instance_name=None, read_only=None, collection=None):
82+
def __init__(self, instance_name=None, read_only=None, no_delete=None, collection=None):
7983
if read_only is None:
8084
read_only = self.read_only
8185
if self.read_only and not read_only:
8286
raise exceptions.UserError("This storage can only be read-only.")
8387
self.read_only = bool(read_only)
8488

89+
if no_delete is None:
90+
no_delete = self.no_delete
91+
if self.no_delete and not no_delete:
92+
raise exceptions.UserError("Nothing can be deleted in this storage.")
93+
self.no_delete = bool(no_delete)
94+
8595
if collection and instance_name:
8696
instance_name = f"{instance_name}/{collection}"
8797
self.instance_name = instance_name

vdirsyncer/sync/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ def __init__(self, ident, dest):
243243

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

0 commit comments

Comments
 (0)