[pacman-dev] [PATCH 1/4] makepkg: fix find_lib{depends, provides} results
Neither function was checking for the existence of actual results before calling printf, resulting in them returning a list with a single empty value if there were no depends/provides. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- scripts/makepkg.sh.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 02398cf..714b376 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -494,7 +494,7 @@ find_libdepends() { done if (( sodepends == 0 )); then - printf '%s\n' "${depends[@]}" + (( ${#depends[@]} )) && printf '%s\n' "${depends[@]}" return; fi @@ -543,7 +543,7 @@ find_libdepends() { esac done - printf '%s\n' "${libdepends[@]}" + (( ${#libdepends[@]} )) && printf '%s\n' "${libdepends[@]}" } @@ -594,7 +594,7 @@ find_libprovides() { fi done - printf '%s\n' "${libprovides[@]}" + (( ${#libprovides[@]} )) && printf '%s\n' "${libprovides[@]}" } write_pkginfo() { -- 2.10.2
The PKGINFO format cannot handle values that contain newlines. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- Many package fields get processed in such a way that getting a newline into a .PKGINFO file is actually not all that easy. One way to do it is with PACKAGER (e.g. `PACKAGER=foo$'\n'bar makepkg`). Ideally there would be a lint_package check for this, but we don't currently have an easy way to loop through all package variables and this is the most reliable way to be sure that we check everything we write. scripts/makepkg.sh.in | 63 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 714b376..8376e4a 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -597,6 +597,19 @@ find_libprovides() { (( ${#libprovides[@]} )) && printf '%s\n' "${libprovides[@]}" } +write_kv_pair() { + local key="$1" + shift + + for val in "$@"; do + if [[ $val = *$'\n'* ]]; then + error "$(gettext "Invalid value for %s: %s")" "$key" "$val" + exit 1 + fi + printf "%s = %s\n" "$key" "$val" + done +} + write_pkginfo() { local builddate=$(date -u "+%s") if [[ -n $PACKAGER ]]; then @@ -615,15 +628,15 @@ write_pkginfo() { printf "# using %s\n" "$(fakeroot -v)" printf "# %s\n" "$(LC_ALL=C date -u)" - printf "pkgname = %s\n" "$pkgname" + write_kv_pair "pkgname" "$pkgname" if (( SPLITPKG )) || [[ "$pkgbase" != "$pkgname" ]]; then - printf "pkgbase = %s\n" "$pkgbase" + write_kv_pair "pkgbase" "$pkgbase" fi local fullver=$(get_full_version) - printf "pkgver = %s\n" "$fullver" + write_kv_pair "pkgver" "$fullver" if [[ "$fullver" != "$basever" ]]; then - printf "basever = %s\n" "$basever" + write_kv_pair "basever" "$basever" fi # TODO: all fields should have this treatment @@ -631,43 +644,43 @@ write_pkginfo() { spd=("${spd[@]#[[:space:]]}") spd=("${spd[@]%[[:space:]]}") - printf "pkgdesc = %s\n" "$spd" - printf "url = %s\n" "$url" - printf "builddate = %s\n" "$builddate" - printf "packager = %s\n" "$packager" - printf "size = %s\n" "$size" - printf "arch = %s\n" "$pkgarch" + write_kv_pair "pkgdesc" "$spd" + write_kv_pair "url" "$url" + write_kv_pair "builddate" "$builddate" + write_kv_pair "packager" "$packager" + write_kv_pair "size" "$size" + write_kv_pair "arch" "$pkgarch" mapfile -t provides < <(find_libprovides) mapfile -t depends < <(find_libdepends) - [[ $license ]] && printf "license = %s\n" "${license[@]}" - [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}" - [[ $groups ]] && printf "group = %s\n" "${groups[@]}" - [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}" - [[ $provides ]] && printf "provides = %s\n" "${provides[@]}" - [[ $backup ]] && printf "backup = %s\n" "${backup[@]}" - [[ $depends ]] && printf "depend = %s\n" "${depends[@]}" - [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]//+([[:space:]])/ }" - [[ $makedepends ]] && printf "makedepend = %s\n" "${makedepends[@]}" - [[ $checkdepends ]] && printf "checkdepend = %s\n" "${checkdepends[@]}" + write_kv_pair "license" "${license[@]}" + write_kv_pair "replaces" "${replaces[@]}" + write_kv_pair "group" "${groups[@]}" + write_kv_pair "conflict" "${conflicts[@]}" + write_kv_pair "provides" "${provides[@]}" + write_kv_pair "backup" "${backup[@]}" + write_kv_pair "depend" "${depends[@]}" + write_kv_pair "optdepend" "${optdepends[@]//+([[:space:]])/ }" + write_kv_pair "makedepend" "${makedepends[@]}" + write_kv_pair "checkdepend" "${checkdepends[@]}" } write_buildinfo() { msg2 "$(gettext "Generating %s file...")" ".BUILDINFO" - printf "builddir = %s\n" "${BUILDDIR}" + write_kv_pair "builddir" "${BUILDDIR}" local sum="$(sha256sum "${BUILDFILE}")" sum=${sum%% *} - printf "pkgbuild_sha256sum = %s\n" $sum + write_kv_pair "pkgbuild_sha256sum" $sum - printf "buildenv = %s\n" "${BUILDENV[@]}" - printf "options = %s\n" "${OPTIONS[@]}" + write_kv_pair "buildenv" "${BUILDENV[@]}" + write_kv_pair "options" "${OPTIONS[@]}" local pkglist=($(run_pacman -Q | sed "s# #-#")) - printf "installed = %s\n" "${pkglist[@]}" + write_kv_pair "installed" "${pkglist[@]}" } create_package() { -- 2.10.2
On 06/11/16 08:08, Andrew Gregory wrote:
The PKGINFO format cannot handle values that contain newlines.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> ---
Many package fields get processed in such a way that getting a newline into a .PKGINFO file is actually not all that easy. One way to do it is with PACKAGER (e.g. `PACKAGER=foo$'\n'bar makepkg`). Ideally there would be a lint_package check for this, but we don't currently have an easy way to loop through all package variables and this is the most reliable way to be sure that we check everything we write.
OK.
Allows lint_package to prevent makepkg from creating an invalid package. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- scripts/libmakepkg/lint_package.sh.in | 4 +++- scripts/libmakepkg/lint_package/build_references.sh.in | 1 + scripts/libmakepkg/lint_package/missing_backup.sh.in | 1 + scripts/makepkg.sh.in | 4 ++-- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/libmakepkg/lint_package.sh.in b/scripts/libmakepkg/lint_package.sh.in index 82b8b9b..f5bd979 100644 --- a/scripts/libmakepkg/lint_package.sh.in +++ b/scripts/libmakepkg/lint_package.sh.in @@ -40,7 +40,9 @@ lint_package() { cd_safe "$pkgdir" msg "$(gettext "Checking for packaging issue...")" + local ret=0 for func in ${lint_package_functions[@]}; do - $func + $func || ret=1 done + return $ret } diff --git a/scripts/libmakepkg/lint_package/build_references.sh.in b/scripts/libmakepkg/lint_package/build_references.sh.in index 514ec05..cae9852 100644 --- a/scripts/libmakepkg/lint_package/build_references.sh.in +++ b/scripts/libmakepkg/lint_package/build_references.sh.in @@ -37,4 +37,5 @@ warn_build_references() { printf '%s\n' "${refs[@]}" >&2 fi done + return 0 } diff --git a/scripts/libmakepkg/lint_package/missing_backup.sh.in b/scripts/libmakepkg/lint_package/missing_backup.sh.in index 727a18b..1963627 100644 --- a/scripts/libmakepkg/lint_package/missing_backup.sh.in +++ b/scripts/libmakepkg/lint_package/missing_backup.sh.in @@ -35,4 +35,5 @@ warn_missing_backup() { warning "$(gettext "%s entry file not in package : %s")" "backup" "$file" fi done + return 0 } diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 8376e4a..80b5d9e 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1164,7 +1164,7 @@ run_split_packaging() { backup_package_variables run_package $pkgname tidy_install - lint_package + lint_package || exit 1 create_package create_debug_package restore_package_variables @@ -1598,7 +1598,7 @@ if (( INFAKEROOT )); then run_package fi tidy_install - lint_package + lint_package || exit 1 create_package create_debug_package else -- 2.10.2
libalpm's local database format does not support paths with newlines. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- scripts/Makefile.am | 1 + scripts/libmakepkg/lint_package/file_names.sh.in | 42 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 scripts/libmakepkg/lint_package/file_names.sh.in diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 448057d..ba9c3fc 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -58,6 +58,7 @@ LIBMAKEPKG_IN = \ libmakepkg/integrity/verify_signature.sh \ libmakepkg/lint_package.sh \ libmakepkg/lint_package/build_references.sh \ + libmakepkg/lint_package/file_names.sh \ libmakepkg/lint_package/missing_backup.sh \ libmakepkg/lint_pkgbuild.sh \ libmakepkg/lint_pkgbuild/arch.sh \ diff --git a/scripts/libmakepkg/lint_package/file_names.sh.in b/scripts/libmakepkg/lint_package/file_names.sh.in new file mode 100644 index 0000000..56458a3 --- /dev/null +++ b/scripts/libmakepkg/lint_package/file_names.sh.in @@ -0,0 +1,42 @@ +#!/bin/bash +# +# file_names.sh - check package file names +# +# Copyright (c) 2016 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_LINT_PACKAGE_FILE_NAMES_SH" ]] && return +LIBMAKEPKG_LINT_PACKAGE_FILE_NAMES_SH=1 + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" + +lint_package_functions+=('lint_file_names') + +lint_file_names() { + local ret=0 paths + + # alpm's local database format does not support newlines in paths + mapfile -t paths < <(find "$pkgdir" -name \*$'\n'\*) + if (( ${#paths} > 0 )); then + error "$(gettext 'Package contains paths with newlines')" + printf '%s\n' "${paths[@]}" >&2 + ret=1 + fi + + return $ret +} -- 2.10.2
On 06/11/16 08:08, Andrew Gregory wrote:
libalpm's local database format does not support paths with newlines.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- scripts/Makefile.am | 1 + scripts/libmakepkg/lint_package/file_names.sh.in | 42 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 scripts/libmakepkg/lint_package/file_names.sh.in
OK. Needed an addition to scripts/po/POTFILES.in A
participants (2)
-
Allan McRae
-
Andrew Gregory