1
0

shutil error handling

This commit is contained in:
2025-01-08 11:26:08 +01:00
parent 97ec4a6f66
commit cda43c118b
+13 -1
View File
@@ -202,9 +202,21 @@ def process_single_file(
return False return False
else: else:
# File successfully converted to av1, move to destination # File successfully converted to av1, move to destination
# Use shutil move because of inter-fs issues
target_path.parent.mkdir(parents=True, exist_ok=True) target_path.parent.mkdir(parents=True, exist_ok=True)
try:
shutil.move(str(temp_path), str(target_path)) shutil.move(str(temp_path), str(target_path))
except (PermissionError, OSError):
try:
logging.warning(f"Failed to move file with metadata, falling back to copy")
shutil.copy(str(temp_path), str(target_path))
temp_path.unlink()
except Exception as e:
logging.error(f"Failed to copy file: {e}")
if temp_path.exists():
temp_path.unlink()
release_file_lock(filepath)
return False
logging.info(f"Successfully compressed {filepath}") logging.info(f"Successfully compressed {filepath}")
if remove_source: if remove_source:
logging.info(f"Removing source file {filepath}") logging.info(f"Removing source file {filepath}")