Skip to content

Commit

Permalink
Simplify overwrite mode revert code
Browse files Browse the repository at this point in the history
This was done because the new code is cleaner and still produces the
desired result, at least from my testing.
  • Loading branch information
ARAKHN1D committed May 16, 2024
1 parent e3149d3 commit 3e0944d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import threading
import subprocess
import logging
import io
import shutil
from gi.repository import GLib, Gio
from pathlib import Path
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 3e0944d

Please sign in to comment.