1
0

another shutil update

This commit is contained in:
2025-01-08 11:34:22 +01:00
parent cda43c118b
commit fd43dc5d87
+20 -18
View File
@@ -203,26 +203,28 @@ def process_single_file(
else:
# File successfully converted to av1, move to destination
target_path.parent.mkdir(parents=True, exist_ok=True)
try:
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
success = False
try:
# Use cp to copy file since it handles permissions better
subprocess.run(["cp", str(temp_path), str(target_path)], check=True)
temp_path.unlink()
success = True
except subprocess.CalledProcessError as e:
logging.error(f"Failed to copy file: {e}")
if temp_path.exists():
temp_path.unlink()
if success:
logging.info(f"Successfully compressed {filepath}")
if remove_source:
logging.info(f"Removing source file {filepath}")
filepath.unlink()
release_file_lock(filepath)
return True
logging.info(f"Successfully compressed {filepath}")
if remove_source:
logging.info(f"Removing source file {filepath}")
filepath.unlink()
release_file_lock(filepath)
return True
return False
def process_directory(
*,