[pacman-dev] [PATCH] Allow makepkg to use busybox find

Dave Reisner d at falconindy.com
Thu May 3 06:16:06 EDT 2012


On Thu, May 03, 2012 at 03:29:08AM -0400, jhuntwork at lightcubesolutions.com wrote:
> From: Jeremy Huntwork <jhuntwork at lightcubesolutions.com>
> 
> This is an updated version to the previous patch which had a misplaced -o
> option and a misformatted line.
> 
> Allow makepkg to work correctly when used with find from busybox. The switches
> -empty, -samefile and -lname are not available. It is easy to work around
> -empty with rmdir, and -lname with readlink. However, -samefile functionality
> requires tracking and storing inodes to ensure hard links are re-created
> correctly.
> 
> Signed-off-by: Jeremy Huntwork <jhuntwork at lightcubesolutions.com>
> ---

I'm hard pressed to believe that this is the only place we choke on
busybox's "coreutils". We have other, more complete and more sane
userspaces which we need to support, and this patch does not honor that.
Comments inline.

d

>  scripts/makepkg.sh.in |   53 ++++++++++++++++++++++--------------------------
>  1 files changed, 24 insertions(+), 29 deletions(-)
> 
> diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
> index d36dbd6..acf9c99 100644
> --- a/scripts/makepkg.sh.in
> +++ b/scripts/makepkg.sh.in
> @@ -1057,37 +1057,32 @@ tidy_install() {
>  
>  	if check_option "zipman" "y" && [[ -n ${MAN_DIRS[*]} ]]; then
>  		msg2 "$(gettext "Compressing man and info pages...")"
> -		local manpage ext file link hardlinks hl
> -		find ${MAN_DIRS[@]} -type f 2>/dev/null |
> -		while read manpage ; do
> -			ext="${manpage##*.}"
> -			file="${manpage##*/}"
> -			if [[ $ext != gz && $ext != bz2 ]]; then
> -				# update symlinks to this manpage
> -				find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null |
> -				while read link ; do
> +		local manpages inode files link
> +		#   the '|| true' part keeps the script from bailing on the EOF returned
> +		#   by read at the end of the find output
> +		IFS=$'\n' read -rd '' -a files < \
> +			<(find ${MAN_DIRS[@]} \! -name "*.bz2" \! -name "*.gz" \
> +				-type f 2>/dev/null || true) || true

This ||true crap isn't wanted since dca10b062. I realize you're just
copying it, but it needs to go away if you're touching this line.

> +		for file in ${files[@]} ; do

Quoting.

> +			# Track inodes so hard links can be identified and removed
> +			inode=`stat -c %i ${file}`

Style -- we use $() over `` everywhere else in the codebase. You're
breaking compat here, as not every stat implementation supports the -c
flag for format.

Additionally, it'd probably be better to do this all in one step, rather
than stat every single file individually (the forks will add up fast).

  while read -rd ' ' inode; do
    read file
    files[inode]=$file
  done < <(find ... -exec @STATINODE@ {} +)

Where find actually has all the right predicates and @STATINODE@ is
something portable (BSDs, OSX, Cygwin) to grab the inode and the
filename.

> +			if [ -z ${manpages[$inode]} ] ; then

Style -- We don't use POSIX tests anywhere else in makepkg.

> +				manpages[$inode]="$file"
> +				gzip -9 "$file"
> +			else
> +				rm -f "$file"
> +				ln "${manpages[$inode]}.gz" "${file}.gz"
> +				chmod 644 "${file}.gz"
> +			fi
> +			# update any symlinks to this manpage
> +			file="${file##*/}"
> +			find ${MAN_DIRS[@]} -type l 2>/dev/null |
> +			while read link ; do
> +				if [ "${file}" = "`readlink ${link}`" ] ; then

Style fail again... And please use -ef rather than explicitly resolving the
symlink (which could be a symlink to another symlink).

>  					rm -f "$link" "${link}.gz"
>  					ln -s -- "${file}.gz" "${link}.gz"
> -				done
> -
> -				# check file still exists (potentially already compressed due to hardlink)
> -				if [[ -f ${manpage} ]]; then
> -					# find hard links and remove them
> -					#   the '|| true' part keeps the script from bailing on the EOF returned
> -					#   by read at the end of the find output
> -					IFS=$'\n' read -rd '' -a hardlinks < \
> -						<(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" \
> -								2>/dev/null || true) || true
> -					rm -f "${hardlinks[@]}"
> -					# compress the original
> -					gzip -9 "$manpage"
> -					# recreate hard links removed earlier
> -					for hl in "${hardlinks[@]}"; do
> -						ln "${manpage}.gz" "${hl}.gz"
> -						chmod 644 ${hl}.gz
> -					done
>  				fi
> -			fi
> +			done
>  		done
>  	fi
>  
> @@ -1116,7 +1111,7 @@ tidy_install() {
>  
>  	if check_option "emptydirs" "n"; then
>  		msg2 "$(gettext "Removing empty directories...")"
> -		find . -depth -type d -empty -delete
> +		find . -depth -mindepth 1 -type d -exec rmdir --ignore-fail-on-non-empty '{}' +

There's no way --ignore-fail-on-non-empty is anything but a ridiculous
GNU option that busybox picked up.

>  	fi
>  
>  	if check_option "upx" "y"; then
> -- 
> 1.7.2.2
> 
> 


More information about the pacman-dev mailing list