Ticket #867: c-p-d-867.diff

File c-p-d-867.diff, 5.7 KB (added by jdreed, 12 years ago)

Proposed patch

  • divert.sh.in

     
    1919ours=#DEB_DIVERT_EXTENSION# 
    2020theirs=#DEB_DIVERT_EXTENSION#-orig 
    2121 
     22tmpdir="/var/cache/config-package-dev" 
     23 
    2224divert_link_divert() 
    2325{ 
    2426    file=$1 
     
    131133        undivert_unremove "$file" 
    132134    fi 
    133135} 
     136 
     137save_diverted_list() 
     138{ 
     139    filename="$1" 
     140    rm -f "$tmpdir/$filename" 
     141    mkdir -p "$tmpdir" 
     142    touch "$tmpdir/$filename" 
     143    # Get the list of what the currently installed version of the  
     144    # package diverts, from its Conflicts.  We can't simply use  
     145    # dpkg-divert --list, because we can't guarantee that all  
     146    # diversions by our package were created by c-p-d 
     147    diverted_files=$(dpkg-query -W -f '${Conflicts}' "$package" | perl -ne 'sub unparse {    $_ = $_[0];    return "/" unless $_;    return "_" if $_ eq "-";    return uc($_) if /^[a-z]$/;    s/^x//;    return chr hex $_;} s/\s+//g; print join(" ", map { if (/^diverts/) { s|^diverts-|/|; s/\+([^+]*)\+/unparse($1)/eg; (-e $_) ? $_ : "" } } split(",", $_));') 
     148    for f in $diverted_files; do 
     149        # It's possible we should explicitly check for diversion to  
     150        # $theirs or diversion to /usr/share/$packge/(encoded name) 
     151        if LC_ALL=C dpkg-divert --list "$package" | \ 
     152            grep -qx "diversion of $f to .* by $package"; then 
     153            echo $f >> "$tmpdir/$filename" 
     154        fi 
     155    done 
     156} 
     157 
     158cleanup_old_diversions() { 
     159    # Save the list of what we're diverting now 
     160    save_diverted_list "${package}.diversions-new" 
     161    if [ -f "$tmpdir/${package}.diversions-old" ]; then 
     162        for f in $(cat "$tmpdir/${package}.diversions-old"); do 
     163            # If we used to divert something and we now don't, punt it 
     164            if ! grep -xFq "$f" "$tmpdir/${package}.diversions-new"; then 
     165                echo "Cleaning up old diversion of $f" >&2 
     166                undivert_unlink "$f" 
     167            fi 
     168        done 
     169    fi 
     170    rm -f "$tmpdir/${package}.diversions-new" 
     171    rm -f "$tmpdir/${package}.diversions-old" 
     172} 
  • debian/changelog

     
     1config-package-dev (4.14) unstable; urgency=low 
     2 
     3  * Add functions to divert.sh.in and code to the preinst to allow 
     4    config-package-dev to cleanup after itself without requiring manual 
     5    specification of undiversions/unremovals (Trac: #867) 
     6  * Write divert.sh.in to the preinst to enable the aforementioned feature 
     7  * Change the prerm to undivert on "deconfigure" as well as "remove" 
     8    operations (Trac: #388) 
     9 
     10 -- Jonathan Reed <jdreed@mit.edu>  Wed, 26 Sep 2012 11:01:46 -0400 
     11 
    112config-package-dev (4.13) unstable; urgency=low 
    213 
    314  * Fix DEB_CHECK_FILES and DEB_TRANSFORM_FILES with non-conffiles in 
  • debian/control

     
    77Vcs-Git: git://andersk.mit.edu/config-package-dev.git 
    88Vcs-Browser: http://andersk.mit.edu/gitweb/config-package-dev.git 
    99Build-Depends: cdbs, 
    10  debhelper (>= 6), 
     10 debhelper, 
    1111 dh-buildinfo 
    1212Standards-Version: 3.9.2 
    1313 
  • divert.mk

     
    3030 
    3131CDBS_BUILD_DEPENDS := $(CDBS_BUILD_DEPENDS), config-package-dev (>= 4.5~) 
    3232 
    33 # divert.sh.in is included in the postinst/prerm scripts of packages 
    34 # installing diversions using config-package-dev. 
     33# divert.sh.in is included in the preinst/postinst/prerm scripts of  
     34# packages installing diversions using config-package-dev. 
    3535DEB_DIVERT_SCRIPT = /usr/share/config-package-dev/divert.sh.in 
    3636# script used to encode the path of a file uniquely in a valid virtual 
    3737# package name. 
     
    7676        set -e; \ 
    7777        { \ 
    7878            sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \ 
     79            echo 'if [ "$$1" = "configure" ]; then'; \ 
     80            echo '    cleanup_old_diversions'; \ 
    7981            $(if $(divert_files_all), \ 
    80                 echo 'if [ "$$1" = "configure" ]; then'; \ 
    8182                $(foreach file,$(divert_undivert_files), \ 
    8283                    echo "    check_undivert_unlink $(call divert_files_replace_name,$(file), )"; )\ 
    8384                $(foreach file,$(divert_unremove_files), \ 
     
    8788                $(foreach file,$(divert_remove_files), \ 
    8889                    mkdir -p debian/$(cdbs_curpkg)/usr/share/$(cdbs_curpkg); \ 
    8990                    echo "    divert_remove $(file) $(call remove_files_name,$(file))";) \ 
    90                 echo 'fi'; \ 
    9191            ) \ 
     92            echo 'fi'; \ 
    9293        } >> $(CURDIR)/debian/$(cdbs_curpkg).postinst.debhelper 
     94# Add code to the preinst script to calculate the list 
     95# of diverted files from the previous (if any) version 
     96        set -e; \ 
     97        { \ 
     98            sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \ 
     99            echo 'case "$$1" in'; \ 
     100            echo '    install|upgrade)'; \ 
     101            echo '        if [ -n "$$2" ]; then'; \ 
     102            echo '            save_diverted_list "$${package}.diversions-old"'; \ 
     103            echo '        fi'; \ 
     104            echo '        ;;'; \ 
     105            echo 'esac'; \ 
     106        } >> $(CURDIR)/debian/$(cdbs_curpkg).preinst.debhelper 
    93107# Add code to prerm script to undo diversions when package is removed. 
    94108        set -e; \ 
    95109        { \ 
     
    99113                fi;) \ 
    100114            sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \ 
    101115            $(if $(divert_files_thispkg), \ 
    102                 echo 'if [ "$$1" = "remove" ]; then'; \ 
     116                echo 'if [ "$$1" = "remove" ] || [ "$$1" = "deconfigure" ]; then'; \ 
    103117                $(foreach file,$(call reverse_dh_compat_5,$(divert_files)), \ 
    104118                    echo "    undivert_unlink $(call divert_files_replace_name,$(file), )";) \ 
    105119                $(foreach file,$(call reverse_dh_compat_5,$(divert_remove_files)), \