Skip to content

Commit

Permalink
base-files: sysupgrade: always cleanup after backups
Browse files Browse the repository at this point in the history
When tar was failing, it was exiting immediately. Some files and the
tmpfs mount (-k) would remain breaking the next backup attempt.

Also remove redundant $? from exit builtin call as exit already returns
the last command exit code when called.

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
  • Loading branch information
luizluca authored and Rafał Miłecki committed Feb 19, 2024
1 parent 14ac91c commit 700907b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions package/base-files/files/sbin/sysupgrade
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,19 @@ do_save_conffiles() {
[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
sed -i -e 's,^/,,' "$CONFFILES"
tar c${TAR_V}zf "$conf_tar" -C / -T "$CONFFILES"
if [ "$?" -ne 0 ]; then
local err=$?
if [ "$err" -ne 0 ]; then
echo "Failed to create the configuration backup."
rm -f "$conf_tar"
exit 1
fi

[ "$UMOUNT_ETCBACKUP_DIR" -eq 1 ] && {
umount "$ETCBACKUP_DIR"
rm -rf "$RAMFS"
}
rm -f "$CONFFILES"

return "$err"
}

if [ $CONF_BACKUP_LIST -eq 1 ]; then
Expand All @@ -282,7 +284,7 @@ fi

if [ -n "$CONF_BACKUP" ]; then
do_save_conffiles "$CONF_BACKUP"
exit $?
exit
fi

if [ -n "$CONF_RESTORE" ]; then
Expand Down Expand Up @@ -351,7 +353,7 @@ if [ -n "$CONF_IMAGE" ]; then
get_image "$CONF_IMAGE" "cat" > "$CONF_TAR"
export SAVE_CONFIG=1
elif ask_bool $SAVE_CONFIG "Keep config files over reflash"; then
[ $TEST -eq 1 ] || do_save_conffiles "$CONF_TAR"
[ $TEST -eq 1 ] || do_save_conffiles "$CONF_TAR" || exit
export SAVE_CONFIG=1
else
[ $TEST -eq 1 ] || rm -f "$CONF_TAR"
Expand Down

0 comments on commit 700907b

Please sign in to comment.