mirror of
https://github.com/Kozea/Radicale.git
synced 2025-09-15 20:36:55 +00:00
Split BaseCollection into BaseStorage and BaseCollection
This commit is contained in:
parent
1453c0b72c
commit
040d8c0fff
15 changed files with 221 additions and 213 deletions
|
@ -21,9 +21,11 @@ import os
|
|||
from radicale import pathutils
|
||||
|
||||
|
||||
class CollectionMoveMixin:
|
||||
@classmethod
|
||||
def move(cls, item, to_collection, to_href):
|
||||
class StorageMoveMixin:
|
||||
def __init__(self, configuration):
|
||||
super().__init__(configuration)
|
||||
|
||||
def move(self, item, to_collection, to_href):
|
||||
if not pathutils.is_safe_filesystem_path_component(to_href):
|
||||
raise pathutils.UnsafePathError(to_href)
|
||||
os.replace(
|
||||
|
@ -31,24 +33,24 @@ class CollectionMoveMixin:
|
|||
item.collection._filesystem_path, item.href),
|
||||
pathutils.path_to_filesystem(
|
||||
to_collection._filesystem_path, to_href))
|
||||
cls._sync_directory(to_collection._filesystem_path)
|
||||
self._sync_directory(to_collection._filesystem_path)
|
||||
if item.collection._filesystem_path != to_collection._filesystem_path:
|
||||
cls._sync_directory(item.collection._filesystem_path)
|
||||
self._sync_directory(item.collection._filesystem_path)
|
||||
# Move the item cache entry
|
||||
cache_folder = os.path.join(item.collection._filesystem_path,
|
||||
".Radicale.cache", "item")
|
||||
to_cache_folder = os.path.join(to_collection._filesystem_path,
|
||||
".Radicale.cache", "item")
|
||||
cls._makedirs_synced(to_cache_folder)
|
||||
self._makedirs_synced(to_cache_folder)
|
||||
try:
|
||||
os.replace(os.path.join(cache_folder, item.href),
|
||||
os.path.join(to_cache_folder, to_href))
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
else:
|
||||
cls._makedirs_synced(to_cache_folder)
|
||||
self._makedirs_synced(to_cache_folder)
|
||||
if cache_folder != to_cache_folder:
|
||||
cls._makedirs_synced(cache_folder)
|
||||
self._makedirs_synced(cache_folder)
|
||||
# Track the change
|
||||
to_collection._update_history_etag(to_href, item)
|
||||
item.collection._update_history_etag(item.href, None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue