On Fri, May 09, 2025 at 06:10:04PM +0200, Alexander Bluhm wrote:
> In general it is very hard to write shell scripts that handle spaces
> in file names correctly.  This is not Perl :-)
> I would recommend to avoid them in UNIX environments.  Why not fix
> this in ports/sysutils/firmware/bwfm/pkg/PLIST?  This is the only
> firmware that gets it wrong.

It is true that shell scripts make it hard to handle strings, but I
think fw_update generally does it correctly.  It does assume that
neither the firmware tgz or the device names will have spaces, but apart
from those two items and my not thinking through the format of the
+CONTENTS well,  I'm fairly confident that we use ksh arrays to handle
tokens with whitespace appropriately.

Adjusting how we read the +CONTENTS file allows us to properly handle
files in the packing list with spaces.

I don't really have a preference on renaming the files in the firmware
tgz's.


Index: fw_update.sh
===================================================================
RCS file: /cvs/src/usr.sbin/fw_update/fw_update.sh,v
diff -u -p -r1.64 fw_update.sh
--- fw_update.sh        22 Mar 2025 19:51:29 -0000      1.64
+++ fw_update.sh        9 May 2025 16:33:32 -0000
@@ -431,7 +431,7 @@ remove_files() {
 }
 
 delete_firmware() {
-       local _cwd _pkg="$1" _pkgdir="${DESTDIR}/var/db/pkg"
+       local _cwd _pkg="$1" _pkgdir="${DESTDIR}/var/db/pkg" _remove _l
 
        # TODO: Check hash for files before deleting
        ((VERBOSE > 2)) && echo -n "Uninstall $_pkg ..."
@@ -445,13 +445,13 @@ delete_firmware() {
 
        set -A _remove -- "${_cwd}/+CONTENTS" "${_cwd}"
 
-       while read -r _c _g; do
-               case $_c in
-               @cwd) _cwd="${DESTDIR}$_g"
+       while read -r _l; do
+               case "$_l" in
+               @cwd\ *) _cwd="${DESTDIR}${_l##@cwd*( )}"
                  ;;
                @*) continue
                  ;;
-               *) set -A _remove -- "$_cwd/$_c" "${_remove[@]}"
+               *) set -A _remove -- "$_cwd/$_l" "${_remove[@]}"
                  ;;
                esac
        done < "${_pkgdir}/${_pkg}/+CONTENTS"

Reply via email to