[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Guillem Jover] Parsing of dpkg status file considered harmful



Hi bash/shell/dpkg_md5sum gurus,

Can you comment on my proposed patch, it is lying uncommited in my
subversion repos ...

On Die, 05 Jun 2007, Norbert Preining wrote:
> > >   dpkg-query -W -f='${Conffiles}' "$package" \
> > >     | grep -F " $file " | cut -d ' ' -f 3
> > 
> > There is one problem here, we have to know the $package which can/is a
> > bit of a pain ... I took a look into the code in texlive
> 
> Ok, it wasn't that bad, here is a diff for common.functions.preinst,
> comments:
> 
> Index: common.functions.preinst
> ===================================================================
> --- common.functions.preinst	(revision 2935)
> +++ common.functions.preinst	(working copy)
> @@ -3,6 +3,22 @@
>  
>  dpkg_md5sum()
>  {
> +    file="$1"
> +    package="$2"
> +    md5sum=$(dpkg-query -W -f='${Conffiles}' "$package" \
> +            | grep -F " $conffile " | cut -d ' ' -f 3)
> +    if [ -z "$md5sum" ]; then
> +        echo "$file: md5sum not known." >&2
> +        echo "It seems that this file is not handled by dpkg conffiles." >&2
> +        # don't exit but return empty md5sum
> +        md5sum=""
> +        # exit 1
> +    fi
> +    echo $md5sum
> +}
> +
> +dpkg_md5sum_old()
> +{
>      file=$1
>      md5sum=$(grep "$file[[:space:]]"  /var/lib/dpkg/status | cut -f 3 -d ' ')
>      if [ -z "$md5sum" ]; then
> @@ -19,10 +35,11 @@
>  {
>      dodelete="$1"
>      orig="$2"
> -    new="$3"
> -    version="$4"
> +    package="$3"
> +    new="$4"
> +    version="$5"
>      if [ -r "$orig" ] ; then
> -      mdorig=$(dpkg_md5sum "$orig")
> +      mdorig=$(dpkg_md5sum "$orig" "$package")
>        if [ $(md5sum "$orig" | cut -f 1 -d ' ') = "$mdorig" ] ; then
>          rm "$orig"
>        else
> @@ -67,6 +84,8 @@
>      
>      conf_relpath=${cfgfile#/etc/texmf/}
>      conf_oldpath="/etc/texmf/texlive/$conf_relpath"
> +    # default package is texlive-base-bin
> +    package=texlive-base-bin
>      case "$cfgfile" in 
>          /etc/texmf/dvips/config/*)
>              # special case for dvips config
> @@ -74,6 +93,7 @@
>              ;;
>          # files which were only present in tetex
>          /etc/texmf/texdoctk/texdoctk.dat)
> +            package=tetex-base
>              conf_oldpath="/etc/texdoctk/texdoctk.dat"
>              ;;
>          # symlink target had a different name
> @@ -87,12 +107,12 @@
>              # We do not want to create .preinst-deleted, so we call
>              # check_move with first argument 0 which means that the
>              # preinst-deleted file will not be created
> -            check_move 0 /etc/texmf/xdvi.cfg /etc/texmf/xdvi/xdvi.cfg $version
> +            check_move 0 /etc/texmf/xdvi.cfg tetex-bin /etc/texmf/xdvi/xdvi.cfg $version
>              # now set the conf_oldpath to the texlive version
>              conf_oldpath="/etc/texmf/texlive/xdvi.cfg"
>              ;;   
>      esac
> -    check_move 1 $conf_oldpath $cfgfile $version
> +    check_move 1 $conf_oldpath $package $cfgfile $version
>  }
>  # common.functions.preinst end
>  # Local Variables:
> 

Best wishes

Norbert

-------------------------------------------------------------------------------
Dr. Norbert Preining <preining@logic.at>        Vienna University of Technology
Debian Developer <preining@debian.org>                         Debian TeX Group
gpg DSA: 0x09C5B094      fp: 14DF 2E6C 0307 BE6D AD76  A9C0 D2BF 4AA3 09C5 B094
-------------------------------------------------------------------------------
DRAFFAN (n.)
An infuriating person who always manages to look much more dashing
that anyone else by turning up unshaven and hangover at a formal
party.
			--- Douglas Adams, The Meaning of Liff



Reply to: