From 9804411d74c52ae8246098dd922e6100479ccae7 Mon Sep 17 00:00:00 2001 From: dw-0 Date: Thu, 2 May 2024 21:52:29 +0200 Subject: [PATCH] feat: add remove_with_sudo function Signed-off-by: Dominik Willner --- kiauh/utils/fs_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kiauh/utils/fs_utils.py b/kiauh/utils/fs_utils.py index 4ac3df9..57efbaf 100644 --- a/kiauh/utils/fs_utils.py +++ b/kiauh/utils/fs_utils.py @@ -60,6 +60,15 @@ def create_symlink(source: Path, target: Path, sudo=False) -> None: raise +def remove_with_sudo(file_path: Path) -> None: + try: + cmd = ["sudo", "rm", "-f", file_path] + run(cmd, stderr=PIPE, check=True) + except CalledProcessError as e: + Logger.print_error(f"Failed to remove file: {e}") + raise + + @deprecated(info="Use remove_with_sudo instead", replaced_by=remove_with_sudo) def remove_file(file_path: Path, sudo=False) -> None: try: