Browse Source

dpkg: Pass <new-version> to maintscript actions that cannot get it otherwise

The upgrade actions and their rollback counterparts do not have access
to the new binary package which is somewhere on the filesystem depending
on how dpkg was invoked, nor to its metadata. If the maintainer script
wants to know the <new-version>, it needs to be turned into a template
and that version instantiated at build-time, which is cumbersome.

So we now pass <new-version> when these upgrade actions are already
getting <old-version>, but not on the cases where they do not get any
argument at all, as that's their differentiator.

Prompted-by: Andrey Utkin <andrey.krieger.utkin@gmail.com>
Guillem Jover 9 years ago
parent
commit
5802467920
7 changed files with 20 additions and 6 deletions
  1. 9 0
      debian/changelog
  2. 3 3
      debian/dpkg.postrm
  3. 2 2
      debian/dpkg.preinst
  4. 1 1
      debian/dpkg.prerm
  5. 2 0
      src/cleanup.c
  6. 1 0
      src/script.c
  7. 2 0
      src/unpack.c

+ 9 - 0
debian/changelog

@@ -60,6 +60,15 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
   * Decouple local keyword declaration from command assignment in
     dpkg-maintscript-helper, which masks the command return value when
     using «set -e».
+  * Make dpkg pass <new-version> to maintscript actions that cannot get it
+    otherwise. These actions are now:
+    - <new-postrm> failed-upgrade <old-version> <new-version>
+    - <new-postrm> abort-install <old-version> <new-version>
+    - <new-postrm> abort-upgrade <old-version> <new-version>
+    - <new-preinst> install <old-version> <new-version>
+    - <new-preinst> upgrade <old-version> <new-version>
+    - <new-prerm> failed-upgrade <old-version> <new-version>
+    Prompted by Andrey Utkin <andrey.krieger.utkin@gmail.com>.
   * Portability:
     - Move DPKG_ADMINDIR environment variable name out from update-alternatives
       code, to make life easier for non-dpkg-based systems.

+ 3 - 3
debian/dpkg.postrm

@@ -10,7 +10,7 @@
 # After the package was upgraded:
 #	<old-postrm> upgrade <new-version>
 # if that fails:
-#	<new-postrm> failed-upgrade <old-version>
+#	<new-postrm> failed-upgrade <old-version> <new-version>
 #
 #
 # After all of the packages files have been replaced:
@@ -21,10 +21,10 @@
 #	<new-postrm> abort-install
 #
 # If preinst fails during upgrade of removed package:
-#	<new-postrm> abort-install <old-version>
+#	<new-postrm> abort-install <old-version> <new-version>
 #
 # If preinst fails during upgrade:
-#	<new-postrm> abort-upgrade <old-version>
+#	<new-postrm> abort-upgrade <old-version> <new-version>
 
 set -e
 

+ 2 - 2
debian/dpkg.preinst

@@ -5,10 +5,10 @@
 #	<new-preinst> install
 #
 # Before removed package is upgraded:
-#	<new-preinst> install <old-version>
+#	<new-preinst> install <old-version> <new-version>
 #
 # Before the package is upgraded:
-#	<new-preinst> upgrade <old-version>
+#	<new-preinst> upgrade <old-version> <new-version>
 #
 #
 # If postrm fails during upgrade or fails on failed upgrade:

+ 1 - 1
debian/dpkg.prerm

@@ -7,7 +7,7 @@
 # Before an upgrade:
 #      <old-prerm> upgrade <new-version>
 # if that fails:
-#      <new-prerm> failed-upgrade <old-version>
+#      <new-prerm> failed-upgrade <old-version> <new-version>
 #
 #
 # Before package is deconfigured while dependency is replaced due to conflict:

+ 2 - 0
src/cleanup.c

@@ -209,6 +209,7 @@ void cu_preinstnew(int argc, void **argv) {
   maintscript_new(pkg, POSTRMFILE, "post-removal", cidir, cidirrest,
                   "abort-install",
                   versiondescribe(&pkg->installed.version, vdew_nonambig),
+                  versiondescribe(&pkg->available.version, vdew_nonambig),
                   NULL);
   pkg_set_status(pkg, PKG_STAT_CONFIGFILES);
   pkg_clear_eflags(pkg, PKG_EFLAG_REINSTREQ);
@@ -226,6 +227,7 @@ void cu_preinstupgrade(int argc, void **argv) {
   maintscript_new(pkg, POSTRMFILE, "post-removal", cidir, cidirrest,
                   "abort-upgrade",
                   versiondescribe(&pkg->installed.version, vdew_nonambig),
+                  versiondescribe(&pkg->available.version, vdew_nonambig),
                   NULL);
   pkg_set_status(pkg, *oldstatusp);
   pkg_clear_eflags(pkg, PKG_EFLAG_REINSTREQ);

+ 1 - 0
src/script.c

@@ -348,6 +348,7 @@ maintscript_fallback(struct pkginfo *pkg,
 	command_init(&cmd, cidir, buf);
 	command_add_args(&cmd, scriptname, iffallback,
 	                 versiondescribe(&pkg->installed.version, vdew_nonambig),
+	                 versiondescribe(&pkg->available.version, vdew_nonambig),
 	                 NULL);
 
 	if (stat(cidir, &stab)) {

+ 2 - 0
src/unpack.c

@@ -1299,6 +1299,7 @@ void process_archive(const char *filename) {
     maintscript_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest,
                     "install",
                     versiondescribe(&pkg->installed.version, vdew_nonambig),
+                    versiondescribe(&pkg->available.version, vdew_nonambig),
                     NULL);
   } else {
     push_cleanup(cu_preinstupgrade, ~ehflag_normaltidy, NULL, 0,
@@ -1306,6 +1307,7 @@ void process_archive(const char *filename) {
     maintscript_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest,
                     "upgrade",
                     versiondescribe(&pkg->installed.version, vdew_nonambig),
+                    versiondescribe(&pkg->available.version, vdew_nonambig),
                     NULL);
   }