Re: Pre-unblock: dash 0.5.5.1-7.3
Adam D. Barratt wrote:
> diff -u dash-0.5.5.1/debian/dash.preinst dash-0.5.5.1/debian/dash.preinst
> --- dash-0.5.5.1/debian/dash.preinst
> +++ dash-0.5.5.1/debian/dash.preinst
> @@ -1,4 +1,4 @@
> -#!/bin/sh
> +#!/bin/bash
> set -e
>
> divert() {
> @@ -6,16 +6,19 @@
> ltarget=$2
> div=$(dpkg-divert --list $dfile)
> distrib=${3:-$dfile.distrib}
> + temp=$dfile.tmp
> if [ -z "$div" ]; then
> - dpkg-divert --package dash --divert $distrib --add $dfile
> # This differs from dpkg-divert's --rename because we
> # first make a copy of $dfile (the file being diverted)
> # in $distrib. Then, a symlink to $ltarget is forcibly created
> - # from $dfile.
> + # from $dfile; this is performed in two stages with an
> + # intermediate temporary file as ln -sf is not idempotent.
The word I was thinking of before is atomic. ln -sf is not atomic.
> # dpkg-divert's --rename direct equivalent would be:
> # mv $dfile $distrib -- but we could end up without a symlink
> cp -dp $dfile $distrib
> - ln -sf $ltarget $dfile
> + ln -sf $ltarget $temp
> + mv -f $temp $dfile
> + dpkg-divert --package dash --divert $distrib --add $dfile
If preinst is interrupted after the mv but before the dpkg-divert,
then /bin/sh will point to dash but it will not be diverted yet, so if
bash were installed before preinst gets a chance to run again, /bin/sh
would be overwritten. That seems fine to me, expected even.
Thanks, this looks good.
Jonathan
Reply to: