[pacman-dev] libmakepkg/strip: don't re-add the same debug source multiple times

Message ID 20200511041630.1739558-1-eschwartz@archlinux.org
State Accepted, archived
Headers show
Series [pacman-dev] libmakepkg/strip: don't re-add the same debug source multiple times | expand

Commit Message

Eli Schwartz May 11, 2020, 4:16 a.m. UTC
It's either a waste of work, or triggers edge cases in some packages
(like coreutils-8.31) where the source file is readonly and cp gets a
permission denied error trying to overwrite it with an identical copy of
itself.

Also while we are at it, make the variable names be something readable,
because I could barely tell what this was doing while editing it.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
---
 scripts/libmakepkg/tidy/strip.sh.in | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Allan McRae May 12, 2020, 1:09 a.m. UTC | #1
On 11/5/20 2:16 pm, Eli Schwartz wrote:
> It's either a waste of work, or triggers edge cases in some packages
> (like coreutils-8.31) where the source file is readonly and cp gets a
> permission denied error trying to overwrite it with an identical copy of
> itself.
> 
> Also while we are at it, make the variable names be something readable,
> because I could barely tell what this was doing while editing it.
> 

OK.

> Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
> ---
>  scripts/libmakepkg/tidy/strip.sh.in | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in
> index 2b6f732d..868b96f3 100644
> --- a/scripts/libmakepkg/tidy/strip.sh.in
> +++ b/scripts/libmakepkg/tidy/strip.sh.in
> @@ -56,11 +56,14 @@ strip_file() {
>  		fi
>  
>  		# copy source files to debug directory
> -		local f t
> +		local file dest t
>  		while IFS= read -r t; do
> -			f=${t/${dbgsrcdir}/"$srcdir"}
> -			mkdir -p "${dbgsrc/"$dbgsrcdir"/}${t%/*}"
> -			cp -- "$f" "${dbgsrc/"$dbgsrcdir"/}$t"
> +			file=${t/${dbgsrcdir}/"$srcdir"}
> +			dest="${dbgsrc/"$dbgsrcdir"/}$t"
> +			if ! [[ -f $dest ]]; then
> +				mkdir -p "${dest%/*}"
> +				cp -- "$file" "$dest"
> +			fi
>  		done < <(source_files "$binary")
>  
>  		# copy debug symbols to debug directory
>

Patch

diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in
index 2b6f732d..868b96f3 100644
--- a/scripts/libmakepkg/tidy/strip.sh.in
+++ b/scripts/libmakepkg/tidy/strip.sh.in
@@ -56,11 +56,14 @@  strip_file() {
 		fi
 
 		# copy source files to debug directory
-		local f t
+		local file dest t
 		while IFS= read -r t; do
-			f=${t/${dbgsrcdir}/"$srcdir"}
-			mkdir -p "${dbgsrc/"$dbgsrcdir"/}${t%/*}"
-			cp -- "$f" "${dbgsrc/"$dbgsrcdir"/}$t"
+			file=${t/${dbgsrcdir}/"$srcdir"}
+			dest="${dbgsrc/"$dbgsrcdir"/}$t"
+			if ! [[ -f $dest ]]; then
+				mkdir -p "${dest%/*}"
+				cp -- "$file" "$dest"
+			fi
 		done < <(source_files "$binary")
 
 		# copy debug symbols to debug directory