Improve errorhandling in multifilesystem
If the collection doesn't exist yet, OSError(2, 'No such file or directory') is raised. https://travis-ci.org/untitaker/vdirsyncer/jobs/42540595
This commit is contained in:
parent
ce9fd74d98
commit
d300949fe8
@ -29,6 +29,7 @@ import sys
|
||||
|
||||
from . import filesystem
|
||||
from .. import ical
|
||||
from .. import log
|
||||
|
||||
|
||||
class Collection(filesystem.Collection):
|
||||
@ -69,14 +70,23 @@ class Collection(filesystem.Collection):
|
||||
ical.Timezone, ical.Event, ical.Todo, ical.Journal, ical.Card)
|
||||
items = set()
|
||||
try:
|
||||
for filename in os.listdir(self._path):
|
||||
with filesystem.open(os.path.join(self._path, filename)) as fd:
|
||||
items.update(self._parse(fd.read(), components))
|
||||
except IOError:
|
||||
filenames = os.listdir(self._path)
|
||||
except (OSError, IOError) as e:
|
||||
log.LOGGER.info('Error while reading collection %r: %r'
|
||||
% (self._path, e))
|
||||
return ""
|
||||
else:
|
||||
return ical.serialize(
|
||||
self.tag, self.headers, sorted(items, key=lambda x: x.name))
|
||||
|
||||
for filename in filenames:
|
||||
path = os.path.join(self._path, filename)
|
||||
try:
|
||||
with filesystem.open(path) as fd:
|
||||
items.update(self._parse(fd.read(), components))
|
||||
except (OSError, IOError) as e:
|
||||
log.LOGGER.warning('Error while reading item %r: %r'
|
||||
% (path, e))
|
||||
|
||||
return ical.serialize(
|
||||
self.tag, self.headers, sorted(items, key=lambda x: x.name))
|
||||
|
||||
@classmethod
|
||||
def is_node(cls, path):
|
||||
|
Loading…
x
Reference in New Issue
Block a user