Ignore fs collections that have subfolders (#591)

Fix #588
This commit is contained in:
Markus Unterwaditzer 2017-03-09 13:40:27 +01:00 committed by GitHub
parent feea65ff1d
commit a285c555f0
2 changed files with 22 additions and 4 deletions

View file

@ -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'}

View file

@ -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):