mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Warning users when files exist in mount location. Users may have accidentally downloaded files into the media directory, we want to warn them.
This commit is contained in:
parent
da340a00b3
commit
cd8792f697
12 changed files with 482 additions and 34 deletions
|
|
@ -14,6 +14,7 @@ from controller.lib.config import (
|
|||
update_config,
|
||||
)
|
||||
from controller.lib.disks import (
|
||||
check_shadowed_data,
|
||||
get_block_devices,
|
||||
get_mounts,
|
||||
mount_drive,
|
||||
|
|
@ -39,6 +40,10 @@ class MountRequest(BaseModel):
|
|||
fstype: Optional[str] = Field(default=None, description="Filesystem type (auto-detected if not specified)")
|
||||
options: str = Field(default="defaults", description="Mount options")
|
||||
persist: bool = Field(default=False, description="Add to fstab for persistent mounting")
|
||||
force_shadowed: bool = Field(
|
||||
default=False,
|
||||
description="Proceed even if existing data at the mount target would be hidden by the new mount",
|
||||
)
|
||||
|
||||
|
||||
class UnmountRequest(BaseModel):
|
||||
|
|
@ -98,6 +103,24 @@ async def disk_mount(request: MountRequest):
|
|||
"""Mount a partition."""
|
||||
_check_native_mode()
|
||||
|
||||
# Soft-block if the mount target already contains user data that would
|
||||
# be hidden by the new mount. The UI re-submits with force_shadowed=True
|
||||
# to override.
|
||||
if not request.force_shadowed:
|
||||
shadowed = check_shadowed_data(request.mount_point)
|
||||
if shadowed:
|
||||
return {
|
||||
"success": False,
|
||||
"needs_force": "shadowed",
|
||||
"shadowed_data": shadowed,
|
||||
"error": (
|
||||
f"{request.mount_point} contains {len(shadowed['entries'])} "
|
||||
f"existing data "
|
||||
f"{'entry' if len(shadowed['entries']) == 1 else 'entries'}. "
|
||||
f"Mounting now would hide them on the underlying filesystem."
|
||||
),
|
||||
}
|
||||
|
||||
result = mount_drive(
|
||||
device=request.device,
|
||||
mount_point=request.mount_point,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from controller.api.schemas import (
|
|||
OnboardingCommitResponse,
|
||||
OnboardingProbeRequest,
|
||||
OnboardingProbeResponse,
|
||||
ShadowedDataInfo,
|
||||
)
|
||||
from controller.lib.config import is_docker_mode, is_primary_drive_mounted
|
||||
from controller.lib.onboarding import (
|
||||
|
|
@ -78,9 +79,23 @@ async def commit(request: OnboardingCommitRequest):
|
|||
result = commit_onboarding(
|
||||
device_path=request.device_path,
|
||||
fstype=request.fstype,
|
||||
force=request.force,
|
||||
force_shadowed=request.force_shadowed,
|
||||
)
|
||||
|
||||
# Soft-block: existing data at the mount target would be hidden. Return
|
||||
# a structured response (200 OK with success=False) so the UI can prompt
|
||||
# the user to override.
|
||||
if not result.get("success") and result.get("needs_force") == "shadowed":
|
||||
shadowed = result.get("shadowed_data") or {}
|
||||
return OnboardingCommitResponse(
|
||||
success=False,
|
||||
error=result.get("error"),
|
||||
mounts=[],
|
||||
repair_started=False,
|
||||
needs_force="shadowed",
|
||||
shadowed_data=ShadowedDataInfo(**shadowed) if shadowed else None,
|
||||
)
|
||||
|
||||
if not result.get("success"):
|
||||
raise HTTPException(status_code=500, detail=result.get("error", "Onboarding failed"))
|
||||
|
||||
|
|
|
|||
|
|
@ -467,7 +467,17 @@ class OnboardingCommitRequest(BaseModel):
|
|||
|
||||
device_path: str = Field(description="Device path to use as primary drive")
|
||||
fstype: str = Field(description="Filesystem type")
|
||||
force: bool = Field(default=False, description="Proceed even if no config found on drive")
|
||||
force_shadowed: bool = Field(
|
||||
default=False,
|
||||
description="Proceed even if existing data at the mount target would be hidden by the new mount",
|
||||
)
|
||||
|
||||
|
||||
class ShadowedDataInfo(BaseModel):
|
||||
"""Information about data that would be hidden by a mount."""
|
||||
|
||||
size_bytes: int = Field(description="Total size of data that would be shadowed")
|
||||
entries: list[str] = Field(description="Top-level entries that would be hidden")
|
||||
|
||||
|
||||
class OnboardingCommitResponse(BaseModel):
|
||||
|
|
@ -477,3 +487,12 @@ class OnboardingCommitResponse(BaseModel):
|
|||
error: Optional[str] = Field(default=None, description="Error message if failed")
|
||||
mounts: list[str] = Field(default_factory=list, description="Mount points that were mounted")
|
||||
repair_started: bool = Field(default=False, description="Whether repair script was started")
|
||||
needs_force: Optional[str] = Field(
|
||||
default=None,
|
||||
description="If set, the request was soft-blocked. Re-submit with the matching force flag. "
|
||||
"Currently: 'shadowed'.",
|
||||
)
|
||||
shadowed_data: Optional[ShadowedDataInfo] = Field(
|
||||
default=None,
|
||||
description="Populated when needs_force='shadowed'.",
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue