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 filesystem
|
||||||
from .. import ical
|
from .. import ical
|
||||||
|
from .. import log
|
||||||
|
|
||||||
|
|
||||||
class Collection(filesystem.Collection):
|
class Collection(filesystem.Collection):
|
||||||
@ -69,12 +70,21 @@ class Collection(filesystem.Collection):
|
|||||||
ical.Timezone, ical.Event, ical.Todo, ical.Journal, ical.Card)
|
ical.Timezone, ical.Event, ical.Todo, ical.Journal, ical.Card)
|
||||||
items = set()
|
items = set()
|
||||||
try:
|
try:
|
||||||
for filename in os.listdir(self._path):
|
filenames = os.listdir(self._path)
|
||||||
with filesystem.open(os.path.join(self._path, filename)) as fd:
|
except (OSError, IOError) as e:
|
||||||
items.update(self._parse(fd.read(), components))
|
log.LOGGER.info('Error while reading collection %r: %r'
|
||||||
except IOError:
|
% (self._path, e))
|
||||||
return ""
|
return ""
|
||||||
else:
|
|
||||||
|
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(
|
return ical.serialize(
|
||||||
self.tag, self.headers, sorted(items, key=lambda x: x.name))
|
self.tag, self.headers, sorted(items, key=lambda x: x.name))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user