From 9ade92c0269c0993b9d4f19c622f3d8625c47900 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 28 May 2016 22:36:40 +0200 Subject: [PATCH 1/4] Always release lock --- radicale/storage.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/radicale/storage.py b/radicale/storage.py index b135f20..b63a3e5 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -578,23 +578,26 @@ class Collection(BaseCollection): except OSError: cls.logger.debug("Locking not supported") cls._lock_file_locked = True - yield - with cls._lock: - if mode == "r": - cls._readers -= 1 - else: - cls._writer = False - if cls._readers == 0: - if os.name == "nt": - handle = msvcrt.get_osfhandle(cls._lock_file.fileno()) - overlapped = Overlapped() - if not unlock_file_ex(handle, 0, 1, 0, overlapped): - cls.logger.debug("Unlocking not supported") - elif os.name == "posix": - try: - fcntl.lockf(cls._lock_file.fileno(), fcntl.LOCK_UN) - except OSError: - cls.logger.debug("Unlocking not supported") - cls._lock_file_locked = False - if cls._waiters: - cls._waiters[0].notify() + try: + yield + finally: + with cls._lock: + if mode == "r": + cls._readers -= 1 + else: + cls._writer = False + if cls._readers == 0: + if os.name == "nt": + handle = msvcrt.get_osfhandle(cls._lock_file.fileno()) + overlapped = Overlapped() + if not unlock_file_ex(handle, 0, 1, 0, overlapped): + cls.logger.debug("Unlocking not supported") + elif os.name == "posix": + try: + fcntl.lockf(cls._lock_file.fileno(), + fcntl.LOCK_UN) + except OSError: + cls.logger.debug("Unlocking not supported") + cls._lock_file_locked = False + if cls._waiters: + cls._waiters[0].notify() From 28e643dec1440f738f33a02c58a1d2173c64e21b Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 28 May 2016 22:46:20 +0200 Subject: [PATCH 2/4] Don't pass None to vobject.readComponents If an empty collections is created with PUT, content is None. --- radicale/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index fb23675..bf9e149 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -546,7 +546,7 @@ class Application: # Case 1: No item and no ETag precondition: Add new item # Case 2: Item and ETag precondition verified: Modify item # Case 3: Item and no Etag precondition: Force modifying item - items = list(vobject.readComponents(content)) + items = list(vobject.readComponents(content or "")) if items: if item: # PUT is modifying an existing item From af1dce1504ef9651a4c918295cbeb49805cbf179 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 28 May 2016 23:49:15 +0200 Subject: [PATCH 3/4] Fix crash on unknown content type --- radicale/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index fb23675..2dc78e0 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -533,7 +533,9 @@ class Application: content_type = environ.get("CONTENT_TYPE") if content_type: tags = {value: key for key, value in storage.MIMETYPES.items()} - collection.set_meta("tag", tags[content_type.split(";")[0]]) + tag = tags.get(content_type.split(";")[0]) + if tag: + collection.set_meta("tag", tag) headers = {} item_name = xmlutils.name_from_path(environ["PATH_INFO"], collection) item = collection.get(item_name) From 4861b798780375435e785b2558f0ef7e3e0ff5a0 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sun, 29 May 2016 01:18:29 +0200 Subject: [PATCH 4/4] Allow creation of empty collection via PUT --- radicale/__init__.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index bf9e149..6c73b12 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -547,20 +547,25 @@ class Application: # Case 2: Item and ETag precondition verified: Modify item # Case 3: Item and no Etag precondition: Force modifying item items = list(vobject.readComponents(content or "")) - if items: - if item: - # PUT is modifying an existing item + if item: + # PUT is modifying an existing item + if items: new_item = collection.update(item_name, items[0]) - elif item_name: - # PUT is adding a new item + else: + new_item = None + elif item_name: + # PUT is adding a new item + if items: new_item = collection.upload(item_name, items[0]) else: - # PUT is replacing the whole collection - collection.delete() - new_item = self.Collection.create_collection( - environ["PATH_INFO"], items) - if new_item: - headers["ETag"] = new_item.etag + new_item = None + else: + # PUT is replacing the whole collection + collection.delete() + new_item = self.Collection.create_collection( + environ["PATH_INFO"], items) + if new_item: + headers["ETag"] = new_item.etag status = client.CREATED else: # PUT rejected in all other cases