Merge branch 'master' of github.com:Kozea/radicale
This commit is contained in:
commit
5b6f0784d0
@ -533,7 +533,9 @@ class Application:
|
|||||||
content_type = environ.get("CONTENT_TYPE")
|
content_type = environ.get("CONTENT_TYPE")
|
||||||
if content_type:
|
if content_type:
|
||||||
tags = {value: key for key, value in storage.MIMETYPES.items()}
|
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 = {}
|
headers = {}
|
||||||
item_name = xmlutils.name_from_path(environ["PATH_INFO"], collection)
|
item_name = xmlutils.name_from_path(environ["PATH_INFO"], collection)
|
||||||
item = collection.get(item_name)
|
item = collection.get(item_name)
|
||||||
@ -546,21 +548,26 @@ class Application:
|
|||||||
# Case 1: No item and no ETag precondition: Add new item
|
# Case 1: No item and no ETag precondition: Add new item
|
||||||
# Case 2: Item and ETag precondition verified: Modify item
|
# Case 2: Item and ETag precondition verified: Modify item
|
||||||
# Case 3: Item and no Etag precondition: Force modifying 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:
|
||||||
if item:
|
# PUT is modifying an existing item
|
||||||
# PUT is modifying an existing item
|
if items:
|
||||||
new_item = collection.update(item_name, items[0])
|
new_item = collection.update(item_name, items[0])
|
||||||
elif item_name:
|
else:
|
||||||
# PUT is adding a new item
|
new_item = None
|
||||||
|
elif item_name:
|
||||||
|
# PUT is adding a new item
|
||||||
|
if items:
|
||||||
new_item = collection.upload(item_name, items[0])
|
new_item = collection.upload(item_name, items[0])
|
||||||
else:
|
else:
|
||||||
# PUT is replacing the whole collection
|
new_item = None
|
||||||
collection.delete()
|
else:
|
||||||
new_item = self.Collection.create_collection(
|
# PUT is replacing the whole collection
|
||||||
environ["PATH_INFO"], items)
|
collection.delete()
|
||||||
if new_item:
|
new_item = self.Collection.create_collection(
|
||||||
headers["ETag"] = new_item.etag
|
environ["PATH_INFO"], items)
|
||||||
|
if new_item:
|
||||||
|
headers["ETag"] = new_item.etag
|
||||||
status = client.CREATED
|
status = client.CREATED
|
||||||
else:
|
else:
|
||||||
# PUT rejected in all other cases
|
# PUT rejected in all other cases
|
||||||
|
@ -578,23 +578,26 @@ class Collection(BaseCollection):
|
|||||||
except OSError:
|
except OSError:
|
||||||
cls.logger.debug("Locking not supported")
|
cls.logger.debug("Locking not supported")
|
||||||
cls._lock_file_locked = True
|
cls._lock_file_locked = True
|
||||||
yield
|
try:
|
||||||
with cls._lock:
|
yield
|
||||||
if mode == "r":
|
finally:
|
||||||
cls._readers -= 1
|
with cls._lock:
|
||||||
else:
|
if mode == "r":
|
||||||
cls._writer = False
|
cls._readers -= 1
|
||||||
if cls._readers == 0:
|
else:
|
||||||
if os.name == "nt":
|
cls._writer = False
|
||||||
handle = msvcrt.get_osfhandle(cls._lock_file.fileno())
|
if cls._readers == 0:
|
||||||
overlapped = Overlapped()
|
if os.name == "nt":
|
||||||
if not unlock_file_ex(handle, 0, 1, 0, overlapped):
|
handle = msvcrt.get_osfhandle(cls._lock_file.fileno())
|
||||||
cls.logger.debug("Unlocking not supported")
|
overlapped = Overlapped()
|
||||||
elif os.name == "posix":
|
if not unlock_file_ex(handle, 0, 1, 0, overlapped):
|
||||||
try:
|
cls.logger.debug("Unlocking not supported")
|
||||||
fcntl.lockf(cls._lock_file.fileno(), fcntl.LOCK_UN)
|
elif os.name == "posix":
|
||||||
except OSError:
|
try:
|
||||||
cls.logger.debug("Unlocking not supported")
|
fcntl.lockf(cls._lock_file.fileno(),
|
||||||
cls._lock_file_locked = False
|
fcntl.LOCK_UN)
|
||||||
if cls._waiters:
|
except OSError:
|
||||||
cls._waiters[0].notify()
|
cls.logger.debug("Unlocking not supported")
|
||||||
|
cls._lock_file_locked = False
|
||||||
|
if cls._waiters:
|
||||||
|
cls._waiters[0].notify()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user