Преглед на файлове

try/catch of objects avoiding not serving any object in case an object has no valid contents
also log duration of how many objects are read per folder

Peter Bieringer преди 9 години
родител
ревизия
cd97aab72c
променени са 1 файла, в които са добавени 8 реда и са изтрити 1 реда
  1. 8 1
      radicale/storage.py

+ 8 - 1
radicale/storage.py

@@ -34,6 +34,7 @@ import stat
 import subprocess
 import threading
 import time
+import datetime
 from contextlib import contextmanager
 from hashlib import md5
 from importlib import import_module
@@ -699,6 +700,7 @@ class Collection(BaseCollection):
         if not os.path.exists(self._filesystem_path):
             return None
         items = []
+        time_begin = datetime.datetime.now()
         for href in os.listdir(self._filesystem_path):
             if not is_safe_filesystem_path_component(href):
                 self.logger.debug("Skipping component: %s", href)
@@ -707,7 +709,12 @@ class Collection(BaseCollection):
             if os.path.isfile(path):
                 self.logger.debug("Read object: %s", path)
                 with open(path, encoding=self.encoding, newline="") as fd:
-                    items.append(vobject.readOne(fd.read()))
+                    try:
+                        items.append(vobject.readOne(fd.read()))
+                    except:
+                        self.logger.error("Object broken (skip): %s", path)
+        time_end = datetime.datetime.now()
+        self.logger.info("Collection read %d items in %s sec from %s", len(items),(time_end - time_begin).total_seconds(), self._filesystem_path)
         if self.get_meta("tag") == "VCALENDAR":
             collection = vobject.iCalendar()
             for item in items: