Don't raise errors if directories don't exist

This commit is contained in:
Markus Unterwaditzer 2014-12-26 00:49:18 +01:00
parent 11c9541b53
commit 4757fac383

View file

@ -50,12 +50,18 @@ class FilesystemStorage(Storage):
if kwargs.pop('collection', None) is not None: if kwargs.pop('collection', None) is not None:
raise TypeError('collection argument must not be given.') raise TypeError('collection argument must not be given.')
path = expand_path(path) path = expand_path(path)
for collection in os.listdir(path): try:
collection_path = os.path.join(path, collection) collections = os.listdir(path)
if os.path.isdir(collection_path): except OSError:
args = dict(collection=collection, path=collection_path, if not kwargs.get('create', True):
**kwargs) raise
yield args 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
@classmethod @classmethod
def join_collection(cls, collection, **kwargs): def join_collection(cls, collection, **kwargs):