Skip to content

Commit e4af81d

Browse files
committed
fix: Lock directory properly deleted when using run subcommand (exec)
1 parent 74884ec commit e4af81d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

pkg/lib/commands/do-run.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,27 @@ do-run() {
2121
bprint.die "The only argument must be the executable name"
2222
fi
2323

24+
# Look in current package
2425
local bin_name="${args[0]}"
26+
if util.get_toml_array "$BASALT_LOCAL_PROJECT_DIR/basalt.toml" 'binDirs'; then
27+
for bin_dir in "${REPLIES[@]}"; do
28+
for bin_file in "$bin_dir"/*; do
29+
if [ -f "$bin_file" ] && [ -x "$bin_file" ]; then
30+
util.deinit
31+
exec "$bin_file"
32+
elif [ -f "$bin_file" ]; then
33+
bprint.die "File '$bin_name' is found, but the package providing it has not made it executable"
34+
else
35+
bprint.die "No executable called '$bin_name' was found"
36+
fi
37+
done; unset bin_file
38+
done; unset bin_dir
39+
fi
40+
41+
# Look in subdependencies
2542
local bin_file="$BASALT_LOCAL_PROJECT_DIR/.basalt/bin/$bin_name"
26-
if [ -x "$bin_file" ]; then
43+
if [ -f "$bin_file" ] && [ -x "$bin_file" ]; then
44+
util.deinit
2745
exec "$bin_file"
2846
elif [ -f "$bin_file" ]; then
2947
bprint.die "File '$bin_name' is found, but the package providing it has not made it executable"

pkg/lib/util/util.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ util.init_always() {
6969
else
7070
___basalt_lock_dir="$BASALT_GLOBAL_DATA_DIR/basalt.lock"
7171
fi
72-
if mkdir "$___basalt_lock_dir"; then
73-
trap 'rm -rf "$___basalt_lock_dir"' INT TERM EXIT
72+
if mkdir "$___basalt_lock_dir" 2>/dev/null; then
73+
trap 'util.deinit' INT TERM EXIT
7474
else
7575
bprint.die "Cannot run Basalt at this time because another Basalt process is already running (lock directory '$___basalt_lock_dir' exists)"
7676
fi
@@ -81,6 +81,10 @@ util.init_always() {
8181
fi
8282
}
8383

84+
util.deinit() {
85+
rm -rf "$___basalt_lock_dir"
86+
}
87+
8488
# @description Ensure the downloaded file is really a .tar.gz file...
8589
util.file_is_targz() {
8690
local file="$1"

0 commit comments

Comments
 (0)