Skip to content

Commit e10e5f7

Browse files
committed
- Improve cleanup in rush snatch
1 parent 6783079 commit e10e5f7

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

rush

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,13 +1722,19 @@ rush_snatch_command() {
17221722
[[ -n "${args['--verbose']}" ]] && export VERBOSE=1
17231723

17241724
cleanup() {
1725-
rush remove snatched --purge
1726-
rm -r "$tmpdir"
1725+
local exitcode="$1"
1726+
1727+
if config_has_key "snatched"; then
1728+
rush remove snatched --purge || true
1729+
fi
1730+
1731+
rm -rf "$tmpdir"
1732+
return "$exitcode"
17271733
}
17281734

17291735
say "snatch" "$repo_id $package"
17301736

1731-
trap cleanup EXIT ERR INT TERM
1737+
trap 'exitcode=$?; cleanup "$exitcode"' EXIT
17321738

17331739
rush clone "$repo_id" "$path" --name snatched
17341740
if [[ $undo ]]; then

src/commands/snatch.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ path="$tmpdir/snatched"
99
[[ -n "${args['--verbose']}" ]] && export VERBOSE=1
1010

1111
cleanup() {
12-
rush remove snatched --purge
13-
rm -r "$tmpdir"
12+
local exitcode="$1"
13+
14+
if config_has_key "snatched"; then
15+
rush remove snatched --purge || true
16+
fi
17+
18+
rm -rf "$tmpdir"
19+
return "$exitcode"
1420
}
1521

1622
say "snatch" "$repo_id $package"
1723

18-
trap cleanup EXIT ERR INT TERM
24+
trap 'exitcode=$?; cleanup "$exitcode"' EXIT
1925

2026
rush clone "$repo_id" "$path" --name snatched
2127
if [[ $undo ]]; then

test/approve

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe "default"
5656
approve "rush default -h"
5757
approve "rush default sample"
5858
approve "rush default default" || return 0
59+
expect_exit_code 1
5960

6061
describe "get"
6162
approve "rush add sample ~/rush-repos/sample-repo"

0 commit comments

Comments
 (0)