From 4757fac383bb581e107d19e86bc0e0a8e33e5d4c Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Fri, 26 Dec 2014 00:49:18 +0100 Subject: [PATCH] Don't raise errors if directories don't exist --- vdirsyncer/storage/filesystem.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/vdirsyncer/storage/filesystem.py b/vdirsyncer/storage/filesystem.py index 9dc28e5..f656b7f 100644 --- a/vdirsyncer/storage/filesystem.py +++ b/vdirsyncer/storage/filesystem.py @@ -50,12 +50,18 @@ class FilesystemStorage(Storage): if kwargs.pop('collection', None) is not None: raise TypeError('collection argument must not be given.') path = expand_path(path) - for collection in os.listdir(path): - collection_path = os.path.join(path, collection) - if os.path.isdir(collection_path): - args = dict(collection=collection, path=collection_path, - **kwargs) - yield args + try: + collections = os.listdir(path) + except OSError: + if not kwargs.get('create', True): + raise + 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 def join_collection(cls, collection, **kwargs):