Skip to content

Add option to delete a local collection, when it is deleted on the server #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dilyanpalauzov opened this issue Jun 17, 2020 · 2 comments

Comments

@dilyanpalauzov
Copy link
Contributor

I want to delete local collections, when on the server the collection is deleted. I use Vdirsyncer 0.17 (rust).

I also want that when on the server a collection is created, that it is created locally on the next synchronization, but I achivede this by changing in vdirsyncer/cli/utils.py:handle_collections_not_found: `if click.confirm('Should vdirsyncer attempt to create it?)'

  • add a command line option to vdirsyncer, that deletes local collection, when these are deleted on the server.
@dilyanpalauzov
Copy link
Contributor Author

Something like this on current master (when the direction is collection=["from a"] and b is type="filesystem":

diff --git a/vdirsyncer/cli/discover.py b/vdirsyncer/cli/discover.py
--- a/vdirsyncer/cli/discover.py
+++ b/vdirsyncer/cli/discover.py
@@ -1,6 +1,8 @@
 import hashlib
 import json
 import logging
+import os
+import shutil
 import sys
 
 from .. import exceptions
@@ -9,6 +11,7 @@ from .utils import handle_collection_not_found
 from .utils import handle_storage_init_error
 from .utils import load_status
 from .utils import save_status
+from .utils import get_status_path
 from .utils import storage_class_from_config
 from .utils import storage_instance_from_config
 
@@ -63,6 +66,19 @@ def collections_for_pair(status_path, pair, from_cache=True,
 
     a_discovered = _DiscoverResult(pair.config_a)
     b_discovered = _DiscoverResult(pair.config_b)
+    if pair.config_b['type'] == 'filesystem':
+        for dele in set(b_discovered._discovered.keys()) - set(a_discovered._discovered.keys()):
+            path = pair.config_b['path'] + '/' + dele
+            if not os.path.islink(path):
+                shutil.rmtree(path, ignore_errors=True)
+                try:
+                    os.remove(get_status_path(status_path, pair.name, dele, 'items'))
+                except:
+                    pass
+                try:
+                    os.remove(get_status_path(status_path, pair.name, dele, 'metadata'))
+                except:
+                    pass
 
     if list_collections:
         _print_collections(pair.config_a['instance_name'],

@dilyanpalauzov
Copy link
Contributor Author

Moved to #868. “It works for me.”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant