Fix dashcam mount-point creation permission error
mount_device() used a bare os.makedirs() to create the mount point, but the app runs as an unprivileged user while /mnt is root-owned - surfaced as a real PermissionError during the first actual hardware test. Create the mount point via sudo mkdir -p instead, consistent with the existing sudo mount/umount calls in this module. Co-authored-by: Copilot <[email protected]>
This commit is contained in:
+18
-2
@@ -108,8 +108,24 @@ def find_dashcam_partition():
|
|||||||
|
|
||||||
|
|
||||||
def mount_device(device_path, mount_point=DEFAULT_MOUNT_POINT):
|
def mount_device(device_path, mount_point=DEFAULT_MOUNT_POINT):
|
||||||
"""Mount device_path read-only at mount_point. Returns True on success."""
|
"""Mount device_path read-only at mount_point. Returns True on success.
|
||||||
os.makedirs(mount_point, exist_ok=True)
|
|
||||||
|
The app runs as an unprivileged user while /mnt is root-owned, so the
|
||||||
|
mount point directory itself has to be created via sudo too (not just
|
||||||
|
the mount call) - first real-hardware test surfaced this as a plain
|
||||||
|
PermissionError from a bare os.makedirs().
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
subprocess.run(
|
||||||
|
["sudo", "mkdir", "-p", mount_point],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Failed to create mount point {mount_point}: {e.stderr.strip()}")
|
||||||
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["sudo", "mount", "-o", "ro", device_path, mount_point],
|
["sudo", "mount", "-o", "ro", device_path, mount_point],
|
||||||
|
|||||||
Reference in New Issue
Block a user