From 5a9d956b492dea5f77f093147ef9d6a06d542e1a Mon Sep 17 00:00:00 2001 From: Unrud Date: Mon, 1 Aug 2016 13:44:27 +0200 Subject: [PATCH] delete atomic and durable See #440 --- radicale/storage.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/radicale/storage.py b/radicale/storage.py index d14797f..97f168a 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -580,7 +580,21 @@ class Collection(BaseCollection): if href is None: # Delete the collection if os.path.isdir(self._filesystem_path): - shutil.rmtree(self._filesystem_path) + try: + os.rmdir(self._filesystem_path) + except OSError: + while True: + tmp_filesystem_path = os.path.join( + os.path.dirname(self._filesystem_path), + ".Radicale.tmp-" + hex(getrandbits(32))[2:]) + if not os.path.exists(tmp_filesystem_path): + break + os.rename(self._filesystem_path, tmp_filesystem_path) + sync_directory(os.path.dirname(self._filesystem_path)) + # Deferred because it might take a long time + shutil.rmtree(tmp_filesystem_path) + else: + sync_directory(os.path.dirname(self._filesystem_path)) else: # Delete an item if not is_safe_filesystem_path_component(href): @@ -593,6 +607,7 @@ class Collection(BaseCollection): if etag and etag != get_etag(text): raise EtagMismatchError(etag, get_etag(text)) os.remove(path) + sync_directory(os.path.dirname(path)) def get_meta(self, key): if os.path.exists(self._props_path):