Skip to content

Commit ff3e783

Browse files
cli/discover: remove local collections if the remote collection is deleted
This works when the destination backend is 'filesystem' and the source is CalDAV-calendar-home-set. pimutils#868
1 parent 51535af commit ff3e783

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

vdirsyncer/cli/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import functools
22
import logging
3+
import os
4+
import shutil
35
import sys
46

57
import click
68
import click_log
79

10+
from ..utils import expand_path
811
from .. import __version__
912
from .. import BUGTRACKER_HOME
1013

@@ -198,6 +201,9 @@ def discover(ctx, pairs, max_workers, list):
198201
config = ctx.config
199202
wq = WorkerQueue(max_workers)
200203

204+
pairs_a = set()
205+
pairs_b = set()
206+
pairs_b_path = {}
201207
with wq.join():
202208
for pair_name in (pairs or config.pairs):
203209
pair = config.get_pair(pair_name)
@@ -210,6 +216,22 @@ def discover(ctx, pairs, max_workers, list):
210216
list_collections=list,
211217
))
212218
wq.spawn_worker()
219+
if pair.config_b['type'] == 'filesystem':
220+
for key in _DiscoverResult(pair.config_b)._discovered.keys():
221+
pairs_b.add(key)
222+
pairs_b_path[key] = (pair.config_b["path"], pair.name)
223+
pairs_a = pairs_a.union(set(_DiscoverResult(pair.config_a)._discovered.keys()))
224+
225+
for dele in pairs_b - pairs_a:
226+
path = pairs_b_path[dele][0] + '/' + dele
227+
if not os.path.islink(path):
228+
shutil.rmtree(path, ignore_errors=True)
229+
path = expand_path(os.path.join(config.general['status_path'], pairs_b_path[dele][1] + '/' + dele))
230+
for m in ('items', 'metadata'):
231+
try:
232+
os.remove(path + '.' + m)
233+
except:
234+
pass
213235

214236

215237
@app.command()
@@ -243,3 +265,5 @@ def repair(ctx, collection, repair_unsafe_uid):
243265
click.confirm('Do you want to continue?', abort=True)
244266
repair_collection(ctx.config, collection,
245267
repair_unsafe_uid=repair_unsafe_uid)
268+
269+
from .discover import _DiscoverResult

0 commit comments

Comments
 (0)