diff --git a/radicale/__init__.py b/radicale/__init__.py index d951528..4267d61 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -267,8 +267,15 @@ class Application(object): def delete(self, environ, calendars, content, user): """Manage DELETE request.""" calendar = calendars[0] - item = calendar.get_item( - xmlutils.name_from_path(environ["PATH_INFO"], calendar)) + + if calendar.local_path == environ["PATH_INFO"].strip("/"): + # Path matching the calendar, the item to delete is the calendar + item = calendar + else: + # Try to get an item matching the path + item = calendar.get_item( + xmlutils.name_from_path(environ["PATH_INFO"], calendar)) + if item and environ.get("HTTP_IF_MATCH", item.etag) == item.etag: # No ETag precondition or precondition verified, delete item answer = xmlutils.delete(environ["PATH_INFO"], calendar) diff --git a/radicale/ical.py b/radicale/ical.py index 53a292a..3c07d3c 100644 --- a/radicale/ical.py +++ b/radicale/ical.py @@ -172,6 +172,7 @@ class Calendar(object): self.encoding = "utf-8" split_path = path.split("/") self.path = os.path.join(FOLDER, path.replace("/", os.sep)) + self.props_path = self.path + '.props' if principal and split_path and os.path.isdir(self.path): # Already existing principal calendar self.owner = split_path[0] @@ -300,6 +301,11 @@ class Calendar(object): self.write(items=items) + def delete(self): + """Delete the calendar.""" + os.remove(self.path) + os.remove(self.props_path) + def remove(self, name): """Remove object named ``name`` from calendar.""" components = [ @@ -415,16 +421,15 @@ class Calendar(object): @contextmanager def props(self): """Get the calendar properties.""" - props_path = self.path + '.props' # On enter properties = {} - if os.path.exists(props_path): - with open(props_path) as prop_file: + if os.path.exists(self.props_path): + with open(self.props_path) as prop_file: properties.update(json.load(prop_file)) yield properties # On exit - self._create_dirs(props_path) - with open(props_path, 'w') as prop_file: + self._create_dirs(self.props_path) + with open(self.props_path, 'w') as prop_file: json.dump(properties, prop_file) @property diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 3e08ec5..1b0163d 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -153,7 +153,12 @@ def delete(path, calendar): """ # Reading request - calendar.remove(name_from_path(path, calendar)) + if calendar.local_path == path.strip("/"): + # Delete the whole calendar + calendar.delete() + else: + # Remove an item from the calendar + calendar.remove(name_from_path(path, calendar)) # Writing answer multistatus = ET.Element(_tag("D", "multistatus"))