[openwrt/openwrt] base-files: sysupgrade: fix streaming backup archives to stdout

LEDE Commits lede-commits at lists.infradead.org
Mon Mar 4 05:58:57 PST 2024


jow pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/6f6406a1321b4ead1d61abdea450d7c76bd5a927

commit 6f6406a1321b4ead1d61abdea450d7c76bd5a927
Author: Jo-Philipp Wich <jo at mein.io>
AuthorDate: Mon Mar 4 14:50:46 2024 +0100

    base-files: sysupgrade: fix streaming backup archives to stdout
    
    Due to previous refactoring in sysupgrade, writing backup archives to
    stdout became impossible since the hardcoded gzip output redirection
    did not account for the `-` special case filename.
    
    Fix this issue by substituting `-` with `/proc/self/fd/1` in the tar
    archive output path variable.
    
    Also remove a redundant `rm -f` of the target file path that occurs
    before the file could've possibly been written.
    
    Fixes: #14773
    Fixes: https://github.com/openwrt/luci/issues/6961
    Fixes: e36cc53092 ("base-files: sysupgrade: use tar helper to include installed_packages.txt")
    Signed-off-by: Jo-Philipp Wich <jo at mein.io>
---
 package/base-files/files/sbin/sysupgrade | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 78ec455067..720f3da3fa 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -241,12 +241,13 @@ create_backup_archive() {
 	[ "$(rootfs_type)" = "tmpfs" ] && {
 		echo "Cannot save config while running from ramdisk." >&2
 		ask_bool 0 "Abort" && exit
-		rm -f "$conf_tar"
 		return 0
 	}
 	run_hooks "$CONFFILES" $sysupgrade_init_conffiles
 	ask_bool 0 "Edit config file list" && vi "$CONFFILES"
 
+	[ "$conf_tar" != "-" ] || conf_tar=""
+
 	v "Saving config files..."
 	[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
 	sed -i -e 's,^/,,' "$CONFFILES"
@@ -272,12 +273,12 @@ create_backup_archive() {
 
 		# Rest of archive with config files and ending padding
 		tar c${TAR_V} -C / -T "$CONFFILES"
-	} | gzip > "$conf_tar"
+	} | gzip > "${conf_tar:-/proc/self/fd/1}"
 
 	local err=$?
 	if [ "$err" -ne 0 ]; then
 		echo "Failed to create the configuration backup."
-		rm -f "$conf_tar"
+		[ -f "$conf_tar" ] && rm -f "$conf_tar"
 	fi
 
 	rm -f "$CONFFILES"




More information about the lede-commits mailing list