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

Re: preinst: get new pkg version to check for downgrade



Hi!

On Thu, 2015-01-08 at 20:12:00 +0100, Guillem Jover wrote:
> On Wed, 2015-01-07 at 17:55:36 +0200, Andrey Utkin wrote:
> > We change database schema from time to time. We do this with scripts,
> > in a way similar to dbconfig-common (but it turned out to be buggy so
> > we made our solution from scratch). It is too hard to support
> > downgrading, so we need to avoid that.
> 
> Ah! Ok, yes, that does make sense. So the rest of the maintainer script
> actions either already get the new-version, it is irrelevant, or they
> are passed the old-version after the new-version is already in the dpkg
> database which then can be retrieved through dpkg-query for example. The
> only problematic actions seem to be the ones involved in upgrades which
> only get the old-version, when it's too early for the maintscript to be
> able to infer the new-version by itself. So I think it would be nice to
> pass that as well just after old-version. Something like these changes:

I'm planning on using the attached patch, which I'll push targetting
dpkg 1.18.0.

> The «<new-preinst> install» case (which I've ignored here) has the
> problem that it cannot get just the <new-version> as it would be
> confused with «<new-preinst> install <old-version>», but maybe that
> calls for passing those as envvars instead, hmmm.

I'll leave this for later pondering, noted it down on my TODO.

> Of course the problem is that only new dpkg versions will pass those
> arguments, so its usage cannot be relied upon until after a stable
> release cycle anyway. I'll ponder about adding this for 1.18.x, but
> I'm running it through the policy list in case someone has comments
> or concerns.

This still applies.

> While at it, it might also make sense to pass <old-version> to:
> 
>   # After the package was purged:
>   #       <postrm> purge
> 
> otherwise the maintscript has not way of knowing which version was
> purged, as the package is not in the database anymore.

But this is actually completely bogus and a non-issue. The purge
maintscript action is called after the conffiles have been removed
but before the package metadata has been cleared, so it should be
accessible through dpkg-query for example.

Thanks,
Guillem
From 88855ab34e6278ec71f5822f06b6d963ba4c706d Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@debian.org>
Date: Sat, 24 Jan 2015 02:10:22 +0100
Subject: [PATCH] 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>
---
 debian/dpkg.postrm  | 6 +++---
 debian/dpkg.preinst | 4 ++--
 debian/dpkg.prerm   | 2 +-
 src/cleanup.c       | 2 ++
 src/script.c        | 1 +
 src/unpack.c        | 2 ++
 6 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/debian/dpkg.postrm b/debian/dpkg.postrm
index f218e95..2b0f7dc 100755
--- a/debian/dpkg.postrm
+++ b/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
 
diff --git a/debian/dpkg.preinst b/debian/dpkg.preinst
index d29fa41..acac88a 100755
--- a/debian/dpkg.preinst
+++ b/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:
diff --git a/debian/dpkg.prerm b/debian/dpkg.prerm
index 9a11387..b9afc49 100755
--- a/debian/dpkg.prerm
+++ b/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:
diff --git a/src/cleanup.c b/src/cleanup.c
index 5e592a4..b455c0a 100644
--- a/src/cleanup.c
+++ b/src/cleanup.c
@@ -207,6 +207,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);
@@ -224,6 +225,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);
diff --git a/src/script.c b/src/script.c
index 2f5ae86..bb373cb 100644
--- a/src/script.c
+++ b/src/script.c
@@ -343,6 +343,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)) {
diff --git a/src/unpack.c b/src/unpack.c
index bdd16f1..dac7baa 100644
--- a/src/unpack.c
+++ b/src/unpack.c
@@ -850,6 +850,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,
@@ -857,6 +858,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);
   }
 
-- 
2.2.1.209.g41e5f3a


Reply to: