luci-lib-nixio: Fix add_luci_conffiles adding duplicate files (#6568)
authorXiang W <wxjstz@126.com>
Mon, 4 Dec 2023 20:48:19 +0000 (04:48 +0800)
committerGitHub <noreply@github.com>
Mon, 4 Dec 2023 20:48:19 +0000 (21:48 +0100)
* luci-lib-nixio: Fix add_luci_conffiles adding duplicate files

add_luci_conffiles does not check whether the file already exists
when adding the file, which may result in redundant backups in the
sysupgrade backup.

Signed-off-by: Xiang W <wxjstz@126.com>
libs/luci-lib-nixio/root/lib/upgrade/luci-add-conffiles.sh

index 77399b98724ff2dfc93a8f9c17ab3fb086242d6a..d5117f9d89e9ac6c1b6a0d31b6c17948d074ac3e 100644 (file)
@@ -1,15 +1,26 @@
 add_luci_conffiles()
 {
+       add_luci_conffiles_helper()
+       {
+               [ ! -f "$1" ] && return
+               grep -q "$1" "$2" && return
+               echo "$1" >> "$2"
+       }
+
        local filelist="$1"
 
        # save ssl certs
        if [ -d /etc/nixio ]; then
-               find /etc/nixio -type f >> $filelist
+               find /etc/nixio -type f | while read ff; do
+                       add_luci_conffiles_helper "$ff" "$filelist"
+               done
        fi
 
        # save uhttpd certs
-       [ -f "/etc/uhttpd.key" ] && echo /etc/uhttpd.key >> $filelist
-       [ -f "/etc/uhttpd.crt" ] && echo /etc/uhttpd.crt >> $filelist
+       add_luci_conffiles_helper /etc/uhttpd.key "$filelist"
+       add_luci_conffiles_helper /etc/uhttpd.crt "$filelist"
+
+       unset -f add_luci_conffiles_helper
 }
 
 sysupgrade_init_conffiles="$sysupgrade_init_conffiles add_luci_conffiles"