From 56cabe4594ccbc3927fd78669bee9ba73e2660a7 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Fri, 28 Mar 2008 16:33:13 +0200 Subject: [PATCH] Refactor postinst maintainer script handling Based on a patch by Ian Jackson . --- ChangeLog | 21 +++++++++++++++++ src/cleanup.c | 50 ++++++++++++++++++--------------------- src/configure.c | 11 ++++----- src/help.c | 63 +++++++++++++++++++++++++++++++++++++++---------- src/main.h | 1 + 5 files changed, 101 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 122ac871..0178cade 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2008-03-28 Ian Jackson , + Guillem Jover + + * 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 , Guillem Jover diff --git a/src/cleanup.c b/src/cleanup.c index 0a9ffad1..a61aa803 100644 --- a/src/cleanup.c +++ b/src/cleanup.c @@ -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--; diff --git a/src/configure.c b/src/configure.c index 12ffdb1e..71087ef4 100644 --- a/src/configure.c +++ b/src/configure.c @@ -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); diff --git a/src/help.c b/src/help.c index e74d51b7..e4db9f07 100644 --- a/src/help.c +++ b/src/help.c @@ -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; } diff --git a/src/main.h b/src/main.h index 5c503436..add265d6 100644 --- a/src/main.h +++ b/src/main.h @@ -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); -- 2.39.5