Fix FAT dashcam file deletion
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
+19
-1
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user