[Pkg-xen-devel] [PATCH 13/16] d/shuffle-boot-files: Simplify loop structure

Hans van Kranenburg hans at knorrie.org
Sat Jan 16 20:11:52 GMT 2021


On 7/17/20 9:05 PM, Elliott Mitchell wrote:
> Rather than changing into the work directory and then running find,
> instead simply run find and strip off the directory name later.  Since
> the directory name was being re-added to the source filename later, this
> reduces complexity.  Instead the work directory name needs to be stripped
> off the target filename.
> 
> Put another way, remove all processing of source filename and do more
> processing of target filename.
> 
> While at it use structures which conform to POSIX, allowing the use of
> /bin/sh instead of bash.

I highly suspect this was the actual main goal. So, the back ticks and
${//} replacement have to go.

To me old and new version looked equally obscure and complex, so I
started reverse engineering what's actually happening here.

This resulted in 2 changes that I just made based on this one,
"d/shuffle-boot-files: make it POSIX compliant", which simply explains
the change like I just did and "d/shuffle-boot-files: Document more
inner workings" to help any future reader to much quicker figure out
what's going on here.

> Signed-off-by: Elliott Mitchell <ehem+debian at m5p.com>
> ---
>  debian/shuffle-boot-files | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/debian/shuffle-boot-files b/debian/shuffle-boot-files
> index 88bcdd8d68..f4b11eddb6 100755
> --- a/debian/shuffle-boot-files
> +++ b/debian/shuffle-boot-files
> @@ -25,6 +25,8 @@ verstring="$(readlink debian/tmp/boot/xen.?z* ||
>  verstring="${verstring##*xen-}"
>  verstring="${verstring%.?z*}"
>  
> -for f in `cd "$t/boot" && find * -type f -print`; do
> -	cp -v "$t/boot/$f" "$dest/${f/$verstring/$newvers}"
> +find "$t/boot" -type f -print | while read f; do
> +	head="${f%$verstring*}"
> +	tail="${f#*$verstring}"
> +	cp -vl "$f" "$dest${head#$t/boot}$newvers${tail}"
>  done
> 




More information about the Pkg-xen-devel mailing list