diff --git a/python/ctsm/site_and_regional/neon_site.py b/python/ctsm/site_and_regional/neon_site.py index 31ae78f5ad..29b5d2c7b5 100755 --- a/python/ctsm/site_and_regional/neon_site.py +++ b/python/ctsm/site_and_regional/neon_site.py @@ -18,6 +18,7 @@ # pylint: disable=wrong-import-position, import-error, unused-import, wrong-import-order from ctsm import add_cime_to_path from ctsm.path_utils import path_to_ctsm_root +from ctsm.utils import abort from CIME import build from CIME.case import Case @@ -75,6 +76,9 @@ def build_base_case( if overwrite and os.path.isdir(case_path): print("Removing the existing case at: {}".format(case_path)) + if os.getcwd() == case_path: + abort("Trying to remove the directory tree that we are in") + shutil.rmtree(case_path) with Case(case_path, read_only=False) as case: @@ -211,6 +215,8 @@ def run_case( if os.path.isdir(case_root): if overwrite: print("---- removing the existing case -------") + if os.getcwd() == case_root: + abort("Trying to remove the directory tree that we are in") shutil.rmtree(case_root) elif rerun: with Case(case_root, read_only=False) as case: