Onboarding a drive keeps a library on the internal disk (#828)

The onboarding wizard deleted /media/wrolpi/config before mounting a
drive, and the shadowed data check ignored config/.  A library kept on
the internal disk keeps wrolpi.db and its configs there, so onboarding
a drive later deleted them without warning.  Only a config/ holding
nothing but the ssl/ CA is now treated as transient.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-10-13 16:19:41 -06:00 • committed by GitHub
parent 1554dfb268
commit b83a9cf017
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 89 additions and 25 deletions

View file

@ -271,15 +271,25 @@ def is_mount_busy(mount_point: str) -> bool:
return False
def is_transient_config(config_dir: Path) -> bool:
"""True when `config_dir` holds only the `ssl/` CA that `generate_certificates.sh` writes before the primary
drive is mounted. Anything else (wrolpi.db, configs) belongs to a library kept on that disk."""
try:
return all(e.name == "ssl" for e in config_dir.iterdir())
except FileNotFoundError:
return True
except OSError:
return False
def check_shadowed_data(target: str) -> Optional[dict]:
"""Look for user data at `target` that would be hidden by a mount over it.
Returns a dict with `size_bytes` and `entries` when non-config content is
present, or None when the target is empty (or contains only `config/`).
Returns a dict with `size_bytes` and `entries` when user data is present,
or None when the target is empty (or contains only a transient `config/`).
`config/` is whitelisted because it is created transiently by
`generate_certificates.sh` before the primary drive is mounted; that is
expected, not user data.
A `config/` holding only `ssl/` is ignored because `generate_certificates.sh`
creates it before the primary drive is mounted; see `is_transient_config`.
Returns None for non-existent targets.
"""
@ -288,7 +298,8 @@ def check_shadowed_data(target: str) -> Optional[dict]:
return None
try:
entries = [e.name for e in target_path.iterdir() if e.name != "config"]
entries = [e.name for e in target_path.iterdir()
if not (e.name == "config" and is_transient_config(e))]
except OSError:
return None
if not entries:

View file

@ -21,7 +21,13 @@ from controller.lib.config import (
save_config,
update_config,
)
from controller.lib.disks import check_shadowed_data, get_block_devices, mount_drive, unmount_drive
from controller.lib.disks import (
check_shadowed_data,
get_block_devices,
is_transient_config,
mount_drive,
unmount_drive,
)
from controller.lib.fstab import add_fstab_entry
from controller.lib.scripts import start_script
@ -226,9 +232,12 @@ def commit_onboarding(
# Step 1b: Clean up any transient config directory created on the root
# filesystem (e.g. by generate_certificates.sh running before the drive
# was mounted). This prevents stale root CAs from lingering.
# was mounted). This prevents stale root CAs from lingering. A config
# directory with anything else in it is a library kept on the internal
# disk; the shadowed data check below protects it.
transient_config = Path(media_dir) / "config"
if transient_config.exists() and not Path(media_dir).is_mount():
if transient_config.exists() and not Path(media_dir).is_mount() \
and is_transient_config(transient_config):
import shutil
shutil.rmtree(transient_config)
logger.info("Removed transient config directory at %s", transient_config)