]> err.no Git - dpkg/commitdiff
Refactor postinst maintainer script handling
authorGuillem Jover <guillem@debian.org>
Fri, 28 Mar 2008 14:33:13 +0000 (16:33 +0200)
committerGuillem Jover <guillem@debian.org>
Sun, 30 Mar 2008 09:46:43 +0000 (12:46 +0300)
Based on a patch by Ian Jackson <ian@davenant.greenend.org.uk>.

ChangeLog
src/cleanup.c
src/configure.c
src/help.c
src/main.h

index 122ac871125fbb7c06fd402c8b265d9f6eaa245e..0178cade9d56ad7a3ca44da3adfe4b27b7d0e85d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2008-03-28  Ian Jackson  <ian@davenant.greenend.org.uk>,
+            Guillem Jover  <guillem@debian.org>
+
+       * src/main.h (maintainer_script_postinst): New prototype.
+       * src/help.c (post_script_tasks): New function.
+       (maintainer_script_installed): Renamed to ...
+       (vmaintainer_script_installed): ... this. Dot not call
+       ensure_diversions.
+       (maintainer_script_installed): New function.
+       (maintainer_script_postinst): Likewise.
+       (maintainer_script_new): Call post_script_tasks instead of directly
+       calling ensure_diversions.
+       (maintainer_script_alternative): Likewise.
+       * src/cleanup.c (cu_prermupgrade): Use maintainer_script_postinst
+       instead of maintainer_script_installed.
+       (cu_prermdeconfigure): Likewise.
+       (cu_prerminfavour): Likewise.
+       (cu_prermremove): Likewise.
+       (deferred_configure): Likewise.
+       * src/configure.c (deferred_configure): Likewise.
+
 2008-03-28  Ian Jackson  <ian@davenant.greenend.org.uk>,
             Guillem Jover  <guillem@debian.org>
 
