shutil error handling
This commit is contained in:
@@ -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}")
|
||||||
|
|||||||
Reference in New Issue
Block a user