diff --git a/src/virtualship/cli/_run.py b/src/virtualship/cli/_run.py index 2b5f5c30..2feb43a3 100644 --- a/src/virtualship/cli/_run.py +++ b/src/virtualship/cli/_run.py @@ -3,6 +3,7 @@ import logging import os import shutil +import sys import time from datetime import datetime from pathlib import Path @@ -131,9 +132,12 @@ def _run( return # delete and create results directory - if os.path.exists(expedition_dir.joinpath(RESULTS)): - shutil.rmtree(expedition_dir.joinpath(RESULTS)) - os.makedirs(expedition_dir.joinpath(RESULTS)) + results_dir = expedition_dir.joinpath(RESULTS) + _warn_overwrite_results_dir(results_dir) + + if os.path.exists(results_dir): + shutil.rmtree(results_dir) + os.makedirs(results_dir) print("\n----- EXPEDITION SUMMARY ------") @@ -284,6 +288,21 @@ def _unique_id(expedition: Expedition, cache_dir: Path) -> str: return new_id +def _warn_overwrite_results_dir(results_dir: Path) -> None: + if os.path.exists(results_dir): + print( + f"\nWARNING: The '{results_dir}' directory already exists and will be overwritten. If you want to keep the previous results, please move or rename the '{results_dir}' directory before re-running the expedition.\n" + ) + decision = input( + "Do you want to continue the expedition run and thereby overwrite the existing results? (y/n): " + ) + if decision.lower() != "y": + print("Expedition run cancelled by user.") + sys.exit(0) + if decision.lower() == "y": + print("Continuing with expedition run and overwriting existing results...") + + def _load_checkpoint(expedition_dir: Path) -> Checkpoint | None: file_path = expedition_dir.joinpath(CHECKPOINT) try: