Skip to content

Commit 918b91f

Browse files
committed
framework: add schedule_deletion, to delete files as late as possible
1 parent 86f473d commit 918b91f

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
# Copyright (c) 2025 tabris <[email protected]>
3+
# This file is a part of the Armbian Build Framework https://github.com/armbian/build/
4+
5+
declare -a schedule_deletion_files_to_delete
6+
7+
function schedule_deletion() {
8+
local file="$1"
9+
local source="${BASH_SOURCE[1]}"
10+
local func="${FUNCNAME[1]}"
11+
local line="${BASH_LINENO[0]}"
12+
13+
schedule_deletion_files_to_delete+=("$file;$source;$func;$line")
14+
}
15+
16+
function pre_umount_final_image__schedule_deletion_delete_now() {
17+
local file source func line message deletion_info
18+
for deletion_info in "${schedule_deletion_files_to_delete[@]}"; do
19+
IFS=';' read -r file source func line <<< "$deletion_info"
20+
message="scheduled from $source $func $line"
21+
22+
set +e # don't bail out, let us bail out ourselves more verbosely
23+
if [[ ! -e "$file" ]]; then
24+
exit_with_error "FILE DELETION FAILED (missing): '${file}'; ${message}"
25+
elif rm -- "$file"; then
26+
display_alert "deleted file '${file}'" "$message" "info"
27+
else
28+
exit_with_error "FILE DELETION FAILED: '${file}'; ${message}"
29+
fi
30+
set -e # restore the previous behaviour
31+
done
32+
}

lib/library-functions.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# This file is/was autogenerated by ./lib/tools/gen-library.sh; don't modify manually
2+
# This file is/was autogenerated by lib/tools/gen-library.sh; don't modify manually
33

44
# no errors tolerated. invoked before each sourced file to make sure.
55
#set -o pipefail # trace ERR through pipes - will be enabled "soon"
@@ -748,6 +748,15 @@ set -o errexit ## set -e : exit the script if any statement returns a non-true
748748
# shellcheck source=lib/functions/general/retry.sh
749749
source "${SRC}"/lib/functions/general/retry.sh
750750

751+
# no errors tolerated. invoked before each sourced file to make sure.
752+
#set -o pipefail # trace ERR through pipes - will be enabled "soon"
753+
#set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled
754+
set -o errtrace # trace ERR through - enabled
755+
set -o errexit ## set -e : exit the script if any statement returns a non-true return value - enabled
756+
### lib/functions/general/schedule_deletion.sh
757+
# shellcheck source=lib/functions/general/schedule_deletion.sh
758+
source "${SRC}"/lib/functions/general/schedule_deletion.sh
759+
751760
# no errors tolerated. invoked before each sourced file to make sure.
752761
#set -o pipefail # trace ERR through pipes - will be enabled "soon"
753762
#set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled
@@ -1176,4 +1185,4 @@ source "${SRC}"/lib/functions/rootfs/trap-rootfs.sh
11761185
#set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled
11771186
set -o errtrace # trace ERR through - enabled
11781187
set -o errexit ## set -e : exit the script if any statement returns a non-true return value - enabled
1179-
# This file is/was autogenerated by ./lib/tools/gen-library.sh; don't modify manually
1188+
# This file is/was autogenerated by lib/tools/gen-library.sh; don't modify manually

0 commit comments

Comments
 (0)