Fix FAT dashcam file deletion

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Mathieu Moran
2026-08-09 18:23:52 -04:00
co-authored by Copilot
parent 80d9c150fe
commit e058ea8a41
2 changed files with 29 additions and 3 deletions
+19 -1
View File
@@ -292,6 +292,24 @@ def _safe_video_path(source_folder, relative_path):
return target_real
def _remove_video_file(path):
try:
os.remove(path)
return
except PermissionError:
pass
try:
subprocess.run(
["sudo", "rm", "--", path],
capture_output=True,
text=True,
check=True,
)
except subprocess.CalledProcessError as e:
raise OSError(e.stderr.strip() or f"Failed to delete {path}") from e
def delete_dashcam_files(relative_path=None, delete_all=False, mount_point=DEFAULT_MOUNT_POINT):
"""Delete one or all dashcam videos, restoring read-only state afterward."""
if not delete_all and relative_path is None:
@@ -336,7 +354,7 @@ def delete_dashcam_files(relative_path=None, delete_all=False, mount_point=DEFAU
for _abs_path, rel_path in targets:
try:
safe_path = _safe_video_path(source, rel_path)
os.remove(safe_path)
_remove_video_file(safe_path)
deleted.append(rel_path)
except (OSError, ValueError) as e:
errors.append(f"{rel_path}: {e}")