index 0a9ffad189b2a9edb9060942730475cd7d3d6194..a61aa8038211c0cf5bab31f98a5207717350113e 100644 (file)
@@ -107,11 +107,10 @@ void cu_prermupgrade(int argc, void **argv) {
   struct pkginfo *pkg= (struct pkginfo*)argv[0];
 
   if (cleanup_pkg_failed++) return;
-  maintainer_script_installed(pkg,POSTINSTFILE,"post-installation",
-                              "abort-upgrade",
-                              versiondescribe(&pkg->available.version,
-                                              vdew_nonambig),
-                              NULL);
+  maintainer_script_postinst(pkg, "abort-upgrade",
+                             versiondescribe(&pkg->available.version,
+                                             vdew_nonambig),
+                             NULL);
   pkg->eflag &= ~eflagf_reinstreq;
   post_postinst_tasks(pkg, stat_installed);
   cleanup_pkg_failed--;
@@ -132,22 +131,20 @@ void cu_prermdeconfigure(int argc, void **argv) {
   struct pkginfo *infavour= (struct pkginfo*)argv[2];
 
   if (conflictor) {
-    maintainer_script_installed(deconf, POSTINSTFILE, "post-installation",
-                                "abort-deconfigure",
-                                "in-favour", infavour->name,
-                                versiondescribe(&infavour->available.version,
-                                                vdew_nonambig),
-                                "removing", conflictor->name,
-                                versiondescribe(&conflictor->installed.version,
-                                                vdew_nonambig),
-                                NULL);
+    maintainer_script_postinst(deconf, "abort-deconfigure",
+                               "in-favour", infavour->name,
+                               versiondescribe(&infavour->available.version,
+                                               vdew_nonambig),
+                               "removing", conflictor->name,
+                               versiondescribe(&conflictor->installed.version,
+                                               vdew_nonambig),
+                               NULL);
   } else {
-    maintainer_script_installed(deconf, POSTINSTFILE, "post-installation",
-                                "abort-deconfigure",
-                                "in-favour", infavour->name,
-                                versiondescribe(&infavour->available.version,
-                                                vdew_nonambig),
-                                NULL);
+    maintainer_script_postinst(deconf, "abort-deconfigure",
+                               "in-favour", infavour->name,
+                               versiondescribe(&infavour->available.version,
+                                               vdew_nonambig),
+                               NULL);
   }
 
   post_postinst_tasks(deconf, stat_installed);
@@ -158,11 +155,11 @@ void cu_prerminfavour(int argc, void **argv) {
   struct pkginfo *infavour= (struct pkginfo*)argv[1];
 
   if (cleanup_conflictor_failed++) return;
-  maintainer_script_installed(conflictor,POSTINSTFILE,"post-installation",
-                              "abort-remove", "in-favour", infavour->name,
-                              versiondescribe(&infavour->available.version,
-                                              vdew_nonambig),
-                              NULL);
+  maintainer_script_postinst(conflictor, "abort-remove",
+                             "in-favour", infavour->name,
+                             versiondescribe(&infavour->available.version,
+                                             vdew_nonambig),
+                             NULL);
   conflictor->eflag &= ~eflagf_reinstreq;
   post_postinst_tasks(conflictor, stat_installed);
   cleanup_conflictor_failed--;
@@ -233,8 +230,7 @@ void cu_prermremove(int argc, void **argv) {
   enum pkgstatus *oldpkgstatus= (enum pkgstatus*)argv[1];
 
   if (cleanup_pkg_failed++) return;
-  maintainer_script_installed(pkg,POSTINSTFILE,"post-installation",
-                              "abort-remove", NULL);
+  maintainer_script_postinst(pkg, "abort-remove", NULL);
   pkg->eflag &= ~eflagf_reinstreq;
   post_postinst_tasks(pkg, *oldpkgstatus);
   cleanup_pkg_failed--;
index 12ffdb1ead082a64af5540e3af33e2ef90c89a5f..71087ef48ec9ccdcdae380230d2a6b4514593806 100644 (file)
@@ -296,12 +296,11 @@ void deferred_configure(struct pkginfo *pkg) {
 
        modstatdb_note(pkg);
 
-       maintainer_script_installed(pkg, POSTINSTFILE, "post-installation",
-                                   "configure",
-                                   informativeversion(&pkg->configversion) ?
-                                   versiondescribe(&pkg->configversion,
-                                                   vdew_nonambig) : "",
-                                   NULL);
+       maintainer_script_postinst(pkg, "configure",
+                                  informativeversion(&pkg->configversion) ?
+                                  versiondescribe(&pkg->configversion,
+                                                  vdew_nonambig) : "",
+                                  NULL);
 
        pkg->eflag= eflagv_ok;
        post_postinst_tasks(pkg, stat_installed);
index e74d51b7a2ade3a9c30efbb200837fbadffedf0d..e4db9f072bbef72345d4264fd4e45ea7ff5b7564 100644 (file)
@@ -224,6 +224,12 @@ post_postinst_tasks(struct pkginfo *pkg, enum pkgstatus new_status)
   modstatdb_note(pkg);
 }
 
+static void
+post_script_tasks(void)
+{
+  ensure_diversions();
+}
+
 static void setexecute(const char *path, struct stat *stab) {
   if ((stab->st_mode & 0555) == 0555) return;
   if (!chmod(path,0755)) return;
@@ -252,33 +258,64 @@ static int do_script(const char *pkg, const char *scriptname, const char *script
   return r;
 }
 
-int maintainer_script_installed(struct pkginfo *pkg, const char *scriptname,
-                                const char *description, ...) {
-  /* all ...'s are const char*'s */
+static int
+vmaintainer_script_installed(struct pkginfo *pkg, const char *scriptname,
+                             const char *description, va_list ap)
+{
   const char *scriptpath;
   char *const *arglist;
   struct stat stab;
-  va_list ap;
   char buf[100];
 
   scriptpath= pkgadminfile(pkg,scriptname);
-  va_start(ap,description);
   arglist= vbuildarglist(scriptname,ap);
-  va_end(ap);
   sprintf(buf,"%s script",description);
 
   if (stat(scriptpath,&stab)) {
     if (errno == ENOENT) {
-      debug(dbg_scripts,"maintainer_script_installed nonexistent %s",scriptname);
+      debug(dbg_scripts, "vmaintainer_script_installed nonexistent %s",
+            scriptname);
       return 0;
     }
     ohshite(_("unable to stat installed %s script `%.250s'"),description,scriptpath);
   }
   do_script(pkg->name, scriptname, scriptpath, &stab, arglist, _("unable to execute %s"), buf, 0);
-  ensure_diversions();
+
   return 1;
 }
-  
+
+/* All ...'s are const char*'s. */
+int
+maintainer_script_installed(struct pkginfo *pkg, const char *scriptname,
+                            const char *description, ...)
+{
+  int r;
+  va_list ap;
+
+  va_start(ap, description);
+  r = vmaintainer_script_installed(pkg, scriptname, description, ap);
+  va_end(ap);
+  if (r)
+    post_script_tasks();
+
+  return r;
+}
+
+int
+maintainer_script_postinst(struct pkginfo *pkg, ...)
+{
+  int r;
+  va_list ap;
+
+  va_start(ap, pkg);
+  r = vmaintainer_script_installed(pkg, POSTINSTFILE, "post-installation", ap);
+  va_end(ap);
+  if (r)
+    ensure_diversions();
+
+  return r;
+}
+
 int maintainer_script_new(const char *pkgname,
                          const char *scriptname, const char *description,
                           const char *cidir, char *cidirrest, ...) {
@@ -301,7 +338,8 @@ int maintainer_script_new(const char *pkgname,
     ohshite(_("unable to stat new %s script `%.250s'"),description,cidir);
   }
   do_script(pkgname, scriptname, cidir, &stab, arglist, _("unable to execute new %s"), buf, 0);
-  ensure_diversions();
+  post_script_tasks();
+
   return 1;
 }
 
@@ -332,7 +370,7 @@ int maintainer_script_alternative(struct pkginfo *pkg,
   } else {
     if (!do_script(pkg->name, scriptname, oldscriptpath, &stab, arglist, _("unable to execute %s"), buf, PROCWARN))
       return 1;
-    ensure_diversions();
+    post_script_tasks();
   }
   fprintf(stderr, _("dpkg - trying script from the new package instead ...\n"));
 
@@ -353,7 +391,8 @@ int maintainer_script_alternative(struct pkginfo *pkg,
   do_script(pkg->name, scriptname, cidir, &stab, arglist, _("unable to execute %s"), buf, 0);
   fprintf(stderr, _("dpkg: ... it looks like that went OK.\n"));
 
-  ensure_diversions();
+  post_script_tasks();
+
   return 1;
 }
 
index 5c5034364751dc9877a093ace75be34db8e388d0..add265d62b8ce4b2d913515c71d628c7ae415c10 100644 (file)
@@ -214,6 +214,7 @@ int maintainer_script_alternative(struct pkginfo *pkg,
                                   const char *scriptname, const char *description,
                                   const char *cidir, char *cidirrest,
                                   const char *ifok, const char *iffallback);
+int maintainer_script_postinst(struct pkginfo *pkg, ...);
 void post_postinst_tasks(struct pkginfo *pkg, enum pkgstatus new_status);
 
 void clear_istobes(void);