Skip to content

Commit 20ba0a5

Browse files
committed
add some checks to prevent rm -fr deleting too much
1 parent b707d1d commit 20ba0a5

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

.bazelci/isolate.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
MODULE_DIR="${1:-}"
4+
module_dir="${1:-}"
55

6-
if [[ -z "${MODULE_DIR}" ]]; then
6+
if [[ -z "${module_dir}" ]]; then
77
echo "Usage: $0 <module_directory>"
88
exit 1
99
fi
1010

1111
# Find the repository root assuming this script is in .bazelci/
12-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13-
REPO_ROOT="$(dirname "$SCRIPT_DIR")"
12+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13+
repo_root="$(dirname "${script_dir}")"
1414

15-
cd "${REPO_ROOT}"
15+
cd "${repo_root}"
1616

17-
echo "Removing files outside of ${MODULE_DIR} to simulate BCR environment..."
17+
if [[ ! -f "MODULE.bazel" ]]; then
18+
echo "Error: MODULE.bazel not found in ${repo_root}. Are you sure this is the repo root?"
19+
exit 1
20+
fi
21+
22+
if [[ ! -d "${module_dir}" ]]; then
23+
echo "Error: Module directory '${module_dir}' not found in ${repo_root}."
24+
exit 1
25+
fi
26+
27+
echo "Removing files outside of ${module_dir} to simulate BCR environment..."
1828
find . -maxdepth 1 -mindepth 1 \
19-
! -name "${MODULE_DIR}" \
29+
! -name "${module_dir}" \
2030
! -name ".git" \
2131
! -name ".bazelci" \
2232
-exec rm -rf '{}' +

0 commit comments

Comments
 (0)