mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 10:34:28 +05:00
refactor: make run_remove_routines return boolean
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -73,11 +73,11 @@ def remove_file(file_path: Path, sudo=False) -> None:
|
||||
raise
|
||||
|
||||
|
||||
def run_remove_routines(file: Path) -> None:
|
||||
def run_remove_routines(file: Path) -> bool:
|
||||
try:
|
||||
if not file.is_symlink() and not file.exists():
|
||||
Logger.print_info(f"File '{file}' does not exist. Skipped ...")
|
||||
return
|
||||
return False
|
||||
|
||||
if file.is_dir():
|
||||
shutil.rmtree(file)
|
||||
@@ -86,15 +86,18 @@ def run_remove_routines(file: Path) -> None:
|
||||
else:
|
||||
raise OSError(f"File '{file}' is neither a file nor a directory!")
|
||||
Logger.print_ok(f"File '{file}' was successfully removed!")
|
||||
return True
|
||||
except OSError as e:
|
||||
Logger.print_error(f"Unable to delete '{file}':\n{e}")
|
||||
try:
|
||||
Logger.print_info("Trying to remove with sudo ...")
|
||||
remove_with_sudo(file)
|
||||
Logger.print_ok(f"File '{file}' was successfully removed!")
|
||||
return True
|
||||
except CalledProcessError as e:
|
||||
Logger.print_error(f"Error deleting '{file}' with sudo:\n{e}")
|
||||
Logger.print_error("Remove this directory manually!")
|
||||
return False
|
||||
|
||||
|
||||
def unzip(filepath: Path, target_dir: Path) -> None:
|
||||
|
||||
Reference in New Issue
Block a user