Move collections into collection-root folder
This is required for atomic creation and deletion of the "/" collection.
This commit is contained in:
parent
bd7641699e
commit
e34d1c46cd
@ -327,8 +327,7 @@ class Collection(BaseCollection):
|
|||||||
"""Collection stored in several files per calendar."""
|
"""Collection stored in several files per calendar."""
|
||||||
|
|
||||||
def __init__(self, path, principal=False):
|
def __init__(self, path, principal=False):
|
||||||
folder = os.path.expanduser(
|
folder = self._get_collection_root_folder()
|
||||||
self.configuration.get("storage", "filesystem_folder"))
|
|
||||||
# path should already be sanitized
|
# path should already be sanitized
|
||||||
self.path = sanitize_path(path).strip("/")
|
self.path = sanitize_path(path).strip("/")
|
||||||
self.storage_encoding = self.configuration.get("encoding", "stock")
|
self.storage_encoding = self.configuration.get("encoding", "stock")
|
||||||
@ -343,6 +342,13 @@ class Collection(BaseCollection):
|
|||||||
self.owner = None
|
self.owner = None
|
||||||
self.is_principal = principal
|
self.is_principal = principal
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _get_collection_root_folder(cls):
|
||||||
|
filesystem_folder = os.path.expanduser(
|
||||||
|
cls.configuration.get("storage", "filesystem_folder"))
|
||||||
|
folder = os.path.join(filesystem_folder, "collection-root")
|
||||||
|
return folder
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def _atomic_write(self, path, mode="w"):
|
def _atomic_write(self, path, mode="w"):
|
||||||
with _EncodedAtomicWriter(
|
with _EncodedAtomicWriter(
|
||||||
@ -370,8 +376,11 @@ class Collection(BaseCollection):
|
|||||||
attributes.pop()
|
attributes.pop()
|
||||||
|
|
||||||
# Try to guess if the path leads to a collection or an item
|
# Try to guess if the path leads to a collection or an item
|
||||||
folder = os.path.expanduser(
|
folder = cls._get_collection_root_folder()
|
||||||
cls.configuration.get("storage", "filesystem_folder"))
|
# HACK: Detection of principal collections fails if folder doesn't
|
||||||
|
# exist. This can be removed, when this method stop returning
|
||||||
|
# collections that don't exist.
|
||||||
|
os.makedirs(folder, exist_ok=True)
|
||||||
if not os.path.isdir(path_to_filesystem(folder, sane_path)):
|
if not os.path.isdir(path_to_filesystem(folder, sane_path)):
|
||||||
# path is not a collection
|
# path is not a collection
|
||||||
if attributes and os.path.isfile(path_to_filesystem(folder,
|
if attributes and os.path.isfile(path_to_filesystem(folder,
|
||||||
@ -406,8 +415,7 @@ class Collection(BaseCollection):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_collection(cls, href, collection=None, tag=None):
|
def create_collection(cls, href, collection=None, tag=None):
|
||||||
folder = os.path.expanduser(
|
folder = cls._get_collection_root_folder()
|
||||||
cls.configuration.get("storage", "filesystem_folder"))
|
|
||||||
path = path_to_filesystem(folder, href)
|
path = path_to_filesystem(folder, href)
|
||||||
|
|
||||||
self = cls(href)
|
self = cls(href)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user