From a285c555f02a0a85ebb1c19746914582bcb27526 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 9 Mar 2017 13:40:27 +0100 Subject: [PATCH] Ignore fs collections that have subfolders (#591) Fix #588 --- tests/storage/test_filesystem.py | 7 +++++++ vdirsyncer/storage/filesystem.py | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/storage/test_filesystem.py b/tests/storage/test_filesystem.py index ddaa567..3dcd5ff 100644 --- a/tests/storage/test_filesystem.py +++ b/tests/storage/test_filesystem.py @@ -77,3 +77,10 @@ class TestFilesystemStorage(StorageTests): s = self.storage_class(str(tmpdir), '.txt', post_hook=exe) s.upload(Item(u'UID:a/b/c')) assert calls + + def test_ignore_git_dirs(self, tmpdir): + tmpdir.mkdir('.git').mkdir('foo') + tmpdir.mkdir('a') + tmpdir.mkdir('b') + assert set(c['collection'] for c + in self.storage_class.discover(str(tmpdir))) == {'a', 'b'} diff --git a/vdirsyncer/storage/filesystem.py b/vdirsyncer/storage/filesystem.py index df0072a..fea644a 100644 --- a/vdirsyncer/storage/filesystem.py +++ b/vdirsyncer/storage/filesystem.py @@ -62,10 +62,21 @@ class FilesystemStorage(Storage): else: for collection in collections: collection_path = os.path.join(path, collection) - if os.path.isdir(collection_path): - args = dict(collection=collection, path=collection_path, - **kwargs) - yield args + if not cls._validate_collection(collection_path): + continue + args = dict(collection=collection, path=collection_path, + **kwargs) + yield args + + @classmethod + def _validate_collection(cls, path): + if not os.path.isdir(path): + return False + for item in os.listdir(path): + item_path = os.path.join(path, item) + if os.path.isdir(item_path): + return False + return True @classmethod def create_collection(cls, collection, **kwargs):