Guard probe_target against creating phantom local dirs when mount_root is unmounted

This commit is contained in:
n0mad1k
2026-07-10 14:36:20 -04:00
parent 759d4a6e23
commit 2853d2e125
2 changed files with 60 additions and 0 deletions
+15
View File
@@ -81,6 +81,8 @@ PENDING_DIR: Path = Path(
str(Path.home() / ".local" / "share" / "coe-mirror" / "pending"),
)
).expanduser()
_MOUNT_ROOT_VAL = _resolve("COE_MIRROR_MOUNT_ROOT", _CFG.get("mount_root"), "")
MOUNT_ROOT: Optional[Path] = Path(_MOUNT_ROOT_VAL).expanduser() if _MOUNT_ROOT_VAL else None
LOG_DIR = Path.home() / ".local" / "share" / "coe-mirror"
LOG_FILE = LOG_DIR / "coe-mirror.log"
LOCK_NAME = "coe-mirror.lock"
@@ -168,6 +170,14 @@ def release_lock(lock_fd: int) -> None:
def probe_target() -> bool:
"""Probe target directory health. Write tiny file, read back, delete. Return True if healthy."""
try:
if MOUNT_ROOT is not None:
if not MOUNT_ROOT.exists() or not os.path.ismount(str(MOUNT_ROOT)):
logger.warning("mount_root %s is not a live mountpoint; target unavailable; queuing locally", MOUNT_ROOT)
return False
if not (TARGET_DIR == MOUNT_ROOT or TARGET_DIR.is_relative_to(MOUNT_ROOT)):
logger.warning("target_dir %s is not under configured mount_root %s; misconfig; queuing locally", TARGET_DIR, MOUNT_ROOT)
return False
probe_file = TARGET_DIR / ".write_probe"
TARGET_DIR.mkdir(parents=True, exist_ok=True)
@@ -673,6 +683,11 @@ api_base = "https://git.churchofmalware.org"
# Where mirrored zips are stored. One subdirectory per owner is created here.
target_dir = "~/coe-mirror"
# Optional: require this path to be a live mountpoint before writing. If set and
# not currently mounted, the run queues to pending instead of creating a phantom
# local directory at the mountpoint. Leave blank to disable.
# mount_root = "~/pCloudDrive"
# Optional: local staging when target_dir is unavailable.
# pending_dir = "~/.local/share/coe-mirror/pending"