[pacman-dev] [PATCH 1/2] makepkg: make $pkgdir non-accessible during build()

Allan McRae allan at archlinux.org
Sat Feb 2 00:41:22 EST 2013


On 02/02/13 14:16, Martin Panter wrote:
> On 2 February 2013 02:51, Allan McRae <allan at archlinux.org> wrote:
>> The idea of having separate build() and package() functions is that
>> build() is run as a normal uses and package() as (fake)root.  Any
>> files placed in $pkgdir during build() can have the wrong permissions.
>>
>> Restrict access to $pkgdir during build() - unless there is no package()
>> function.
>>
>> Also, set $pkgdir to something "useful" during build().  For split
>> packages, this uses "<path>/pkg/$pkgbase" because it is not obvious
>> which $pkgdir is being referred to.
>>
>> Signed-off-by: Allan McRae <allan at archlinux.org>
>> ---
>>  scripts/makepkg.sh.in | 42 ++++++++++++++++++++++++------------------
>>  1 file changed, 24 insertions(+), 18 deletions(-)
>>
>> diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
>> index bcc415b..ec39c2e 100644
>> --- a/scripts/makepkg.sh.in
>> +++ b/scripts/makepkg.sh.in
>> @@ -152,7 +152,7 @@ clean_up() {
>>
>>                 # If it's a clean exit and -c/--clean has been passed...
>>                 msg "$(gettext "Cleaning up...")"
>> -               rm -rf "$pkgdir" "$srcdir"
>> +               rm -rf "$pkgdirbase" "$srcdir"
>>                 if [[ -n $pkgbase ]]; then
>>                         local fullver=$(get_full_version)
>>                         # Can't do this unless the BUILDSCRIPT has been sourced.
>> @@ -1519,7 +1519,7 @@ tidy_install() {
>>         if find "${pkgdir}" -type f -print0 | xargs -0  grep -q -I "${srcdir}" ; then
>>                 warning "$(gettext "Package contains reference to %s")" "\$srcdir"
>>         fi
>> -       if find "${pkgdir}" -type f -print0 | xargs -0  grep -q -I "${pkgdir}" ; then
>> +       if find "${pkgdir}" -type f -print0 | xargs -0  grep -q -I "${pkgdirbase}" ; then
>>                 warning "$(gettext "Package contains reference to %s")" "\$pkgdir"
>>         fi
>>
>> @@ -2344,16 +2344,14 @@ restore_package_variables() {
>>  run_split_packaging() {
>>         local pkgname_backup=${pkgname[@]}
>>         for pkgname in ${pkgname_backup[@]}; do
>> -               pkgdir="$pkgdir/$pkgname"
>> -               mkdir -p "$pkgdir"
>> -               chmod a-s "$pkgdir"
>> +               pkgdir="$pkgdirbase/$pkgname"
>> +               mkdir "$pkgdir"
>>                 backup_package_variables
>>                 run_package $pkgname
>>                 tidy_install
>>                 create_package
>>                 create_debug_package
>>                 restore_package_variables
>> -               pkgdir="${pkgdir%/*}"
>>         done
>>         pkgname=${pkgname_backup[@]}
>>  }
>> @@ -2689,12 +2687,16 @@ epoch=${epoch:-0}
>>
>>  if [[ $BUILDDIR = "$startdir" ]]; then
>>         srcdir="$BUILDDIR/src"
>> -       pkgdir="$BUILDDIR/pkg"
>> +       pkgdirbase="$BUILDDIR/pkg"
>>  else
>>         srcdir="$BUILDDIR/$pkgbase/src"
>> -       pkgdir="$BUILDDIR/$pkgbase/pkg"
>> +       pkgdirbase="$BUILDDIR/$pkgbase/pkg"
>> +
>>  fi
>>
>> +# set pkgdir to something "sensible" for (not recommended) use during build()
>> +pkgdir="$pkgdirbase/$pkgbase"
>> +
>>  if (( GENINTEG )); then
>>         mkdir -p "$srcdir"
>>         chmod a-s "$srcdir"
>> @@ -2767,9 +2769,10 @@ if (( INFAKEROOT )); then
>>                 exit 0 # $E_OK
>>         fi
>>
>> +       chmod 755 "$pkgdirbase"
>>         if (( ! SPLITPKG )); then
>> -               pkgdir="$pkgdir/$pkgname"
>> -               mkdir -p "$pkgdir"
>> +               pkgdir="$pkgdirbase/$pkgname"
>> +               mkdir "$pkgdir"
> 
> Looks like removing the “-p” option causes a crash when using
> “--repackage” on a PKGBUILD with no package() function.
> 
> ==> WARNING: Using a PKGBUILD without a package() function is deprecated.
> ==> Checking runtime dependencies...
> ==> Checking buildtime dependencies...
> ==> Entering fakeroot environment...
> mkdir: cannot create directory ‘/home/proj/pacman/pacman/pkg/test’: File exists
> /usr/bin/fakeroot: line 178:  5004 User defined signal 1
> FAKEROOTKEY=$FAKEROOTKEY LD_LIBRARY_PATH="$PATHS" LD_PRELOAD="$LIB"
> "$@"
> 
> Not that I ever used this option, just seeing what it takes to trigger
> the empty package directory error below.

Nice catch...   I forgot "-p" is not just to create parents!

Fixed on my working branch.

Allan




More information about the pacman-dev mailing list