From 936cb21eddc84e106dc3c64f70ee49d51d4a8a16 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 21 Apr 2008 20:34:25 +0000 Subject: [PATCH] * Add new DEB_REMOVE_FILES_$package variable designed for removing files in .d directories. * Move the "configure-" in the filename encoding from the encode script to divert.mk, so that we can re-use the encoder for DEB_REMOVE_FILES. * Add new DEB_UNDIVERT_FILES_package and DEB_UNREMOVE_FILES_package API variables for having a new version of the package stop diverting a file. * Correct check for not generating an empty if clause when no files are being diverted. * Remove only the last DEB_DIVERT_EXTENSION from filenames. git-svn-id: svn+ssh://svn.mit.edu/athena/trunk/debathena/debathena/config-package-dev@22918 728af825-273c-0410-89f9-f7d3b574a069 --- check-files.mk | 2 +- debian/changelog | 15 ++++++++++++ divert.mk | 50 +++++++++++++++++++++++++++++--------- divert.sh.in | 63 ++++++++++++++++++++++++++++++++++++++++-------- encode | 1 - 5 files changed, 108 insertions(+), 23 deletions(-) diff --git a/check-files.mk b/check-files.mk index ca97c21..a6d61d8 100644 --- a/check-files.mk +++ b/check-files.mk @@ -25,7 +25,7 @@ include /usr/share/cdbs/1/rules/divert.mk DEB_CHECK_FILES_DIR = debian/check_file_copies debian_check_files_source = $(if $(DEB_CHECK_FILES_SOURCE_$(1)),$(DEB_CHECK_FILES_SOURCE_$(1)),$(1)) -debian_check_files_check = $(subst $(DEB_DIVERT_EXTENSION),,$(call debian_check_files_source,$(1))) +debian_check_files_check = $(call divert_files_replace_name,$(call debian_check_files_source,$(1))) debian_check_files = $(patsubst %,$(DEB_CHECK_FILES_DIR)%,$(1)) undebian_check_files = $(patsubst $(DEB_CHECK_FILES_DIR)%,%,$(1)) diff --git a/debian/changelog b/debian/changelog index 9f0210f..a76f588 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,18 @@ +config-package-dev (4.4) unstable; urgency=low + + * Add new DEB_REMOVE_FILES_$package variable designed for removing + files in .d directories. + * Move the "configure-" in the filename encoding from the encode script + to divert.mk, so that we can re-use the encoder for DEB_REMOVE_FILES. + * Add new DEB_UNDIVERT_FILES_package and DEB_UNREMOVE_FILES_package + API variables for having a new version of the package stop diverting a + file. + * Correct check for not generating an empty if clause when no files are + being diverted. + * Remove only the last DEB_DIVERT_EXTENSION from filenames. + + -- Tim Abbott Sat, 19 Apr 2008 21:03:02 -0400 + config-package-dev (4.3) unstable; urgency=low * Fix bug where DEB_DIVERT code gets added twice if a package uses both diff --git a/divert.mk b/divert.mk index 30fb02e..bab1770 100644 --- a/divert.mk +++ b/divert.mk @@ -20,13 +20,16 @@ ifndef _cdbs_rules_divert _cdbs_rules_divert = 1 -CDBS_BUILD_DEPENDS := $(CDBS_BUILD_DEPENDS), config-package-dev +CDBS_BUILD_DEPENDS := $(CDBS_BUILD_DEPENDS), config-package-dev (>= 4.4) DEB_DIVERT_SCRIPT = /usr/share/config-package-dev/divert.sh.in DEB_DIVERT_PACKAGES += $(foreach package,$(DEB_ALL_PACKAGES), \ $(if $(DEB_REPLACE_FILES_$(package)),$(package), \ - $(if $(DEB_DIVERT_FILES_$(package)),$(package)))) + $(if $(DEB_REMOVE_FILES_$(package)),$(package), \ + $(if $(DEB_UNREMOVE_FILES_$(package)),$(package), \ + $(if $(DEB_UNDIVERT_FILES_$(package)),$(package), \ + $(if $(DEB_DIVERT_FILES_$(package)),$(package))))))) ifeq ($(DEB_DIVERT_EXTENSION),) DEB_DIVERT_EXTENSION = .divert @@ -34,33 +37,58 @@ endif DEB_DIVERT_ENCODER = /usr/share/config-package-dev/encode +divert_files_replace_name = $(shell echo $(1) | perl -pe 's/(.*)\Q$(DEB_DIVERT_EXTENSION)\E/$$1$(2)/') + debian-divert/%: package = $(subst debian-divert/,,$@) -debian-divert/%: replace_inputs = $(DEB_REPLACE_FILES_$(package)) -debian-divert/%: replace_files = $(foreach file,$(replace_inputs),$(file)) -debian-divert/%: divert_files = $(DEB_DIVERT_FILES_$(package)) $(replace_files) +debian-divert/%: divert_files = $(DEB_DIVERT_FILES_$(package)) $(DEB_REPLACE_FILES_$(package)) +debian-divert/%: divert_remove_files = $(DEB_REMOVE_FILES_$(package)) +debian-divert/%: divert_undivert_files = $(DEB_UNDIVERT_FILES_$(package)) +debian-divert/%: divert_unremove_files = $(DEB_UNREMOVE_FILES_$(package)) +debian-divert/%: divert_files_all = $(strip $(divert_files) $(divert_remove_files) $(divert_undivert_files) $(divert_unremove_files)) +debian-divert/%: divert_files_thispkg = $(strip $(divert_files) $(divert_remove_files)) $(patsubst %,debian-divert/%,$(DEB_DIVERT_PACKAGES)) :: debian-divert/%: ( \ sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \ - $(if $(divert_files), \ + $(if $(divert_files_all), \ echo 'if [ "$$1" = "configure" ]; then'; \ + $(foreach file,$(divert_undivert_files), \ + $(if $(DEB_UNDIVERT_FILES_VERSION_$(file)),,\ + echo "ERROR! Missing undivert version for $(file)!">&2; exit 1;) \ + echo -n " if [ -n \"\$$2\" ] && dpkg --compare-versions \"\$$2\" '<<' "; \ + echo "'$(DEB_UNDIVERT_FILES_VERSION_$(file))'; then"; \ + echo " undivert_unlink $(call divert_files_replace_name,$(file), )"; \ + echo " fi";) \ + $(foreach file,$(divert_unremove_files), \ + $(if $(DEB_UNREMOVE_FILES_VERSION_$(file)),,\ + echo "ERROR! Missing unremove version for $(file)!">&2; exit 1;) \ + echo -n " if [ -n \"\$$2\" ] && dpkg --compare-versions \"\$$2\" '<<' "; \ + echo "'$(DEB_UNREMOVE_FILES_VERSION_$(file))'; then"; \ + echo " undivert_unremove $(file)"; \ + echo " fi";) \ $(foreach file,$(divert_files), \ - echo " divert_link $(subst $(DEB_DIVERT_EXTENSION), ,$(file))";) \ + echo " divert_link $(call divert_files_replace_name,$(file), )";) \ + $(foreach file,$(divert_remove_files), \ + mkdir -p $(DEB_DESTDIR)/usr/share/$(cdbs_curpkg); \ + echo " divert_remove $(file) /usr/share/$(cdbs_curpkg)/`$(DEB_DIVERT_ENCODER) $(file)`";) \ echo 'fi'; \ ) \ ) >> $(CURDIR)/debian/$(cdbs_curpkg).postinst.debhelper ( \ sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \ - $(if $(divert_files), \ + $(if $(divert_files_thispkg), \ echo 'if [ "$$1" = "remove" ]; then'; \ $(foreach file,$(divert_files), \ - echo " undivert_unlink $(subst $(DEB_DIVERT_EXTENSION), ,$(file))";) \ + echo " undivert_unlink $(call divert_files_replace_name,$(file), )";) \ + $(foreach file,$(divert_remove_files), \ + echo " undivert_unremove $(file) $(cdbs_curpkg)";) \ echo 'fi'; \ ) \ ) >> $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper ( \ echo -n "diverted-files="; \ - $(foreach file,$(divert_files),\ - ${DEB_DIVERT_ENCODER} "$(subst $(DEB_DIVERT_EXTENSION),,$(file))"; \ + $(foreach file,$(divert_files_thispkg),\ + echo -n "configures-"; \ + ${DEB_DIVERT_ENCODER} "$(call divert_files_replace_name,$(file))"; \ echo -n ", ";) \ echo \ ) >> $(CURDIR)/debian/$(cdbs_curpkg).substvars diff --git a/divert.sh.in b/divert.sh.in index 47f006c..b705812 100644 --- a/divert.sh.in +++ b/divert.sh.in @@ -11,7 +11,7 @@ # Undoes the action of divert_link specified # above. # -# Version: 3.4 +# Version: 4.0 # package=#PACKAGE# @@ -19,19 +19,22 @@ package=#PACKAGE# ours=#DEB_DIVERT_EXTENSION# theirs=#DEB_DIVERT_EXTENSION#-orig -divert_link() +divert_link_divert() { - prefix=$1 - suffix=$2 - - file=$prefix$suffix - ourfile=$prefix$ours$suffix - theirfile=$prefix$theirs$suffix - + file=$1 + ourfile=$2 + theirfile=$3 if ! dpkg-divert --list "$package" | \ grep -xFq "diversion of $file to $theirfile by $package"; then dpkg-divert --divert "$theirfile" --rename --package "$package" --add "$file" fi +} + +divert_link_symlink() +{ + file=$1 + ourfile=$2 + theirfile=$3 if [ ! -L "$file" ] && [ ! -e "$file" ]; then ln -s "$(basename "$ourfile")" "$file" elif [ ! -L "$file" ] || \ @@ -41,7 +44,7 @@ divert_link() fi } -undivert_unlink() +divert_link() { prefix=$1 suffix=$2 @@ -49,7 +52,23 @@ undivert_unlink() file=$prefix$suffix ourfile=$prefix$ours$suffix theirfile=$prefix$theirs$suffix + divert_link_divert "$file" "$ourfile" "$theirfile" + divert_link_symlink "$file" "$ourfile" "$theirfile" +} +divert_remove() +{ + file=$1 + ourfile="" + theirfile=$2 + divert_link_divert "$file" "$ourfile" "$theirfile" +} + +undivert_unlink_symlink() +{ + file="$1" + ourfile="$2" + theirfile="$3" if [ ! -L "$file" ] || \ [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \ "$(readlink "$file")" != "$(basename "$theirfile")" ]; then @@ -57,6 +76,11 @@ undivert_unlink() else rm -f "$file" fi +} + +undivert_unlink_divert() +{ + file="$1" if [ ! -L "$file" ] && [ ! -e "$file" ]; then dpkg-divert --remove --rename --package "$package" "$file" else @@ -64,3 +88,22 @@ undivert_unlink() fi } +undivert_unlink() +{ + prefix=$1 + suffix=$2 + + file=$prefix$suffix + ourfile=$prefix$ours$suffix + theirfile=$prefix$theirs$suffix + + undivert_unlink_symlink "$file" "$ourfile" "$theirfile" + undivert_unlink_divert "$file" "$package" +} + +undivert_unremove() +{ + file=$1 + undivert_unlink_divert "$file" +} + diff --git a/encode b/encode index e69cdf6..2a787b4 100755 --- a/encode +++ b/encode @@ -13,7 +13,6 @@ # determine the cause of conflicts between different configuration # packages. -print "configures-"; $ARGV[0] =~ s,^/,,; split('', $ARGV[0]); foreach (@_){ -- 2.45.0