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: else:
# File successfully converted to av1, move to destination # File successfully converted to av1, move to destination
target_path.parent.mkdir(parents=True, exist_ok=True) target_path.parent.mkdir(parents=True, exist_ok=True)
try: success = False
shutil.move(str(temp_path), str(target_path))
except (PermissionError, OSError): try:
try: # Use cp to copy file since it handles permissions better
logging.warning(f"Failed to move file with metadata, falling back to copy") subprocess.run(["cp", str(temp_path), str(target_path)], check=True)
shutil.copy(str(temp_path), str(target_path)) temp_path.unlink()
temp_path.unlink() success = True
except Exception as e: except subprocess.CalledProcessError as e:
logging.error(f"Failed to copy file: {e}") logging.error(f"Failed to copy file: {e}")
if temp_path.exists(): if temp_path.exists():
temp_path.unlink() temp_path.unlink()
release_file_lock(filepath)
return False 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) release_file_lock(filepath)
return True return False
def process_directory( def process_directory(
*, *,