From 13c693ba35f0ebc6a40c29df53e9967996fa52d2 Mon Sep 17 00:00:00 2001 From: Unrud Date: Tue, 2 Aug 2016 16:29:34 +0200 Subject: [PATCH] Properties inside of collection * Creation and deletion of collections can be atomic. * The properties file of the root collection is not outside of the filesystem_folder. * It's easier to delete and move collections by hand. * This breaks backward compatibility. --- radicale/storage.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/radicale/storage.py b/radicale/storage.py index 129bf8b..c59faa0 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -333,6 +333,8 @@ class Collection(BaseCollection): self.path = sanitize_path(path).strip("/") self.storage_encoding = self.configuration.get("encoding", "stock") self._filesystem_path = path_to_filesystem(folder, self.path) + self._props_path = path_to_filesystem(self._filesystem_path, + "collection.props") split_path = self.path.split("/") if len(split_path) > 1: # URL with at least one folder @@ -520,9 +522,6 @@ class Collection(BaseCollection): # Delete the collection if os.path.isdir(self._filesystem_path): shutil.rmtree(self._filesystem_path) - props_path = self._filesystem_path + ".props" - if os.path.isfile(props_path): - os.remove(props_path) else: # Delete an item if not is_safe_filesystem_path_component(href): @@ -539,16 +538,14 @@ class Collection(BaseCollection): os.remove(path) def get_meta(self, key): - props_path = self._filesystem_path + ".props" - if os.path.exists(props_path): - with open(props_path, encoding=self.storage_encoding) as prop: + if os.path.exists(self._props_path): + with open(self._props_path, encoding=self.storage_encoding) as prop: return json.load(prop).get(key) def set_meta(self, key, value): - props_path = self._filesystem_path + ".props" properties = {} - if os.path.exists(props_path): - with open(props_path, encoding=self.storage_encoding) as prop: + if os.path.exists(self._props_path): + with open(self._props_path, encoding=self.storage_encoding) as prop: properties.update(json.load(prop)) if value: @@ -556,7 +553,7 @@ class Collection(BaseCollection): else: properties.pop(key, None) - with self._atomic_write(props_path, "w+") as prop: + with self._atomic_write(self._props_path, "w+") as prop: json.dump(properties, prop) @property