Hi,

Quoting Benjamin Drung (2020-01-10 12:35:51)
> thanks for the patch. I tried it and it failed with a dependency issue.
> Debugging it revealed the reason: I have a apt preferences file that reduces
> the pin priority for some repositories. This file is copied in in an
> essential hook. When running as dry-run, the essential hook is skipped and
> therefore apt does not use the pin priority of this preferences file.
> 
> Then I added '--aptopts=Dir::Etc::preferencesparts "[...]"' and it
> worked.

the reason I deactivated hooks for --dry-run is, that hooks are able to do
arbitrary stuff and when specifying --dry-run one probably does not expect
something meaningful to happen. With hooks you could shoot yourself in the
foot. I'm not strongly against allowing users to shoots themselves in the foot,
so another reason to disable them was, that it is then possible to just add
--dry-run to any command line (even including --hook options) and have the
result just work without errors and without the user having to adjust the whole
command line. But your example is a good argument to actually leave hooks be
and expect the user to handle whatever they do.

> Our test-package-selection script did one more thing. It checked that
> exactly one kernel package was installed. Currently mmdebstrap had to
> way to do this check, because all hooks are skipped. This is the code:
> 
> exec 3>&1
> KERNEL_PACKAGE=$(chroot "$1" apt-get install -s -y --no-install-recommends 
> $pkg_list | \
>     tee /dev/fd/3 | grep '^Inst linux-image' | cut -d ' ' -f 2,3 | sed 's/ 
> (/=/')
> exec 3>&-
> number_kernels=$(echo "$KERNEL_PACKAGE" | wc -w)
> if test "$number_kernels" -ne 1; then
>     echo "Error: Found $number_kernels kernels instead of one:" >&2
>     for kernel_package in $KERNEL_PACKAGE; do
>         package="${kernel_package%=*}"
>         echo "*** Kernel package $kernel_package. Direct reverse 
> dependencies:"
>         chroot "$1" apt-cache --no-recommends --no-suggests --no-conflicts \
>             --no-breaks --no-replaces --no-enhances rdepends 
> "${kernel_package}" | \
>             grep -v "^${package}$" | grep -v ':' | sed 's/^ *|\?/  /' | sort 
> | uniq
>         echo "  All recursive reverse dependencies:"
>         chroot "$1" apt-cache --no-recommends --no-suggests --no-conflicts \
>             --no-breaks --no-replaces --no-enhances  --recurse rdepends \
>             "${kernel_package}" | grep -v "^${package}$" | grep -v ':' | \
>             sed 's/^ *|\?/    /' | sort | uniq
>     done
>     printf "Error: Found $number_kernels kernels instead of one." >&2
>     printf " Details see above (search for three asterisks).\n" >&2
>     exit 1
> fi

This would not work anyways with --dry-run because you cannot chroot as the
directory does not contain any binaries.

In case you care: a much cleaner and robust way than the above fragile
grep/cut/sed to answer questions like "what would apt install" or "what are
dependency chains to this package" are to use apt's ability to rely on third
party solvers. You would pass apt your own EDSP script which would intercept
the communication between the apt frontend and the solver backend and would
then be able to parse the EDSP easily because it is in a format similar to
deb822.

Thanks!

cheers, josch

Attachment: signature.asc
Description: signature

Reply via email to