Skip to content

Commit 48120fc

Browse files
authored
Trap exit and create .bak early (#2154)
1 parent ec4534d commit 48120fc

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

ethd

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,9 @@ update() {
16801680
# __env_migrate used to be called w/ arguments and checks for that
16811681
# shellcheck disable=SC2119
16821682
__env_migrate
1683+
if [ "${__migrated}" -eq 1 ] && ! cmp -s "${__env_file}" "${__env_file}".source; then # Create .bak early
1684+
${__as_owner} cp "${__env_file}".source "${__env_file}".bak
1685+
fi
16831686
__pull_and_build
16841687

16851688
__delete_erigon
@@ -1688,8 +1691,7 @@ update() {
16881691

16891692
echo
16901693
if [ "${__migrated}" -eq 1 ] && ! cmp -s "${__env_file}" "${__env_file}".source; then
1691-
${__as_owner} cp "${__env_file}".source "${__env_file}".bak
1692-
${__as_owner} rm "${__env_file}".source
1694+
${__as_owner} rm "${__env_file}".source # .bak was created earlier
16931695
echo "Your ${__env_file} configuration settings have been migrated to a fresh copy. You can \
16941696
find the original contents in ${__env_file}.bak."
16951697
if [ "${__keep_targets}" -eq 0 ]; then
@@ -3814,6 +3816,9 @@ __handle_error() {
38143816
fi
38153817

38163818
local __exit_code=$1
3819+
if [ "$__exit_code" -eq 0 ]; then
3820+
return 0
3821+
fi
38173822
echo
38183823
if [ "$__exit_code" -eq 130 ]; then
38193824
echo "$__me terminated by user"
@@ -4468,6 +4473,7 @@ if [ ! -f ~/.profile ] || ! grep -q "alias ethd" ~/.profile; then
44684473
fi
44694474

44704475
trap '__handle_error $? $LINENO' ERR
4476+
trap '__handle_error $? $LINENO' EXIT
44714477

44724478
if [[ "$#" -eq 0 || "$*" =~ "-h" ]]; then # Lazy match for -h and --help but also --histogram, so careful here
44734479
help "$@"

0 commit comments

Comments
 (0)