소스 검색

Pass ‘struct pkginfo’ instead of pkg name to maint script functions

This allows us to retrieve package information from the maintainer
script invoking functions.
Guillem Jover 17 년 전
부모
커밋
dd1780342a
4개의 변경된 파일23개의 추가작업 그리고 16개의 파일을 삭제
  1. 3 3
      src/cleanup.c
  2. 16 9
      src/help.c
  3. 1 1
      src/main.h
  4. 3 3
      src/processarc.c

+ 3 - 3
src/cleanup.c

@@ -173,7 +173,7 @@ void cu_preinstverynew(int argc, void **argv) {
   char *cidirrest= (char*)argv[2];
 
   if (cleanup_pkg_failed++) return;
-  maintainer_script_new(pkg->name, POSTRMFILE,"post-removal",cidir,cidirrest,
+  maintainer_script_new(pkg, POSTRMFILE, "post-removal", cidir, cidirrest,
                         "abort-install", NULL);
   pkg->status= stat_notinstalled;
   pkg->eflag &= ~eflag_reinstreq;
@@ -188,7 +188,7 @@ void cu_preinstnew(int argc, void **argv) {
   char *cidirrest= (char*)argv[2];
 
   if (cleanup_pkg_failed++) return;
-  maintainer_script_new(pkg->name, POSTRMFILE,"post-removal",cidir,cidirrest,
+  maintainer_script_new(pkg, POSTRMFILE, "post-removal", cidir, cidirrest,
                         "abort-install", versiondescribe(&pkg->installed.version,
                                                          vdew_nonambig),
                         NULL);
@@ -205,7 +205,7 @@ void cu_preinstupgrade(int argc, void **argv) {
   enum pkgstatus *oldstatusp= (enum pkgstatus*)argv[3];
 
   if (cleanup_pkg_failed++) return;
-  maintainer_script_new(pkg->name, POSTRMFILE,"post-removal",cidir,cidirrest,
+  maintainer_script_new(pkg, POSTRMFILE, "post-removal", cidir, cidirrest,
                         "abort-upgrade",
                         versiondescribe(&pkg->installed.version,
                                         vdew_nonambig),

+ 16 - 9
src/help.c

@@ -245,7 +245,12 @@ static void setexecute(const char *path, struct stat *stab) {
   if (!chmod(path,0755)) return;
   ohshite(_("unable to set execute permissions on `%.250s'"),path);
 }
-static int do_script(const char *pkg, const char *scriptname, const char *scriptpath, struct stat *stab, char *const arglist[], const char *desc, const char *name, int warn) {
+
+static int
+do_script(struct pkginfo *pkg,
+          const char *scriptname, const char *scriptpath, struct stat *stab,
+          char *const arglist[], const char *desc, const char *name, int warn)
+{
   const char *scriptexec;
   int c1, r;
   setexecute(scriptpath,stab);
@@ -261,7 +266,7 @@ static int do_script(const char *pkg, const char *scriptname, const char *script
       narglist[r]= arglist[r];
     scriptexec= preexecscript(scriptpath,(char * const *)narglist);
     narglist[0]= scriptexec;
-    if (setenv(MAINTSCRIPTPKGENVVAR, pkg, 1) ||
+    if (setenv(MAINTSCRIPTPKGENVVAR, pkg->name, 1) ||
         setenv(MAINTSCRIPTDPKGENVVAR, PACKAGE_VERSION, 1))
       ohshite(_("unable to setenv for maintainer script"));
     execv(scriptexec,(char * const *)narglist);
@@ -297,7 +302,7 @@ vmaintainer_script_installed(struct pkginfo *pkg, const char *scriptname,
     }
     ohshite(_("unable to stat %s `%.250s'"), buf, scriptpath);
   }
-  do_script(pkg->name, scriptname, scriptpath, &stab, arglist, _("unable to execute %s"), buf, 0);
+  do_script(pkg, scriptname, scriptpath, &stab, arglist, _("unable to execute %s"), buf, 0);
 
   return 1;
 }
@@ -334,9 +339,11 @@ maintainer_script_postinst(struct pkginfo *pkg, ...)
   return r;
 }
 
-int maintainer_script_new(const char *pkgname,
-			  const char *scriptname, const char *description,
-                          const char *cidir, char *cidirrest, ...) {
+int
+maintainer_script_new(struct pkginfo *pkg,
+                      const char *scriptname, const char *description,
+                      const char *cidir, char *cidirrest, ...)
+{
   char *const *arglist;
   struct stat stab;
   va_list ap;
@@ -355,7 +362,7 @@ int maintainer_script_new(const char *pkgname,
     }
     ohshite(_("unable to stat %s `%.250s'"), buf, cidir);
   }
-  do_script(pkgname, scriptname, cidir, &stab, arglist,
+  do_script(pkg, scriptname, cidir, &stab, arglist,
             _("unable to execute %s"), buf, 0);
   post_script_tasks();
 
@@ -386,7 +393,7 @@ int maintainer_script_alternative(struct pkginfo *pkg,
     warning(_("unable to stat %s '%.250s': %s"),
             buf,oldscriptpath,strerror(errno));
   } else {
-    if (!do_script(pkg->name, scriptname, oldscriptpath, &stab, arglist,
+    if (!do_script(pkg, scriptname, oldscriptpath, &stab, arglist,
                    _("unable to execute %s"), buf, PROCWARN)) {
       post_script_tasks();
       return 1;
@@ -408,7 +415,7 @@ int maintainer_script_alternative(struct pkginfo *pkg,
       ohshite(_("unable to stat %s `%.250s'"),buf,cidir);
   }
 
-  do_script(pkg->name, scriptname, cidir, &stab, arglist, _("unable to execute %s"), buf, 0);
+  do_script(pkg, scriptname, cidir, &stab, arglist, _("unable to execute %s"), buf, 0);
   fprintf(stderr, _("dpkg: ... it looks like that went OK.\n"));
 
   post_script_tasks();

+ 1 - 1
src/main.h

@@ -204,7 +204,7 @@ struct filenamenode *namenodetouse(struct filenamenode*, struct pkginfo*);
 /* all ...'s are const char*'s ... */
 int maintainer_script_installed(struct pkginfo *pkg, const char *scriptname,
                                 const char *description, ...);
-int maintainer_script_new(const char *pkgname,
+int maintainer_script_new(struct pkginfo *pkg,
 			  const char *scriptname, const char *description,
                           const char *cidir, char *cidirrest, ...);
 int maintainer_script_alternative(struct pkginfo *pkg,

+ 3 - 3
src/processarc.c

@@ -482,19 +482,19 @@ void process_archive(const char *filename) {
   if (oldversionstatus == stat_notinstalled) {
     push_cleanup(cu_preinstverynew, ~ehflag_normaltidy, NULL, 0,
                  3,(void*)pkg,(void*)cidir,(void*)cidirrest);
-    maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
+    maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest,
                           "install", NULL);
   } else if (oldversionstatus == stat_configfiles) {
     push_cleanup(cu_preinstnew, ~ehflag_normaltidy, NULL, 0,
                  3,(void*)pkg,(void*)cidir,(void*)cidirrest);
-    maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
+    maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest,
                           "install", versiondescribe(&pkg->installed.version,
                                                      vdew_nonambig),
                           NULL);
   } else {
     push_cleanup(cu_preinstupgrade, ~ehflag_normaltidy, NULL, 0,
                  4,(void*)pkg,(void*)cidir,(void*)cidirrest,(void*)&oldversionstatus);
-    maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
+    maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest,
                           "upgrade", versiondescribe(&pkg->installed.version,
                                                      vdew_nonambig),
                           NULL);