From 026d8c95529e55ac51e81ef11985aff7fe32fdcd Mon Sep 17 00:00:00 2001 From: Markus Ostermayer Date: Sun, 15 Sep 2024 11:36:41 +0200 Subject: [PATCH 1/2] Made exploit overwriting interactive --- .../player-cli/player_cli/exploit/__init__.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ataka/player-cli/player_cli/exploit/__init__.py b/ataka/player-cli/player_cli/exploit/__init__.py index ef523b2..2d615b2 100644 --- a/ataka/player-cli/player_cli/exploit/__init__.py +++ b/ataka/player-cli/player_cli/exploit/__init__.py @@ -245,15 +245,20 @@ def exploit_download( print(f'{ERROR_STR}: unsafe archive: link detected') raise typer.Exit(code=1) - try: - os.mkdir(path) - except FileExistsError: - if overwrite: - print(f'{WARN_STR}: directory "{path}" already exists (proceeding anyway)') - else: - print(f'{ERROR_STR}: directory "{path}" already exists (use --overwrite to proceed anyway)') + # Check if the directory already exists and ask the user if + # overwriting is fine if overwrite is not explicitly specified + if os.path.exists(path) and not overwrite: + confirm_str = ( + f'{ERROR_STR}: directory "{path}" already exists, ' + 'do you want to overwrite it?' + ) + overwrite_answer = Confirm.ask(confirm_str) + if not overwrite_answer: raise typer.Exit(code=1) + # Recursivly create directories, not raising FileExistsError on + # existing directories(overwrite-case) + os.makedirs(path, exist_ok=True) tar.extractall(path) From a915513cb9b0c29d1dc9827758a7c0905963c106 Mon Sep 17 00:00:00 2001 From: Markus Ostermayer Date: Sun, 15 Sep 2024 11:38:07 +0200 Subject: [PATCH 2/2] Reworked multiline string --- ataka/player-cli/player_cli/exploit/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ataka/player-cli/player_cli/exploit/__init__.py b/ataka/player-cli/player_cli/exploit/__init__.py index 2d615b2..c16d53f 100644 --- a/ataka/player-cli/player_cli/exploit/__init__.py +++ b/ataka/player-cli/player_cli/exploit/__init__.py @@ -248,10 +248,8 @@ def exploit_download( # Check if the directory already exists and ask the user if # overwriting is fine if overwrite is not explicitly specified if os.path.exists(path) and not overwrite: - confirm_str = ( - f'{ERROR_STR}: directory "{path}" already exists, ' - 'do you want to overwrite it?' - ) + confirm_str = f'{ERROR_STR}: directory "{path}" already exists, do you want to overwrite it?' + overwrite_answer = Confirm.ask(confirm_str) if not overwrite_answer: raise typer.Exit(code=1)