mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-28 09:25:50 +00:00
Fix several bugs with collection creation in filesystem storage
See #179
This commit is contained in:
parent
6f77a9242c
commit
dec08780f3
3 changed files with 25 additions and 18 deletions
|
|
@ -184,17 +184,13 @@ def _discover_from_config(config):
|
|||
return rv
|
||||
|
||||
|
||||
def _get_coll(pair_name, storage_name, collection, discovered, config):
|
||||
try:
|
||||
return discovered[collection]
|
||||
except KeyError:
|
||||
return _handle_collection_not_found(config, collection)
|
||||
|
||||
|
||||
def _handle_collection_not_found(config, collection):
|
||||
def _handle_collection_not_found(config, collection, e=None):
|
||||
storage_name = config.get('instance_name', None)
|
||||
cli_logger.error('No collection {} found for storage {}.'
|
||||
.format(collection, storage_name))
|
||||
|
||||
cli_logger.error('{}No collection {} found for storage {}.'
|
||||
.format('{}\n'.format(e) if e else '',
|
||||
collection, storage_name))
|
||||
|
||||
if click.confirm('Should vdirsyncer attempt to create it?'):
|
||||
storage_type = config['type']
|
||||
cls, config = storage_class_from_config(config)
|
||||
|
|
@ -230,10 +226,16 @@ def _collections_for_pair_impl(status_path, name_a, name_b, pair_name,
|
|||
collections = [shortcut]
|
||||
|
||||
for collection in collections:
|
||||
a_args = _get_coll(pair_name, name_a, collection, a_discovered,
|
||||
config_a)
|
||||
b_args = _get_coll(pair_name, name_b, collection, b_discovered,
|
||||
config_b)
|
||||
try:
|
||||
a_args = a_discovered[collection]
|
||||
except KeyError:
|
||||
a_args = _handle_collection_not_found(config_a, collection)
|
||||
|
||||
try:
|
||||
b_args = b_discovered[collection]
|
||||
except KeyError:
|
||||
b_args = _handle_collection_not_found(config_b, collection)
|
||||
|
||||
yield collection, (a_args, b_args)
|
||||
|
||||
|
||||
|
|
@ -412,9 +414,9 @@ def storage_instance_from_config(config, create=True):
|
|||
try:
|
||||
return cls(**new_config)
|
||||
except exceptions.CollectionNotFound as e:
|
||||
cli_logger.error(str(e))
|
||||
if create:
|
||||
_handle_collection_not_found(config, None)
|
||||
config = _handle_collection_not_found(
|
||||
config, config.get('collection', None), e=str(e))
|
||||
return storage_instance_from_config(config, create=False)
|
||||
else:
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -104,10 +104,14 @@ class Storage(with_metaclass(StorageMeta)):
|
|||
|
||||
@classmethod
|
||||
def create_collection(cls, collection, **kwargs):
|
||||
'''Create the specified collection and return the new arguments.
|
||||
'''
|
||||
Create the specified collection and return the new arguments.
|
||||
|
||||
``collection=None`` means the arguments are already pointing to a
|
||||
possible collection location.'''
|
||||
possible collection location.
|
||||
|
||||
The returned args should contain the collection name, for UI purposes.
|
||||
'''
|
||||
raise NotImplementedError()
|
||||
|
||||
def __repr__(self):
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ class FilesystemStorage(Storage):
|
|||
if collection is not None:
|
||||
kwargs['path'] = os.path.join(kwargs['path'], collection)
|
||||
checkdir(kwargs['path'], create=True)
|
||||
kwargs['collection'] = collection
|
||||
return kwargs
|
||||
|
||||
def _get_filepath(self, href):
|
||||
|
|
|
|||
Loading…
Reference in a new issue