Skip to content

Commit f8bf797

Browse files
committed
set +e will break exit_with_error, so refactor
1 parent e79f7ef commit f8bf797

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lib/functions/general/schedule_deletion.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,30 @@ function schedule_deletion() {
1414
}
1515

1616
function pre_umount_final_image__schedule_deletion_delete_now() {
17-
local file source func line message deletion_info
17+
local file source func line deletion_info
18+
local had_errexit=0
19+
case $- in *e*) had_errexit=1;; esac
1820
for deletion_info in "${schedule_deletion_files_to_delete[@]}"; do
1921
IFS=';' read -r file source func line <<< "$deletion_info"
20-
message="scheduled from $source $func $line"
22+
local reason="scheduled from $source $func line#$line"
23+
local message=""
24+
local failure=0
2125

22-
set +e # don't bail out, let us bail out ourselves more verbosely
26+
[[ $had_errexit ]] && set +e # don't bail out, let us bail out ourselves more verbosely
2327
if [[ ! -e "$file" ]]; then
24-
exit_with_error "FILE DELETION FAILED (missing): '${file}'; ${message}"
28+
message="FILE DELETION FAILED (missing): '${file}'"
29+
((failure++))
2530
elif rm -- "$file"; then
26-
display_alert "deleted file '${file}'" "$message" "info"
31+
message="deleted file '${file}'"
2732
else
28-
exit_with_error "FILE DELETION FAILED: '${file}'; ${message}"
33+
message="FILE DELETION FAILED: '${file}'"
34+
((failure++))
35+
fi
36+
[[ $had_errexit ]] && set -e # restore the previous behaviour
37+
if [[ $failure ]]; then
38+
exit_with_error "$message; $reason"
39+
else
40+
display_alert "$message" "$reason" "info"
2941
fi
30-
set -e # restore the previous behaviour
3142
done
3243
}

0 commit comments

Comments
 (0)