From fd43dc5d873f1eac99afd0d2199ca1c1ecf24e18 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Wed, 8 Jan 2025 11:34:22 +0100 Subject: [PATCH] another shutil update --- bin/vcmp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/bin/vcmp b/bin/vcmp index c40e6ec..4fd822e 100755 --- a/bin/vcmp +++ b/bin/vcmp @@ -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( *,