Merge pull request #236 from untitaker/multifilesystem_fixes

Improve errorhandling in multifilesystem
This commit is contained in:
Guillaume Ayoub 2015-08-21 16:58:26 +02:00
commit 90f4b48f98

View File

@ -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,14 +70,23 @@ 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:
return ical.serialize( for filename in filenames:
self.tag, self.headers, sorted(items, key=lambda x: x.name)) 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 @classmethod
def is_node(cls, path): def is_node(cls, path):