Document _makedirs_synced and remove exist_ok
This commit is contained in:
parent
4549d1b2db
commit
4236077b04
@ -428,16 +428,21 @@ class Collection(BaseCollection):
|
|||||||
raise FileExistsError(errno.EEXIST, "No usable file name found")
|
raise FileExistsError(errno.EEXIST, "No usable file name found")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _makedirs_synced(cls, filesystem_path, exist_ok=False):
|
def _makedirs_synced(cls, filesystem_path):
|
||||||
if os.path.isdir(filesystem_path) and exist_ok:
|
"""Recursively create a directory and its parents in a sync'ed way.
|
||||||
|
|
||||||
|
This method acts silently when the folder already exists.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if os.path.isdir(filesystem_path):
|
||||||
return
|
return
|
||||||
parent_filesystem_path = os.path.dirname(filesystem_path)
|
parent_filesystem_path = os.path.dirname(filesystem_path)
|
||||||
# Prevent infinite loop
|
# Prevent infinite loop
|
||||||
if filesystem_path != parent_filesystem_path:
|
if filesystem_path != parent_filesystem_path:
|
||||||
# Create parent dirs recursively
|
# Create parent dirs recursively
|
||||||
cls._makedirs_synced(parent_filesystem_path, exist_ok=True)
|
cls._makedirs_synced(parent_filesystem_path)
|
||||||
# Possible race!
|
# Possible race!
|
||||||
os.makedirs(filesystem_path, exist_ok=exist_ok)
|
os.makedirs(filesystem_path, exist_ok=True)
|
||||||
sync_directory(parent_filesystem_path)
|
sync_directory(parent_filesystem_path)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -454,7 +459,7 @@ class Collection(BaseCollection):
|
|||||||
|
|
||||||
folder = cls._get_collection_root_folder()
|
folder = cls._get_collection_root_folder()
|
||||||
# Create the root collection
|
# Create the root collection
|
||||||
cls._makedirs_synced(folder, exist_ok=True)
|
cls._makedirs_synced(folder)
|
||||||
try:
|
try:
|
||||||
filesystem_path = path_to_filesystem(folder, sane_path)
|
filesystem_path = path_to_filesystem(folder, sane_path)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -512,11 +517,11 @@ class Collection(BaseCollection):
|
|||||||
if not props.get("tag") and collection:
|
if not props.get("tag") and collection:
|
||||||
props["tag"] = collection[0].name
|
props["tag"] = collection[0].name
|
||||||
if not props:
|
if not props:
|
||||||
cls._makedirs_synced(filesystem_path, exist_ok=True)
|
cls._makedirs_synced(filesystem_path)
|
||||||
return cls(sane_path, principal=principal)
|
return cls(sane_path, principal=principal)
|
||||||
|
|
||||||
parent_dir = os.path.dirname(filesystem_path)
|
parent_dir = os.path.dirname(filesystem_path)
|
||||||
cls._makedirs_synced(parent_dir, exist_ok=True)
|
cls._makedirs_synced(parent_dir)
|
||||||
|
|
||||||
# Create a temporary directory with an unsafe name
|
# Create a temporary directory with an unsafe name
|
||||||
with TemporaryDirectory(
|
with TemporaryDirectory(
|
||||||
@ -735,7 +740,7 @@ class Collection(BaseCollection):
|
|||||||
if not cls._lock_file:
|
if not cls._lock_file:
|
||||||
folder = os.path.expanduser(
|
folder = os.path.expanduser(
|
||||||
cls.configuration.get("storage", "filesystem_folder"))
|
cls.configuration.get("storage", "filesystem_folder"))
|
||||||
cls._makedirs_synced(folder, exist_ok=True)
|
cls._makedirs_synced(folder)
|
||||||
lock_path = os.path.join(folder, ".Radicale.lock")
|
lock_path = os.path.join(folder, ".Radicale.lock")
|
||||||
cls._lock_file = open(lock_path, "w+")
|
cls._lock_file = open(lock_path, "w+")
|
||||||
# Set access rights to a necessary minimum to prevent locking
|
# Set access rights to a necessary minimum to prevent locking
|
||||||
|
Loading…
x
Reference in New Issue
Block a user