From 3e0944d778ade6d86a4dd7ad0d915b616a105928 Mon Sep 17 00:00:00 2001 From: ARAKHNID Date: Thu, 16 May 2024 16:30:52 -0500 Subject: [PATCH] Simplify overwrite mode revert code This was done because the new code is cleaner and still produces the desired result, at least from my testing. --- src/compressor.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compressor.py b/src/compressor.py index 2ee9884..8f6b0aa 100644 --- a/src/compressor.py +++ b/src/compressor.py @@ -18,6 +18,7 @@ import threading import subprocess import logging +import io import shutil from gi.repository import GLib, Gio from pathlib import Path @@ -80,9 +81,8 @@ def run_command(self, command, result_item): if not self.do_new_file: # Creates a copy of the input file # This is done in case the output file is larger than the input file - result_item_path = Path(result_item.filename) - original_filename = Path(result_item.filename).with_stem(f"{result_item_path.stem}-og") - shutil.copy2(result_item.filename, original_filename) + temp_filename = result_item.filename + ".temp" + shutil.copy2(result_item.filename, temp_filename) error = False error_message = '' @@ -112,9 +112,9 @@ def run_command(self, command, result_item): if self.do_new_file: shutil.copy2(result_item.filename, result_item.new_filename) else: - shutil.copy2(original_filename, result_item.new_filename) + shutil.copy2(temp_filename, result_item.new_filename) result_item.new_size = new_file_data.stat().st_size - original_filename.unlink(True) + Path(temp_filename).unlink(True) else: logging.error(str(output))