From f382439edbb19e52dd2b358eb3921eae55cf06e2 Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Wed, 19 Oct 2022 16:46:14 -0300 Subject: [PATCH] build: (fixes #779) prevent ./ns3 clean from deleting the ns-3 directory This could happen if either the output directory or the cmake cache path were set to the ns-3 root path. --- ns3 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ns3 b/ns3 index ccf29e5f0..9886336ec 100755 --- a/ns3 +++ b/ns3 @@ -419,8 +419,10 @@ def print_and_buffer(message): def clean_cmake_artifacts(dry_run=False): print_and_buffer("rm -R %s" % os.path.relpath(out_dir, ns3_path)) - if not dry_run: + if out_dir == ns3_path: + raise Exception("The output directory and the ns-3 directory are the same. " + "Deleting it can cause data loss.") shutil.rmtree(out_dir, ignore_errors=True) cmake_cache_files = glob.glob("%s/**/CMakeCache.txt" % ns3_path, recursive=True) @@ -428,6 +430,9 @@ def clean_cmake_artifacts(dry_run=False): dirname = os.path.dirname(cmake_cache_file) print_and_buffer("rm -R %s" % os.path.relpath(dirname, ns3_path)) if not dry_run: + if dirname == ns3_path: + raise Exception("The CMake cache directory and the ns-3 directory are the same. " + "Deleting it can cause data loss.") shutil.rmtree(dirname, ignore_errors=True) if os.path.exists(lock_file):