LCOV - code coverage report
Current view: top level - src/main - unpack.c (source / functions) Hit Total Coverage
Test: dpkg 1.21.11 C code coverage Lines: 0 811 0.0 %
Date: 2022-12-03 00:40:01 Functions: 0 20 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 447 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * dpkg - main program for package management
       3                 :            :  * unpack.c - .deb archive unpacking
       4                 :            :  *
       5                 :            :  * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
       6                 :            :  * Copyright © 2006-2015 Guillem Jover <guillem@debian.org>
       7                 :            :  * Copyright © 2011 Linaro Limited
       8                 :            :  * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
       9                 :            :  *
      10                 :            :  * This is free software; you can redistribute it and/or modify
      11                 :            :  * it under the terms of the GNU General Public License as published by
      12                 :            :  * the Free Software Foundation; either version 2 of the License, or
      13                 :            :  * (at your option) any later version.
      14                 :            :  *
      15                 :            :  * This is distributed in the hope that it will be useful,
      16                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      17                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18                 :            :  * GNU General Public License for more details.
      19                 :            :  *
      20                 :            :  * You should have received a copy of the GNU General Public License
      21                 :            :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      22                 :            :  */
      23                 :            : 
      24                 :            : #include <config.h>
      25                 :            : #include <compat.h>
      26                 :            : 
      27                 :            : #include <sys/types.h>
      28                 :            : #include <sys/stat.h>
      29                 :            : #include <sys/wait.h>
      30                 :            : 
      31                 :            : #include <errno.h>
      32                 :            : #include <string.h>
      33                 :            : #include <time.h>
      34                 :            : #include <utime.h>
      35                 :            : #include <fcntl.h>
      36                 :            : #include <dirent.h>
      37                 :            : #include <unistd.h>
      38                 :            : #include <stdint.h>
      39                 :            : #include <stdlib.h>
      40                 :            : #include <stdio.h>
      41                 :            : 
      42                 :            : #include <dpkg/i18n.h>
      43                 :            : #include <dpkg/c-ctype.h>
      44                 :            : #include <dpkg/dpkg.h>
      45                 :            : #include <dpkg/dpkg-db.h>
      46                 :            : #include <dpkg/pkg.h>
      47                 :            : #include <dpkg/pkg-queue.h>
      48                 :            : #include <dpkg/path.h>
      49                 :            : #include <dpkg/buffer.h>
      50                 :            : #include <dpkg/subproc.h>
      51                 :            : #include <dpkg/dir.h>
      52                 :            : #include <dpkg/tarfn.h>
      53                 :            : #include <dpkg/options.h>
      54                 :            : #include <dpkg/db-ctrl.h>
      55                 :            : #include <dpkg/db-fsys.h>
      56                 :            : #include <dpkg/triglib.h>
      57                 :            : 
      58                 :            : #include "file-match.h"
      59                 :            : #include "main.h"
      60                 :            : #include "archives.h"
      61                 :            : 
      62                 :            : static const char *
      63                 :          0 : summarize_filename(const char *filename)
      64                 :            : {
      65                 :            :   const char *pfilename;
      66                 :            :   char *pfilenamebuf;
      67                 :            : 
      68                 :          0 :   for (pfilename = filename;
      69   [ #  #  #  #  :          0 :        pfilename && strlen(pfilename) > 30 && strchr(pfilename, '/') != NULL;
                   #  # ]
      70                 :          0 :        pfilename++)
      71                 :          0 :     pfilename = strchr(pfilename, '/');
      72                 :            : 
      73   [ #  #  #  # ]:          0 :   if (pfilename && pfilename != filename) {
      74                 :          0 :     pfilenamebuf = nfmalloc(strlen(pfilename) + 5);
      75                 :          0 :     sprintf(pfilenamebuf, _(".../%s"), pfilename);
      76                 :          0 :     pfilename = pfilenamebuf;
      77                 :            :   } else {
      78                 :          0 :     pfilename = filename;
      79                 :            :   }
      80                 :            : 
      81                 :          0 :   return pfilename;
      82                 :            : }
      83                 :            : 
      84                 :            : static bool
      85                 :          0 : deb_reassemble(const char **filename, const char **pfilename)
      86                 :            : {
      87                 :            :   static char *reasmbuf = NULL;
      88                 :            :   struct stat stab;
      89                 :            :   int status;
      90                 :            :   pid_t pid;
      91                 :            : 
      92         [ #  # ]:          0 :   if (!reasmbuf)
      93                 :          0 :     reasmbuf = dpkg_db_get_path(REASSEMBLETMP);
      94   [ #  #  #  # ]:          0 :   if (unlink(reasmbuf) && errno != ENOENT)
      95                 :          0 :     ohshite(_("error ensuring '%.250s' doesn't exist"), reasmbuf);
      96                 :            : 
      97                 :          0 :   push_cleanup(cu_pathname, ~0, 1, (void *)reasmbuf);
      98                 :            : 
      99                 :          0 :   pid = subproc_fork();
     100         [ #  # ]:          0 :   if (!pid) {
     101                 :          0 :     execlp(SPLITTER, SPLITTER, "-Qao", reasmbuf, *filename, NULL);
     102                 :          0 :     ohshite(_("unable to execute %s (%s)"),
     103                 :            :             _("split package reassembly"), SPLITTER);
     104                 :            :   }
     105                 :          0 :   status = subproc_reap(pid, SPLITTER, SUBPROC_RETERROR);
     106      [ #  #  # ]:          0 :   switch (status) {
     107                 :          0 :   case 0:
     108                 :            :     /* It was a part - is it complete? */
     109         [ #  # ]:          0 :     if (!stat(reasmbuf, &stab)) {
     110                 :            :       /* Yes. */
     111                 :          0 :       *filename = reasmbuf;
     112                 :          0 :       *pfilename = _("reassembled package file");
     113                 :          0 :       break;
     114         [ #  # ]:          0 :     } else if (errno == ENOENT) {
     115                 :            :       /* No. That's it, we skip it. */
     116                 :          0 :       return false;
     117                 :            :     }
     118                 :            :   case 1:
     119                 :            :     /* No, it wasn't a part. */
     120                 :          0 :     break;
     121                 :          0 :   default:
     122                 :          0 :     ohshit(_("subprocess %s returned error exit status %d"), SPLITTER, status);
     123                 :            :   }
     124                 :            : 
     125                 :          0 :   return true;
     126                 :            : }
     127                 :            : 
     128                 :            : static void
     129                 :          0 : deb_verify(const char *filename)
     130                 :            : {
     131                 :            :   pid_t pid;
     132                 :            : 
     133                 :            :   /* We have to check on every unpack, in case the debsig-verify package
     134                 :            :    * gets installed or removed. */
     135         [ #  # ]:          0 :   if (!find_command(DEBSIGVERIFY))
     136                 :          0 :     return;
     137                 :            : 
     138                 :          0 :   printf(_("Authenticating %s ...\n"), filename);
     139                 :          0 :   fflush(stdout);
     140                 :          0 :   pid = subproc_fork();
     141         [ #  # ]:          0 :   if (!pid) {
     142                 :          0 :     execlp(DEBSIGVERIFY, DEBSIGVERIFY, "-q", filename, NULL);
     143                 :          0 :     ohshite(_("unable to execute %s (%s)"),
     144                 :            :             _("package signature verification"), DEBSIGVERIFY);
     145                 :            :   } else {
     146                 :            :     int status;
     147                 :            : 
     148                 :          0 :     status = subproc_reap(pid, "debsig-verify", SUBPROC_NOCHECK);
     149   [ #  #  #  # ]:          0 :     if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
     150         [ #  # ]:          0 :       if (!in_force(FORCE_BAD_VERIFY))
     151                 :          0 :         ohshit(_("verification on package %s failed!"), filename);
     152                 :            :       else
     153                 :          0 :         notice(_("verification on package %s failed; "
     154                 :            :                  "but installing anyway as you requested"), filename);
     155                 :            :     } else {
     156                 :          0 :       printf(_("passed\n"));
     157                 :            :     }
     158                 :            :   }
     159                 :            : }
     160                 :            : 
     161                 :            : static char *
     162                 :          0 : get_control_dir(char *cidir)
     163                 :            : {
     164         [ #  # ]:          0 :   if (f_noact) {
     165                 :            :     char *tmpdir;
     166                 :            : 
     167                 :          0 :     tmpdir = mkdtemp(path_make_temp_template("dpkg"));
     168         [ #  # ]:          0 :     if (tmpdir == NULL)
     169                 :          0 :       ohshite(_("unable to create temporary directory"));
     170                 :            : 
     171                 :          0 :     cidir = m_realloc(cidir, strlen(tmpdir) + MAXCONTROLFILENAME + 10);
     172                 :            : 
     173                 :          0 :     strcpy(cidir, tmpdir);
     174                 :            : 
     175                 :          0 :     free(tmpdir);
     176                 :            :   } else {
     177                 :            :     const char *admindir;
     178                 :            : 
     179                 :          0 :     admindir = dpkg_db_get_dir();
     180                 :            : 
     181                 :            :     /* The admindir length is always constant on a dpkg execution run. */
     182         [ #  # ]:          0 :     if (cidir == NULL)
     183                 :          0 :       cidir = m_malloc(strlen(admindir) + sizeof(CONTROLDIRTMP) +
     184                 :            :                        MAXCONTROLFILENAME + 10);
     185                 :            : 
     186                 :            :     /* We want it to be on the same filesystem so that we can
     187                 :            :      * use rename(2) to install the postinst &c. */
     188                 :          0 :     strcpy(cidir, admindir);
     189                 :          0 :     strcat(cidir, "/" CONTROLDIRTMP);
     190                 :            : 
     191                 :            :     /* Make sure the control information directory is empty. */
     192                 :          0 :     path_remove_tree(cidir);
     193                 :            :   }
     194                 :            : 
     195                 :          0 :   strcat(cidir, "/");
     196                 :            : 
     197                 :          0 :   return cidir;
     198                 :            : }
     199                 :            : 
     200                 :            : static void
     201                 :          0 : pkg_check_depcon(struct pkginfo *pkg, const char *pfilename)
     202                 :            : {
     203                 :            :   struct dependency *dsearch;
     204                 :            :   struct deppossi *psearch;
     205                 :            :   struct pkginfo *fixbytrigaw;
     206                 :            :   static struct varbuf depprobwhy;
     207                 :            : 
     208                 :            :   /* Check if anything is installed that we conflict with, or not installed
     209                 :            :    * that we need. */
     210                 :          0 :   ensure_package_clientdata(pkg);
     211                 :          0 :   pkg->clientdata->istobe = PKG_ISTOBE_INSTALLNEW;
     212                 :            : 
     213         [ #  # ]:          0 :   for (dsearch = pkg->available.depends; dsearch; dsearch = dsearch->next) {
     214   [ #  #  #  #  :          0 :     switch (dsearch->type) {
                   #  # ]
     215                 :          0 :     case dep_conflicts:
     216                 :            :       /* Look for things we conflict with. */
     217                 :          0 :       check_conflict(dsearch, pkg, pfilename);
     218                 :          0 :       break;
     219                 :          0 :     case dep_breaks:
     220                 :            :       /* Look for things we break. */
     221                 :          0 :       check_breaks(dsearch, pkg, pfilename);
     222                 :          0 :       break;
     223                 :          0 :     case dep_provides:
     224                 :            :       /* Look for things that conflict with what we provide. */
     225                 :          0 :       for (psearch = dsearch->list->ed->depended.installed;
     226         [ #  # ]:          0 :            psearch;
     227                 :          0 :            psearch = psearch->rev_next) {
     228         [ #  # ]:          0 :         if (psearch->up->type != dep_conflicts)
     229                 :          0 :           continue;
     230                 :          0 :         check_conflict(psearch->up, pkg, pfilename);
     231                 :            :       }
     232                 :          0 :       break;
     233                 :          0 :     case dep_suggests:
     234                 :            :     case dep_recommends:
     235                 :            :     case dep_depends:
     236                 :            :     case dep_replaces:
     237                 :            :     case dep_enhances:
     238                 :            :       /* Ignore these here. */
     239                 :          0 :       break;
     240                 :          0 :     case dep_predepends:
     241         [ #  # ]:          0 :       if (!depisok(dsearch, &depprobwhy, NULL, &fixbytrigaw, true)) {
     242         [ #  # ]:          0 :         if (fixbytrigaw) {
     243         [ #  # ]:          0 :           while (fixbytrigaw->trigaw.head)
     244                 :          0 :             trigproc(fixbytrigaw->trigaw.head->pend, TRIGPROC_REQUIRED);
     245                 :            :         } else {
     246                 :          0 :           varbuf_end_str(&depprobwhy);
     247                 :          0 :           notice(_("regarding %s containing %s, pre-dependency problem:\n%s"),
     248                 :            :                  pfilename, pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
     249                 :            :                  depprobwhy.buf);
     250         [ #  # ]:          0 :           if (!force_depends(dsearch->list))
     251                 :          0 :             ohshit(_("pre-dependency problem - not installing %.250s"),
     252                 :            :                    pkgbin_name(pkg, &pkg->available, pnaw_nonambig));
     253                 :          0 :           warning(_("ignoring pre-dependency problem!"));
     254                 :            :         }
     255                 :            :       }
     256                 :            :     }
     257                 :            :   }
     258                 :            : 
     259                 :            :   /* Look for things that conflict with us. */
     260         [ #  # ]:          0 :   for (psearch = pkg->set->depended.installed; psearch; psearch = psearch->rev_next) {
     261         [ #  # ]:          0 :     if (psearch->up->type != dep_conflicts)
     262                 :          0 :       continue;
     263                 :            : 
     264                 :          0 :     check_conflict(psearch->up, pkg, pfilename);
     265                 :            :   }
     266                 :          0 : }
     267                 :            : 
     268                 :            : static void
     269                 :          0 : pkg_deconfigure_others(struct pkginfo *pkg)
     270                 :            : {
     271                 :            :   struct pkg_deconf_list *deconpil;
     272                 :            : 
     273         [ #  # ]:          0 :   for (deconpil = deconfigure; deconpil; deconpil = deconpil->next) {
     274                 :          0 :     struct pkginfo *removing = deconpil->pkg_removal;
     275                 :            : 
     276         [ #  # ]:          0 :     if (deconpil->reason == PKG_WANT_DEINSTALL) {
     277                 :          0 :       printf(_("De-configuring %s (%s), to allow removal of %s (%s) ...\n"),
     278                 :            :              pkg_name(deconpil->pkg, pnaw_nonambig),
     279                 :          0 :              versiondescribe(&deconpil->pkg->installed.version, vdew_nonambig),
     280                 :            :              pkg_name(removing, pnaw_nonambig),
     281                 :          0 :              versiondescribe(&removing->installed.version, vdew_nonambig));
     282         [ #  # ]:          0 :     } else if (deconpil->reason == PKG_WANT_INSTALL) {
     283                 :          0 :       printf(_("De-configuring %s (%s), to allow installation of %s (%s) ...\n"),
     284                 :            :              pkg_name(deconpil->pkg, pnaw_nonambig),
     285                 :          0 :              versiondescribe(&deconpil->pkg->installed.version, vdew_nonambig),
     286                 :            :              pkg_name(pkg, pnaw_nonambig),
     287                 :          0 :              versiondescribe(&pkg->available.version, vdew_nonambig));
     288                 :            :     } else {
     289                 :          0 :       printf(_("De-configuring %s (%s), to allow configuration of %s (%s) ...\n"),
     290                 :            :              pkg_name(deconpil->pkg, pnaw_nonambig),
     291                 :          0 :              versiondescribe(&deconpil->pkg->installed.version, vdew_nonambig),
     292                 :            :              pkg_name(pkg, pnaw_nonambig),
     293                 :          0 :              versiondescribe(&pkg->available.version, vdew_nonambig));
     294                 :            :     }
     295                 :            : 
     296                 :          0 :     trig_activate_packageprocessing(deconpil->pkg);
     297                 :          0 :     pkg_set_status(deconpil->pkg, PKG_STAT_HALFCONFIGURED);
     298                 :          0 :     modstatdb_note(deconpil->pkg);
     299                 :            : 
     300                 :            :     /* This means that we *either* go and run postinst abort-deconfigure,
     301                 :            :      * *or* queue the package for later configure processing, depending
     302                 :            :      * on which error cleanup route gets taken. */
     303                 :          0 :     push_cleanup_fallback(cu_prermdeconfigure, ~ehflag_normaltidy,
     304                 :            :                           ok_prermdeconfigure, ehflag_normaltidy,
     305                 :          0 :                           3, (void *)deconpil->pkg, (void *)removing, (void *)pkg);
     306                 :            : 
     307         [ #  # ]:          0 :     if (removing) {
     308                 :          0 :       maintscript_installed(deconpil->pkg, PRERMFILE, "pre-removal",
     309                 :            :                             "deconfigure", "in-favour",
     310                 :            :                             pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
     311                 :          0 :                             versiondescribe(&pkg->available.version,
     312                 :            :                                             vdew_nonambig),
     313                 :            :                             "removing",
     314                 :            :                             pkg_name(removing, pnaw_nonambig),
     315                 :          0 :                             versiondescribe(&removing->installed.version,
     316                 :            :                                             vdew_nonambig),
     317                 :            :                             NULL);
     318                 :            :     } else {
     319                 :          0 :       maintscript_installed(deconpil->pkg, PRERMFILE, "pre-removal",
     320                 :            :                             "deconfigure", "in-favour",
     321                 :            :                             pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
     322                 :          0 :                             versiondescribe(&pkg->available.version,
     323                 :            :                                             vdew_nonambig),
     324                 :            :                             NULL);
     325                 :            :     }
     326                 :            :   }
     327                 :          0 : }
     328                 :            : 
     329                 :            : /**
     330                 :            :  * Read the conffiles, and copy the hashes across.
     331                 :            :  */
     332                 :            : static void
     333                 :          0 : deb_parse_conffiles(const struct pkginfo *pkg, const char *control_conffiles,
     334                 :            :                     struct fsys_namenode_queue *newconffiles)
     335                 :            : {
     336                 :            :   FILE *conff;
     337                 :            :   char conffilenamebuf[MAXCONFFILENAME];
     338                 :            : 
     339                 :          0 :   conff = fopen(control_conffiles, "r");
     340         [ #  # ]:          0 :   if (conff == NULL) {
     341         [ #  # ]:          0 :     if (errno == ENOENT)
     342                 :          0 :       return;
     343                 :          0 :     ohshite(_("error trying to open %.250s"), control_conffiles);
     344                 :            :   }
     345                 :            : 
     346                 :          0 :   push_cleanup(cu_closestream, ehflag_bombout, 1, conff);
     347                 :            : 
     348         [ #  # ]:          0 :   while (fgets(conffilenamebuf, MAXCONFFILENAME - 2, conff)) {
     349                 :            :     struct pkginfo *otherpkg;
     350                 :            :     struct fsys_node_pkgs_iter *iter;
     351                 :            :     struct fsys_namenode *namenode;
     352                 :            :     struct fsys_namenode_list *newconff;
     353                 :            :     struct conffile *searchconff;
     354                 :          0 :     char *conffilename = conffilenamebuf;
     355                 :            :     char *p;
     356                 :          0 :     enum fsys_namenode_flags confflags = FNNF_NEW_CONFF;
     357                 :            : 
     358                 :          0 :     p = conffilename + strlen(conffilename);
     359         [ #  # ]:          0 :     if (p == conffilename)
     360                 :          0 :       ohshit(_("conffile file contains an empty line"));
     361         [ #  # ]:          0 :     if (p[-1] != '\n')
     362                 :          0 :       ohshit(_("conffile name '%s' is too long, or missing final newline"),
     363                 :            :              conffilename);
     364                 :          0 :     p = str_rtrim_spaces(conffilename, p);
     365         [ #  # ]:          0 :     if (p == conffilename)
     366                 :          0 :       continue;
     367                 :            : 
     368                 :            :     /* Check for conffile flags. */
     369         [ #  # ]:          0 :     if (conffilename[0] != '/') {
     370                 :          0 :       char *flag = conffilename;
     371                 :          0 :       char *flag_end = strchr(flag, ' ');
     372                 :            : 
     373         [ #  # ]:          0 :       if (flag_end)
     374                 :          0 :         conffilename = flag_end + 1;
     375                 :            : 
     376                 :            :       /* If no flag separator is found, assume a missing leading slash. */
     377   [ #  #  #  #  :          0 :       if (flag_end == NULL || (conffilename[0] && conffilename[0] != '/'))
                   #  # ]
     378                 :          0 :         ohshit(_("conffile name '%s' is not an absolute pathname"), conffilename);
     379                 :            : 
     380                 :          0 :       flag_end[0] = '\0';
     381                 :            : 
     382                 :            :       /* Otherwise assume a missing filename after the flag separator. */
     383         [ #  # ]:          0 :       if (conffilename[0] == '\0')
     384                 :          0 :         ohshit(_("conffile name missing after flag '%s'"), flag);
     385                 :            : 
     386         [ #  # ]:          0 :       if (strcmp(flag, "remove-on-upgrade") == 0) {
     387                 :          0 :         confflags |= FNNF_RM_CONFF_ON_UPGRADE;
     388                 :          0 :         confflags &= ~FNNF_NEW_CONFF;
     389                 :            :       } else {
     390         [ #  # ]:          0 :         if (c_isspace(flag[0]))
     391                 :          0 :           warning(_("line with conffile filename '%s' has leading white spaces"),
     392                 :            :                   conffilename);
     393                 :          0 :         ohshit(_("unknown flag '%s' for conffile '%s'"), flag, conffilename);
     394                 :            :       }
     395                 :            :     }
     396                 :            : 
     397                 :          0 :     namenode = fsys_hash_find_node(conffilename, 0);
     398                 :          0 :     namenode->oldhash = NEWCONFFILEFLAG;
     399                 :          0 :     newconff = tar_fsys_namenode_queue_push(newconffiles, namenode);
     400                 :            : 
     401                 :            :     /*
     402                 :            :      * Let's see if any packages have this file.
     403                 :            :      *
     404                 :            :      * If they do we check to see if they listed it as a conffile,
     405                 :            :      * and if they did we copy the hash across. Since (for plain
     406                 :            :      * file conffiles, which is the only kind we are supposed to
     407                 :            :      * have) there will only be one package which ‘has’ the file,
     408                 :            :      * this will usually mean we only look in the package which
     409                 :            :      * we are installing now.
     410                 :            :      *
     411                 :            :      * The ‘conffiles’ data in the status file is ignored when a
     412                 :            :      * package is not also listed in the file ownership database as
     413                 :            :      * having that file. If several packages are listed as owning
     414                 :            :      * the file we pick one at random.
     415                 :            :      */
     416                 :          0 :     searchconff = NULL;
     417                 :            : 
     418                 :          0 :     iter = fsys_node_pkgs_iter_new(newconff->namenode);
     419         [ #  # ]:          0 :     while ((otherpkg = fsys_node_pkgs_iter_next(iter))) {
     420                 :          0 :       debug(dbg_conffdetail,
     421                 :            :             "process_archive conffile '%s' in package %s - conff ?",
     422                 :          0 :             newconff->namenode->name, pkg_name(otherpkg, pnaw_always));
     423                 :          0 :       for (searchconff = otherpkg->installed.conffiles;
     424   [ #  #  #  # ]:          0 :            searchconff && strcmp(newconff->namenode->name, searchconff->name);
     425                 :          0 :            searchconff = searchconff->next)
     426                 :          0 :         debug(dbg_conffdetail,
     427                 :            :               "process_archive conffile '%s' in package %s - conff ? not '%s'",
     428                 :          0 :               newconff->namenode->name, pkg_name(otherpkg, pnaw_always),
     429                 :            :               searchconff->name);
     430         [ #  # ]:          0 :       if (searchconff) {
     431         [ #  # ]:          0 :         debug(dbg_conff,
     432                 :            :               "process_archive conffile '%s' package=%s %s hash=%s",
     433                 :          0 :               newconff->namenode->name, pkg_name(otherpkg, pnaw_always),
     434                 :            :               otherpkg == pkg ? "same" : "different!",
     435                 :            :               searchconff->hash);
     436         [ #  # ]:          0 :         if (otherpkg == pkg)
     437                 :          0 :           break;
     438                 :            :       }
     439                 :            :     }
     440                 :          0 :     fsys_node_pkgs_iter_free(iter);
     441                 :            : 
     442         [ #  # ]:          0 :     if (searchconff) {
     443                 :            :       /* We don't copy ‘obsolete’; it's not obsolete in the new package. */
     444                 :          0 :       newconff->namenode->oldhash = searchconff->hash;
     445                 :            :     } else {
     446                 :          0 :       debug(dbg_conff, "process_archive conffile '%s' no package, no hash",
     447                 :          0 :             newconff->namenode->name);
     448                 :            :     }
     449                 :          0 :     newconff->namenode->flags |= confflags;
     450                 :            :   }
     451                 :            : 
     452         [ #  # ]:          0 :   if (ferror(conff))
     453                 :          0 :     ohshite(_("read error in %.250s"), control_conffiles);
     454                 :          0 :   pop_cleanup(ehflag_normaltidy); /* conff = fopen() */
     455         [ #  # ]:          0 :   if (fclose(conff))
     456                 :          0 :     ohshite(_("error closing %.250s"), control_conffiles);
     457                 :            : }
     458                 :            : 
     459                 :            : static struct pkg_queue conflictors = PKG_QUEUE_INIT;
     460                 :            : 
     461                 :            : void
     462                 :          0 : enqueue_conflictor(struct pkginfo *pkg)
     463                 :            : {
     464                 :          0 :   pkg_queue_push(&conflictors, pkg);
     465                 :          0 : }
     466                 :            : 
     467                 :            : static void
     468                 :          0 : pkg_infodb_remove_file(const char *filename, const char *filetype)
     469                 :            : {
     470         [ #  # ]:          0 :   if (unlink(filename))
     471                 :          0 :     ohshite(_("unable to delete control info file '%.250s'"), filename);
     472                 :            : 
     473                 :          0 :   debug(dbg_scripts, "removal_bulk info unlinked %s", filename);
     474                 :          0 : }
     475                 :            : 
     476                 :            : static struct match_node *match_head = NULL;
     477                 :            : 
     478                 :            : static void
     479                 :          0 : pkg_infodb_update_file(const char *filename, const char *filetype)
     480                 :            : {
     481         [ #  # ]:          0 :   if (strlen(filetype) > MAXCONTROLFILENAME)
     482                 :          0 :     ohshit(_("old version of package has overly-long info file name starting '%.250s'"),
     483                 :            :            filename);
     484                 :            : 
     485                 :            :   /* We do the list separately. */
     486         [ #  # ]:          0 :   if (strcmp(filetype, LISTFILE) == 0)
     487                 :          0 :     return;
     488                 :            : 
     489                 :            :   /* We keep files to rename in a list as doing the rename immediately
     490                 :            :    * might influence the current readdir(), the just renamed file might
     491                 :            :    * be returned a second time as it's actually a new file from the
     492                 :            :    * point of view of the filesystem. */
     493                 :          0 :   match_head = match_node_new(filename, filetype, match_head);
     494                 :            : }
     495                 :            : 
     496                 :            : static void
     497                 :          0 : pkg_infodb_update(struct pkginfo *pkg, char *cidir, char *cidirrest)
     498                 :            : {
     499                 :            :   struct match_node *match_node;
     500                 :            :   DIR *dsd;
     501                 :            :   struct dirent *de;
     502                 :            : 
     503                 :            :   /* Deallocate the match list in case we aborted previously. */
     504         [ #  # ]:          0 :   while ((match_node = match_head)) {
     505                 :          0 :     match_head = match_node->next;
     506                 :          0 :     match_node_free(match_node);
     507                 :            :   }
     508                 :            : 
     509                 :          0 :   pkg_infodb_foreach(pkg, &pkg->available, pkg_infodb_update_file);
     510                 :            : 
     511         [ #  # ]:          0 :   while ((match_node = match_head)) {
     512                 :          0 :     strcpy(cidirrest, match_node->filetype);
     513                 :            : 
     514         [ #  # ]:          0 :     if (!rename(cidir, match_node->filename)) {
     515                 :          0 :       debug(dbg_scripts, "process_archive info installed %s as %s",
     516                 :            :             cidir, match_node->filename);
     517         [ #  # ]:          0 :     } else if (errno == ENOENT) {
     518                 :            :       /* Right, no new version. */
     519         [ #  # ]:          0 :       if (unlink(match_node->filename))
     520                 :          0 :         ohshite(_("unable to remove obsolete info file '%.250s'"),
     521                 :            :                 match_node->filename);
     522                 :          0 :       debug(dbg_scripts, "process_archive info unlinked %s",
     523                 :            :             match_node->filename);
     524                 :            :     } else {
     525                 :          0 :       ohshite(_("unable to install (supposed) new info file '%.250s'"), cidir);
     526                 :            :     }
     527                 :          0 :     match_head = match_node->next;
     528                 :          0 :     match_node_free(match_node);
     529                 :            :   }
     530                 :            : 
     531                 :            :   /* The control directory itself. */
     532                 :          0 :   cidirrest[0] = '\0';
     533                 :          0 :   dsd = opendir(cidir);
     534         [ #  # ]:          0 :   if (!dsd)
     535                 :          0 :     ohshite(_("unable to open temp control directory"));
     536                 :          0 :   push_cleanup(cu_closedir, ~0, 1, (void *)dsd);
     537         [ #  # ]:          0 :   while ((de = readdir(dsd))) {
     538                 :            :     const char *newinfofilename;
     539                 :            : 
     540         [ #  # ]:          0 :     if (strchr(de->d_name, '.')) {
     541                 :          0 :       debug(dbg_scripts, "process_archive tmp.ci script/file '%s' contains dot",
     542                 :          0 :             de->d_name);
     543                 :          0 :       continue;
     544                 :            :     }
     545         [ #  # ]:          0 :     if (strlen(de->d_name) > MAXCONTROLFILENAME)
     546                 :          0 :       ohshit(_("package contains overly-long control info file name (starting '%.50s')"),
     547                 :          0 :              de->d_name);
     548                 :            : 
     549                 :          0 :     strcpy(cidirrest, de->d_name);
     550                 :            : 
     551                 :            :     /* First we check it's not a directory. */
     552         [ #  # ]:          0 :     if (rmdir(cidir) == 0)
     553                 :          0 :       ohshit(_("package control info contained directory '%.250s'"), cidir);
     554         [ #  # ]:          0 :     else if (errno != ENOTDIR)
     555                 :          0 :       ohshite(_("package control info rmdir of '%.250s' didn't say not a dir"),
     556                 :          0 :               de->d_name);
     557                 :            : 
     558                 :            :     /* Ignore the control file. */
     559         [ #  # ]:          0 :     if (strcmp(de->d_name, CONTROLFILE) == 0) {
     560                 :          0 :       debug(dbg_scripts, "process_archive tmp.ci script/file '%s' is control",
     561                 :            :             cidir);
     562                 :          0 :       continue;
     563                 :            :     }
     564         [ #  # ]:          0 :     if (strcmp(de->d_name, LISTFILE) == 0) {
     565                 :          0 :       warning(_("package %s contained list as info file"),
     566                 :            :               pkgbin_name(pkg, &pkg->available, pnaw_nonambig));
     567                 :          0 :       continue;
     568                 :            :     }
     569                 :            : 
     570                 :            :     /* Right, install it */
     571                 :          0 :     newinfofilename = pkg_infodb_get_file(pkg, &pkg->available, de->d_name);
     572         [ #  # ]:          0 :     if (rename(cidir, newinfofilename))
     573                 :          0 :       ohshite(_("unable to install new info file '%.250s' as '%.250s'"),
     574                 :            :               cidir, newinfofilename);
     575                 :            : 
     576                 :          0 :     debug(dbg_scripts,
     577                 :            :           "process_archive tmp.ci script/file '%s' installed as '%s'",
     578                 :            :           cidir, newinfofilename);
     579                 :            :   }
     580                 :          0 :   pop_cleanup(ehflag_normaltidy); /* closedir */
     581                 :            : 
     582                 :            :   /* If the old and new versions use a different infodb layout, get rid
     583                 :            :    * of the files using the old layout. */
     584         [ #  # ]:          0 :   if (pkg->installed.multiarch != pkg->available.multiarch &&
     585         [ #  # ]:          0 :       (pkg->installed.multiarch == PKG_MULTIARCH_SAME ||
     586         [ #  # ]:          0 :        pkg->available.multiarch == PKG_MULTIARCH_SAME)) {
     587                 :          0 :     debug(dbg_scripts,
     588                 :            :           "process_archive remove old info files after db layout switch");
     589                 :          0 :     pkg_infodb_foreach(pkg, &pkg->installed, pkg_infodb_remove_file);
     590                 :            :   }
     591                 :            : 
     592                 :          0 :   dir_sync_path(pkg_infodb_get_dir());
     593                 :          0 : }
     594                 :            : 
     595                 :            : static void
     596                 :          0 : pkg_remove_conffile_on_upgrade(struct pkginfo *pkg, struct fsys_namenode *namenode)
     597                 :            : {
     598                 :            :   struct pkginfo *otherpkg;
     599                 :            :   struct fsys_namenode *usenode;
     600                 :            :   struct fsys_node_pkgs_iter *iter;
     601                 :          0 :   struct varbuf cdr = VARBUF_INIT;
     602                 :          0 :   struct varbuf cdrext = VARBUF_INIT;
     603                 :            :   struct varbuf_state cdrext_state;
     604                 :            :   char currenthash[MD5HASHLEN + 1];
     605                 :            :   int rc;
     606                 :            : 
     607                 :          0 :   usenode = namenodetouse(namenode, pkg, &pkg->installed);
     608                 :            : 
     609                 :          0 :   rc = conffderef(pkg, &cdr, usenode->name);
     610         [ #  # ]:          0 :   if (rc == -1) {
     611                 :          0 :     debug(dbg_conffdetail, "%s: '%s' conffile dereference error: %s", __func__,
     612                 :          0 :           namenode->name, strerror(errno));
     613                 :          0 :     namenode->oldhash = EMPTYHASHFLAG;
     614                 :          0 :     return;
     615                 :            :   }
     616                 :            : 
     617                 :          0 :   varbuf_reset(&cdrext);
     618                 :          0 :   varbuf_add_str(&cdrext, cdr.buf);
     619                 :          0 :   varbuf_end_str(&cdrext);
     620                 :            : 
     621                 :          0 :   varbuf_snapshot(&cdrext, &cdrext_state);
     622                 :            : 
     623                 :          0 :   iter = fsys_node_pkgs_iter_new(namenode);
     624         [ #  # ]:          0 :   while ((otherpkg = fsys_node_pkgs_iter_next(iter))) {
     625                 :          0 :     debug(dbg_conffdetail, "%s: namenode '%s' owned by other %s?",
     626                 :            :           __func__, namenode->name, pkg_name(otherpkg, pnaw_always));
     627                 :            : 
     628         [ #  # ]:          0 :     if (otherpkg == pkg)
     629                 :          0 :       continue;
     630                 :            : 
     631                 :          0 :     debug(dbg_conff, "%s: namenode '%s' owned by other %s, remove-on-upgrade ignored",
     632                 :            :          __func__, namenode->name, pkg_name(otherpkg, pnaw_always));
     633                 :          0 :     fsys_node_pkgs_iter_free(iter);
     634                 :          0 :     return;
     635                 :            :   }
     636                 :          0 :   fsys_node_pkgs_iter_free(iter);
     637                 :            : 
     638                 :            :   /* Remove DPKGDISTEXT variant if still present. */
     639                 :          0 :   varbuf_rollback(&cdrext_state);
     640                 :          0 :   varbuf_add_str(&cdrext, DPKGDISTEXT);
     641                 :          0 :   varbuf_end_str(&cdrext);
     642                 :            : 
     643   [ #  #  #  # ]:          0 :   if (unlink(cdrext.buf) < 0 && errno != ENOENT)
     644                 :          0 :     warning(_("%s: failed to remove '%.250s': %s"),
     645                 :            :             pkg_name(pkg, pnaw_nonambig), cdrext.buf,
     646                 :          0 :             strerror(errno));
     647                 :            : 
     648                 :          0 :   md5hash(pkg, currenthash, cdr.buf);
     649                 :            : 
     650                 :            :   /* Has it been already removed (e.g. by local admin)? */
     651         [ #  # ]:          0 :   if (strcmp(currenthash, NONEXISTENTFLAG) == 0)
     652                 :          0 :     return;
     653                 :            : 
     654                 :            :   /* For unmodified conffiles, we just remove them. */
     655         [ #  # ]:          0 :   if (strcmp(currenthash, namenode->oldhash) == 0) {
     656                 :          0 :     printf(_("Removing obsolete conffile %s ...\n"), cdr.buf);
     657   [ #  #  #  # ]:          0 :     if (unlink(cdr.buf) < 0 && errno != ENOENT)
     658                 :          0 :       warning(_("%s: failed to remove '%.250s': %s"),
     659                 :          0 :               pkg_name(pkg, pnaw_nonambig), cdr.buf, strerror(errno));
     660                 :          0 :     return;
     661                 :            :   }
     662                 :            : 
     663                 :            :   /* Otherwise, preserve the modified conffile. */
     664                 :          0 :   varbuf_rollback(&cdrext_state);
     665                 :          0 :   varbuf_add_str(&cdrext, DPKGOLDEXT);
     666                 :          0 :   varbuf_end_str(&cdrext);
     667                 :            : 
     668                 :          0 :   printf(_("Obsolete conffile '%s' has been modified by you.\n"), cdr.buf);
     669                 :          0 :   printf(_("Saving as %s ...\n"), cdrext.buf);
     670         [ #  # ]:          0 :   if (rename(cdr.buf, cdrext.buf) < 0)
     671                 :          0 :     warning(_("%s: cannot rename obsolete conffile '%s' to '%s': %s"),
     672                 :            :             pkg_name(pkg, pnaw_nonambig),
     673                 :          0 :             cdr.buf, cdrext.buf, strerror(errno));
     674                 :            : }
     675                 :            : 
     676                 :            : static void
     677                 :          0 : pkg_remove_old_files(struct pkginfo *pkg,
     678                 :            :                      struct fsys_namenode_queue *newfiles_queue,
     679                 :            :                      struct fsys_namenode_queue *newconffiles)
     680                 :            : {
     681                 :            :   struct fsys_hash_rev_iter rev_iter;
     682                 :            :   struct fsys_namenode_list *cfile;
     683                 :            :   struct fsys_namenode *namenode;
     684                 :            :   struct stat stab, oldfs;
     685                 :            : 
     686                 :            :   /* Before removing any old files, we try to remove obsolete conffiles that
     687                 :            :    * have been requested to be removed during upgrade. These conffiles are
     688                 :            :    * not tracked as part of the package file lists, so removing them here
     689                 :            :    * means we will get their parent directories removed if not present in the
     690                 :            :    * new package without needing to do anything special ourselves. */
     691         [ #  # ]:          0 :   for (cfile = newconffiles->head; cfile; cfile = cfile->next) {
     692                 :          0 :     debug(dbg_conffdetail, "%s: removing conffile '%s' for %s?", __func__,
     693                 :          0 :           cfile->namenode->name, pkg_name(pkg, pnaw_always));
     694                 :            : 
     695         [ #  # ]:          0 :     if (!(cfile->namenode->flags & FNNF_RM_CONFF_ON_UPGRADE))
     696                 :          0 :       continue;
     697                 :            : 
     698                 :          0 :     pkg_remove_conffile_on_upgrade(pkg, cfile->namenode);
     699                 :            :   }
     700                 :            : 
     701                 :          0 :   fsys_hash_rev_iter_init(&rev_iter, pkg->files);
     702                 :            : 
     703         [ #  # ]:          0 :   while ((namenode = fsys_hash_rev_iter_next(&rev_iter))) {
     704                 :            :     struct fsys_namenode *usenode;
     705                 :            : 
     706         [ #  # ]:          0 :     if ((namenode->flags & FNNF_NEW_CONFF) ||
     707         [ #  # ]:          0 :         (namenode->flags & FNNF_RM_CONFF_ON_UPGRADE) ||
     708         [ #  # ]:          0 :         (namenode->flags & FNNF_NEW_INARCHIVE))
     709                 :          0 :       continue;
     710                 :            : 
     711                 :          0 :     usenode = namenodetouse(namenode, pkg, &pkg->installed);
     712                 :            : 
     713                 :          0 :     varbuf_rollback(&fname_state);
     714                 :          0 :     varbuf_add_str(&fnamevb, usenode->name);
     715                 :          0 :     varbuf_end_str(&fnamevb);
     716                 :            : 
     717   [ #  #  #  # ]:          0 :     if (!stat(fnamevb.buf, &stab) && S_ISDIR(stab.st_mode)) {
     718                 :          0 :       debug(dbg_eachfiledetail, "process_archive: %s is a directory",
     719                 :            :             fnamevb.buf);
     720         [ #  # ]:          0 :       if (dir_is_used_by_others(namenode, pkg))
     721                 :          0 :         continue;
     722                 :            :     }
     723                 :            : 
     724         [ #  # ]:          0 :     if (lstat(fnamevb.buf, &oldfs)) {
     725   [ #  #  #  #  :          0 :       if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR))
                   #  # ]
     726                 :          0 :         warning(_("could not stat old file '%.250s' so not deleting it: %s"),
     727                 :          0 :                 fnamevb.buf, strerror(errno));
     728                 :          0 :       continue;
     729                 :            :     }
     730         [ #  # ]:          0 :     if (S_ISDIR(oldfs.st_mode)) {
     731                 :          0 :       trig_path_activate(usenode, pkg);
     732                 :            : 
     733                 :            :       /* Do not try to remove the root directory. */
     734         [ #  # ]:          0 :       if (strcmp(usenode->name, "/.") == 0)
     735                 :          0 :         continue;
     736                 :            : 
     737         [ #  # ]:          0 :       if (rmdir(fnamevb.buf)) {
     738                 :          0 :         warning(_("unable to delete old directory '%.250s': %s"),
     739                 :          0 :                 namenode->name, strerror(errno));
     740         [ #  # ]:          0 :       } else if ((namenode->flags & FNNF_OLD_CONFF)) {
     741                 :          0 :         warning(_("old conffile '%.250s' was an empty directory "
     742                 :            :                   "(and has now been deleted)"), namenode->name);
     743                 :            :       }
     744                 :            :     } else {
     745                 :          0 :       struct fsys_namenode_list *sameas = NULL;
     746                 :            :       static struct file_ondisk_id empty_ondisk_id;
     747                 :          0 :       struct varbuf cfilename = VARBUF_INIT;
     748                 :            : 
     749                 :            :       /*
     750                 :            :        * Ok, it's an old file, but is it really not in the new package?
     751                 :            :        * It might be known by a different name because of symlinks.
     752                 :            :        *
     753                 :            :        * We need to check to make sure, so we stat the file, then compare
     754                 :            :        * it to the new list. If we find a dev/inode match, we assume they
     755                 :            :        * are the same file, and leave it alone. NOTE: we don't check in
     756                 :            :        * other packages for sanity reasons (we don't want to stat _all_
     757                 :            :        * the files on the system).
     758                 :            :        *
     759                 :            :        * We run down the list of _new_ files in this package. This keeps
     760                 :            :        * the process a little leaner. We are only worried about new ones
     761                 :            :        * since ones that stayed the same don't really apply here.
     762                 :            :        */
     763                 :            : 
     764                 :            :       /* If we can't stat the old or new file, or it's a directory,
     765                 :            :        * we leave it up to the normal code. */
     766                 :          0 :       debug(dbg_eachfile, "process_archive: checking %s for same files on "
     767                 :            :             "upgrade/downgrade", fnamevb.buf);
     768                 :            : 
     769         [ #  # ]:          0 :       for (cfile = newfiles_queue->head; cfile; cfile = cfile->next) {
     770                 :            :         /* If the file has been filtered then treat it as if it didn't exist
     771                 :            :          * on the file system. */
     772         [ #  # ]:          0 :         if (cfile->namenode->flags & FNNF_FILTERED)
     773                 :          0 :           continue;
     774                 :            : 
     775         [ #  # ]:          0 :         if (cfile->namenode->file_ondisk_id == NULL) {
     776                 :            :           struct stat tmp_stat;
     777                 :            : 
     778                 :          0 :           varbuf_reset(&cfilename);
     779                 :          0 :           varbuf_add_str(&cfilename, dpkg_fsys_get_dir());
     780                 :          0 :           varbuf_add_str(&cfilename, cfile->namenode->name);
     781                 :          0 :           varbuf_end_str(&cfilename);
     782                 :            : 
     783         [ #  # ]:          0 :           if (lstat(cfilename.buf, &tmp_stat) == 0) {
     784                 :            :             struct file_ondisk_id *file_ondisk_id;
     785                 :            : 
     786                 :          0 :             file_ondisk_id = nfmalloc(sizeof(*file_ondisk_id));
     787                 :          0 :             file_ondisk_id->id_dev = tmp_stat.st_dev;
     788                 :          0 :             file_ondisk_id->id_ino = tmp_stat.st_ino;
     789                 :          0 :             cfile->namenode->file_ondisk_id = file_ondisk_id;
     790                 :            :           } else {
     791   [ #  #  #  #  :          0 :             if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR))
                   #  # ]
     792                 :          0 :               ohshite(_("unable to stat other new file '%.250s'"),
     793                 :          0 :                       cfile->namenode->name);
     794                 :          0 :             cfile->namenode->file_ondisk_id = &empty_ondisk_id;
     795                 :          0 :             continue;
     796                 :            :           }
     797                 :            :         }
     798                 :            : 
     799         [ #  # ]:          0 :         if (cfile->namenode->file_ondisk_id == &empty_ondisk_id)
     800                 :          0 :           continue;
     801                 :            : 
     802         [ #  # ]:          0 :         if (oldfs.st_dev == cfile->namenode->file_ondisk_id->id_dev &&
     803         [ #  # ]:          0 :             oldfs.st_ino == cfile->namenode->file_ondisk_id->id_ino) {
     804         [ #  # ]:          0 :           if (sameas)
     805                 :          0 :             warning(_("old file '%.250s' is the same as several new files! "
     806                 :            :                       "(both '%.250s' and '%.250s')"), fnamevb.buf,
     807                 :          0 :                     sameas->namenode->name, cfile->namenode->name);
     808                 :          0 :           sameas = cfile;
     809                 :          0 :           debug(dbg_eachfile, "process_archive: not removing %s, "
     810                 :          0 :                 "since it matches %s", fnamevb.buf, cfile->namenode->name);
     811                 :            :         }
     812                 :            :       }
     813                 :            : 
     814                 :          0 :       varbuf_destroy(&cfilename);
     815                 :            : 
     816         [ #  # ]:          0 :       if ((namenode->flags & FNNF_OLD_CONFF)) {
     817         [ #  # ]:          0 :         if (sameas) {
     818         [ #  # ]:          0 :           if (sameas->namenode->flags & FNNF_NEW_CONFF) {
     819         [ #  # ]:          0 :             if (strcmp(sameas->namenode->oldhash, NEWCONFFILEFLAG) == 0) {
     820                 :          0 :               sameas->namenode->oldhash = namenode->oldhash;
     821                 :          0 :               debug(dbg_eachfile, "process_archive: old conff %s "
     822                 :            :                     "is same as new conff %s, copying hash",
     823                 :          0 :                     namenode->name, sameas->namenode->name);
     824                 :            :             } else {
     825                 :          0 :               debug(dbg_eachfile, "process_archive: old conff %s "
     826                 :            :                     "is same as new conff %s but latter already has hash",
     827                 :          0 :                     namenode->name, sameas->namenode->name);
     828                 :            :             }
     829                 :            :           }
     830                 :            :         } else {
     831                 :          0 :           debug(dbg_eachfile, "process_archive: old conff %s "
     832                 :            :                 "is disappearing", namenode->name);
     833                 :          0 :           namenode->flags |= FNNF_OBS_CONFF;
     834                 :          0 :           tar_fsys_namenode_queue_push(newconffiles, namenode);
     835                 :          0 :           tar_fsys_namenode_queue_push(newfiles_queue, namenode);
     836                 :            :         }
     837                 :          0 :         continue;
     838                 :            :       }
     839                 :            : 
     840         [ #  # ]:          0 :       if (sameas)
     841                 :          0 :         continue;
     842                 :            : 
     843                 :          0 :       trig_path_activate(usenode, pkg);
     844                 :            : 
     845         [ #  # ]:          0 :       if (secure_unlink_statted(fnamevb.buf, &oldfs)) {
     846                 :          0 :         warning(_("unable to securely remove old file '%.250s': %s"),
     847                 :          0 :                 namenode->name, strerror(errno));
     848                 :            :       }
     849                 :            :     } /* !S_ISDIR */
     850                 :            :   }
     851                 :          0 : }
     852                 :            : 
     853                 :            : static void
     854                 :          0 : pkg_update_fields(struct pkginfo *pkg, struct fsys_namenode_queue *newconffiles)
     855                 :            : {
     856                 :            :   struct dependency *newdeplist, **newdeplistlastp;
     857                 :            :   struct dependency *newdep, *dep;
     858                 :            :   struct deppossi **newpossilastp, *possi, *newpossi;
     859                 :            :   struct conffile **iconffileslastp, *newiconff;
     860                 :            :   struct fsys_namenode_list *cfile;
     861                 :            : 
     862                 :            :   /* The dependencies are the most difficult. We have to build
     863                 :            :    * a whole new forward dependency tree. At least the reverse
     864                 :            :    * links (linking our deppossi's into the reverse chains)
     865                 :            :    * can be done by copy_dependency_links. */
     866                 :          0 :   newdeplist = NULL;
     867                 :          0 :   newdeplistlastp = &newdeplist;
     868         [ #  # ]:          0 :   for (dep = pkg->available.depends; dep; dep = dep->next) {
     869                 :          0 :     newdep = nfmalloc(sizeof(*newdep));
     870                 :          0 :     newdep->up = pkg;
     871                 :          0 :     newdep->next = NULL;
     872                 :          0 :     newdep->list = NULL;
     873                 :          0 :     newpossilastp = &newdep->list;
     874                 :            : 
     875         [ #  # ]:          0 :     for (possi = dep->list; possi; possi = possi->next) {
     876                 :          0 :       newpossi = nfmalloc(sizeof(*newpossi));
     877                 :          0 :       newpossi->up = newdep;
     878                 :          0 :       newpossi->ed = possi->ed;
     879                 :          0 :       newpossi->next = NULL;
     880                 :          0 :       newpossi->rev_next = newpossi->rev_prev = NULL;
     881                 :          0 :       newpossi->arch_is_implicit = possi->arch_is_implicit;
     882                 :          0 :       newpossi->arch = possi->arch;
     883                 :          0 :       newpossi->verrel = possi->verrel;
     884         [ #  # ]:          0 :       if (possi->verrel != DPKG_RELATION_NONE)
     885                 :          0 :         newpossi->version = possi->version;
     886                 :            :       else
     887                 :          0 :         dpkg_version_blank(&newpossi->version);
     888                 :          0 :       newpossi->cyclebreak = false;
     889                 :          0 :       *newpossilastp = newpossi;
     890                 :          0 :       newpossilastp = &newpossi->next;
     891                 :            :     }
     892                 :          0 :     newdep->type = dep->type;
     893                 :          0 :     *newdeplistlastp = newdep;
     894                 :          0 :     newdeplistlastp = &newdep->next;
     895                 :            :   }
     896                 :            : 
     897                 :            :   /* Right, now we've replicated the forward tree, we
     898                 :            :    * get copy_dependency_links to remove all the old dependency
     899                 :            :    * structures from the reverse links and add the new dependency
     900                 :            :    * structures in instead. It also copies the new dependency
     901                 :            :    * structure pointer for this package into the right field. */
     902                 :          0 :   copy_dependency_links(pkg, &pkg->installed.depends, newdeplist, 0);
     903                 :            : 
     904                 :            :   /* We copy the text fields. */
     905                 :          0 :   pkg->installed.essential = pkg->available.essential;
     906                 :          0 :   pkg->installed.is_protected = pkg->available.is_protected;
     907                 :          0 :   pkg->installed.multiarch = pkg->available.multiarch;
     908                 :          0 :   pkg->installed.description = pkg->available.description;
     909                 :          0 :   pkg->installed.maintainer = pkg->available.maintainer;
     910                 :          0 :   pkg->installed.source = pkg->available.source;
     911                 :          0 :   pkg->installed.arch = pkg->available.arch;
     912                 :          0 :   pkg->installed.pkgname_archqual = pkg->available.pkgname_archqual;
     913                 :          0 :   pkg->installed.installedsize = pkg->available.installedsize;
     914                 :          0 :   pkg->installed.version = pkg->available.version;
     915                 :          0 :   pkg->installed.origin = pkg->available.origin;
     916                 :          0 :   pkg->installed.bugs = pkg->available.bugs;
     917                 :            : 
     918                 :            :   /* We have to generate our own conffiles structure. */
     919                 :          0 :   pkg->installed.conffiles = NULL;
     920                 :          0 :   iconffileslastp = &pkg->installed.conffiles;
     921         [ #  # ]:          0 :   for (cfile = newconffiles->head; cfile; cfile = cfile->next) {
     922                 :          0 :     newiconff = nfmalloc(sizeof(*newiconff));
     923                 :          0 :     newiconff->next = NULL;
     924                 :          0 :     newiconff->name = nfstrsave(cfile->namenode->name);
     925                 :          0 :     newiconff->hash = nfstrsave(cfile->namenode->oldhash);
     926                 :          0 :     newiconff->obsolete = !!(cfile->namenode->flags & FNNF_OBS_CONFF);
     927                 :          0 :     newiconff->remove_on_upgrade = !!(
     928                 :          0 :         cfile->namenode->flags & FNNF_RM_CONFF_ON_UPGRADE);
     929                 :          0 :     *iconffileslastp = newiconff;
     930                 :          0 :     iconffileslastp = &newiconff->next;
     931                 :            :   }
     932                 :            : 
     933                 :            :   /* We can just copy the arbitrary fields list, because it is
     934                 :            :    * never even rearranged. Phew! */
     935                 :          0 :   pkg->installed.arbs = pkg->available.arbs;
     936                 :          0 : }
     937                 :            : 
     938                 :            : static void
     939                 :          0 : pkg_disappear(struct pkginfo *pkg, struct pkginfo *infavour)
     940                 :            : {
     941                 :          0 :   printf(_("(Noting disappearance of %s, which has been completely replaced.)\n"),
     942                 :            :          pkg_name(pkg, pnaw_nonambig));
     943                 :          0 :   log_action("disappear", pkg, &pkg->installed);
     944                 :          0 :   debug(dbg_general, "pkg_disappear disappearing %s",
     945                 :            :         pkg_name(pkg, pnaw_always));
     946                 :            : 
     947                 :          0 :   trig_activate_packageprocessing(pkg);
     948                 :          0 :   maintscript_installed(pkg, POSTRMFILE,
     949                 :            :                         "post-removal script (for disappearance)",
     950                 :            :                         "disappear",
     951                 :            :                         pkgbin_name(infavour, &infavour->available,
     952                 :            :                                     pnaw_nonambig),
     953                 :          0 :                         versiondescribe(&infavour->available.version,
     954                 :            :                                         vdew_nonambig),
     955                 :            :                         NULL);
     956                 :            : 
     957                 :            :   /* OK, now we delete all the stuff in the ‘info’ directory ... */
     958                 :          0 :   debug(dbg_general, "pkg_disappear cleaning info directory");
     959                 :          0 :   pkg_infodb_foreach(pkg, &pkg->installed, pkg_infodb_remove_file);
     960                 :          0 :   dir_sync_path(pkg_infodb_get_dir());
     961                 :            : 
     962                 :          0 :   pkg_set_status(pkg, PKG_STAT_NOTINSTALLED);
     963                 :          0 :   pkg_set_want(pkg, PKG_WANT_UNKNOWN);
     964                 :          0 :   pkg_reset_eflags(pkg);
     965                 :            : 
     966                 :          0 :   dpkg_version_blank(&pkg->configversion);
     967                 :          0 :   pkgbin_blank(&pkg->installed);
     968                 :            : 
     969                 :          0 :   pkg->files_list_valid = false;
     970                 :            : 
     971                 :          0 :   modstatdb_note(pkg);
     972                 :          0 : }
     973                 :            : 
     974                 :            : static void
     975                 :          0 : pkg_disappear_others(struct pkginfo *pkg)
     976                 :            : {
     977                 :            :   struct pkg_hash_iter *iter;
     978                 :            :   struct pkginfo *otherpkg;
     979                 :            :   struct fsys_namenode_list *cfile;
     980                 :            :   struct deppossi *pdep;
     981                 :            :   struct dependency *providecheck;
     982                 :          0 :   struct varbuf depprobwhy = VARBUF_INIT;
     983                 :            : 
     984                 :          0 :   iter = pkg_hash_iter_new();
     985         [ #  # ]:          0 :   while ((otherpkg = pkg_hash_iter_next_pkg(iter)) != NULL) {
     986                 :          0 :     ensure_package_clientdata(otherpkg);
     987                 :            : 
     988         [ #  # ]:          0 :     if (otherpkg == pkg ||
     989         [ #  # ]:          0 :         otherpkg->status == PKG_STAT_NOTINSTALLED ||
     990         [ #  # ]:          0 :         otherpkg->status == PKG_STAT_CONFIGFILES ||
     991         [ #  # ]:          0 :         otherpkg->clientdata->istobe == PKG_ISTOBE_REMOVE ||
     992         [ #  # ]:          0 :         !otherpkg->files)
     993                 :          0 :       continue;
     994                 :            : 
     995                 :            :     /* Do not try to disappear other packages from the same set
     996                 :            :      * if they are Multi-Arch: same */
     997         [ #  # ]:          0 :     if (pkg->installed.multiarch == PKG_MULTIARCH_SAME &&
     998         [ #  # ]:          0 :         otherpkg->installed.multiarch == PKG_MULTIARCH_SAME &&
     999         [ #  # ]:          0 :         otherpkg->set == pkg->set)
    1000                 :          0 :       continue;
    1001                 :            : 
    1002                 :          0 :     debug(dbg_veryverbose, "process_archive checking disappearance %s",
    1003                 :            :           pkg_name(otherpkg, pnaw_always));
    1004                 :            : 
    1005         [ #  # ]:          0 :     if (otherpkg->clientdata->istobe != PKG_ISTOBE_NORMAL &&
    1006         [ #  # ]:          0 :         otherpkg->clientdata->istobe != PKG_ISTOBE_DECONFIGURE)
    1007                 :          0 :       internerr("disappearing package %s is not to be normal or deconfigure, "
    1008                 :            :                 "is to be %d",
    1009                 :            :                 pkg_name(otherpkg, pnaw_always), otherpkg->clientdata->istobe);
    1010                 :            : 
    1011                 :          0 :     for (cfile = otherpkg->files;
    1012   [ #  #  #  # ]:          0 :          cfile && strcmp(cfile->namenode->name, "/.") == 0;
    1013                 :          0 :          cfile = cfile->next);
    1014         [ #  # ]:          0 :     if (!cfile) {
    1015                 :          0 :       debug(dbg_stupidlyverbose, "process_archive no non-root, no disappear");
    1016                 :          0 :       continue;
    1017                 :            :     }
    1018                 :          0 :     for (cfile = otherpkg->files;
    1019   [ #  #  #  # ]:          0 :          cfile && !filesavespackage(cfile, otherpkg, pkg);
    1020                 :          0 :          cfile = cfile->next);
    1021         [ #  # ]:          0 :     if (cfile)
    1022                 :          0 :       continue;
    1023                 :            : 
    1024                 :            :     /* So dependency things will give right answers ... */
    1025                 :          0 :     otherpkg->clientdata->istobe = PKG_ISTOBE_REMOVE;
    1026                 :          0 :     debug(dbg_veryverbose, "process_archive disappear checking dependencies");
    1027                 :          0 :     for (pdep = otherpkg->set->depended.installed;
    1028         [ #  # ]:          0 :          pdep;
    1029                 :          0 :          pdep = pdep->rev_next) {
    1030         [ #  # ]:          0 :       if (pdep->up->type != dep_depends &&
    1031         [ #  # ]:          0 :           pdep->up->type != dep_predepends &&
    1032         [ #  # ]:          0 :           pdep->up->type != dep_recommends)
    1033                 :          0 :         continue;
    1034                 :            : 
    1035         [ #  # ]:          0 :       if (depisok(pdep->up, &depprobwhy, NULL, NULL, false))
    1036                 :          0 :         continue;
    1037                 :            : 
    1038                 :          0 :       varbuf_end_str(&depprobwhy);
    1039                 :          0 :       debug(dbg_veryverbose,"process_archive cannot disappear: %s",
    1040                 :            :             depprobwhy.buf);
    1041                 :          0 :       break;
    1042                 :            :     }
    1043         [ #  # ]:          0 :     if (!pdep) {
    1044                 :            :       /* If we haven't found a reason not to yet, let's look some more. */
    1045                 :          0 :       for (providecheck = otherpkg->installed.depends;
    1046         [ #  # ]:          0 :            providecheck;
    1047                 :          0 :            providecheck = providecheck->next) {
    1048         [ #  # ]:          0 :         if (providecheck->type != dep_provides)
    1049                 :          0 :           continue;
    1050                 :            : 
    1051                 :          0 :         for (pdep = providecheck->list->ed->depended.installed;
    1052         [ #  # ]:          0 :              pdep;
    1053                 :          0 :              pdep = pdep->rev_next) {
    1054         [ #  # ]:          0 :           if (pdep->up->type != dep_depends &&
    1055         [ #  # ]:          0 :               pdep->up->type != dep_predepends &&
    1056         [ #  # ]:          0 :               pdep->up->type != dep_recommends)
    1057                 :          0 :             continue;
    1058                 :            : 
    1059         [ #  # ]:          0 :           if (depisok(pdep->up, &depprobwhy, NULL, NULL, false))
    1060                 :          0 :             continue;
    1061                 :            : 
    1062                 :          0 :           varbuf_end_str(&depprobwhy);
    1063                 :          0 :           debug(dbg_veryverbose,
    1064                 :            :                 "process_archive cannot disappear (provides %s): %s",
    1065                 :          0 :                 providecheck->list->ed->name, depprobwhy.buf);
    1066                 :          0 :           goto break_from_both_loops_at_once;
    1067                 :            :         }
    1068                 :            :       }
    1069                 :          0 :       break_from_both_loops_at_once:;
    1070                 :            :     }
    1071                 :          0 :     otherpkg->clientdata->istobe = PKG_ISTOBE_NORMAL;
    1072         [ #  # ]:          0 :     if (pdep)
    1073                 :          0 :       continue;
    1074                 :            : 
    1075                 :            :     /* No, we're disappearing it. This is the wrong time to go and
    1076                 :            :      * run maintainer scripts and things, as we can't back out. But
    1077                 :            :      * what can we do ?  It has to be run this late. */
    1078                 :          0 :     pkg_disappear(otherpkg, pkg);
    1079                 :            :   } /* while (otherpkg= ... */
    1080                 :          0 :   pkg_hash_iter_free(iter);
    1081                 :          0 : }
    1082                 :            : 
    1083                 :            : /**
    1084                 :            :  * Check if all instances of a pkgset are getting in sync.
    1085                 :            :  *
    1086                 :            :  * If that's the case, the extraction is going to ensure consistency
    1087                 :            :  * of shared files.
    1088                 :            :  */
    1089                 :            : static bool
    1090                 :          0 : pkgset_getting_in_sync(struct pkginfo *pkg)
    1091                 :            : {
    1092                 :            :   struct pkginfo *otherpkg;
    1093                 :            : 
    1094         [ #  # ]:          0 :   for (otherpkg = &pkg->set->pkg; otherpkg; otherpkg = otherpkg->arch_next) {
    1095         [ #  # ]:          0 :     if (otherpkg == pkg)
    1096                 :          0 :       continue;
    1097         [ #  # ]:          0 :     if (otherpkg->status <= PKG_STAT_CONFIGFILES)
    1098                 :          0 :       continue;
    1099         [ #  # ]:          0 :     if (dpkg_version_compare(&pkg->available.version,
    1100                 :          0 :                              &otherpkg->installed.version)) {
    1101                 :          0 :       return false;
    1102                 :            :     }
    1103                 :            :   }
    1104                 :            : 
    1105                 :          0 :   return true;
    1106                 :            : }
    1107                 :            : 
    1108                 :            : static void
    1109                 :          0 : pkg_remove_files_from_others(struct pkginfo *pkg, struct fsys_namenode_list *newfileslist)
    1110                 :            : {
    1111                 :            :   struct fsys_namenode_list *cfile;
    1112                 :            :   struct pkginfo *otherpkg;
    1113                 :            : 
    1114         [ #  # ]:          0 :   for (cfile = newfileslist; cfile; cfile = cfile->next) {
    1115                 :            :     struct fsys_node_pkgs_iter *iter;
    1116                 :            :     struct pkgset *divpkgset;
    1117                 :            : 
    1118         [ #  # ]:          0 :     if (!(cfile->namenode->flags & FNNF_ELIDE_OTHER_LISTS))
    1119                 :          0 :       continue;
    1120                 :            : 
    1121   [ #  #  #  # ]:          0 :     if (cfile->namenode->divert && cfile->namenode->divert->useinstead) {
    1122                 :          0 :       divpkgset = cfile->namenode->divert->pkgset;
    1123         [ #  # ]:          0 :       if (divpkgset == pkg->set) {
    1124                 :          0 :         debug(dbg_eachfile,
    1125                 :            :               "process_archive not overwriting any '%s' (overriding, '%s')",
    1126                 :          0 :               cfile->namenode->name, cfile->namenode->divert->useinstead->name);
    1127                 :          0 :         continue;
    1128                 :            :       } else {
    1129         [ #  # ]:          0 :         debug(dbg_eachfile,
    1130                 :            :               "process_archive looking for overwriting '%s' (overridden by %s)",
    1131                 :          0 :               cfile->namenode->name, divpkgset ? divpkgset->name : "<local>");
    1132                 :            :       }
    1133                 :            :     } else {
    1134                 :          0 :       divpkgset = NULL;
    1135                 :          0 :       debug(dbg_eachfile, "process_archive looking for overwriting '%s'",
    1136                 :          0 :             cfile->namenode->name);
    1137                 :            :     }
    1138                 :            : 
    1139                 :          0 :     iter = fsys_node_pkgs_iter_new(cfile->namenode);
    1140         [ #  # ]:          0 :     while ((otherpkg = fsys_node_pkgs_iter_next(iter))) {
    1141                 :          0 :       debug(dbg_eachfiledetail, "process_archive ... found in %s",
    1142                 :            :             pkg_name(otherpkg, pnaw_always));
    1143                 :            : 
    1144                 :            :       /* A pkgset can share files between instances, so there's no point
    1145                 :            :        * in rewriting the file that's already in place. */
    1146         [ #  # ]:          0 :       if (otherpkg->set == pkg->set)
    1147                 :          0 :         continue;
    1148                 :            : 
    1149         [ #  # ]:          0 :       if (otherpkg->set == divpkgset) {
    1150                 :          0 :         debug(dbg_eachfiledetail, "process_archive ... diverted, skipping");
    1151                 :          0 :         continue;
    1152                 :            :       }
    1153                 :            : 
    1154         [ #  # ]:          0 :       if (cfile->namenode->flags & FNNF_NEW_CONFF)
    1155                 :          0 :         conffile_mark_obsolete(otherpkg, cfile->namenode);
    1156                 :            : 
    1157                 :            :       /* If !files_list_valid then it's one of the disappeared packages above
    1158                 :            :        * or we have already updated the files list file, and we don't bother
    1159                 :            :        * with it here, clearly. */
    1160         [ #  # ]:          0 :       if (!otherpkg->files_list_valid)
    1161                 :          0 :         continue;
    1162                 :            : 
    1163                 :            :       /* Found one. We delete the list entry for this file,
    1164                 :            :        * (and any others in the same package) and then mark the package
    1165                 :            :        * as requiring a reread. */
    1166                 :          0 :       write_filelist_except(otherpkg, &otherpkg->installed,
    1167                 :            :                             otherpkg->files, FNNF_ELIDE_OTHER_LISTS);
    1168                 :          0 :       debug(dbg_veryverbose, "process_archive overwrote from %s",
    1169                 :            :             pkg_name(otherpkg, pnaw_always));
    1170                 :            :     }
    1171                 :          0 :     fsys_node_pkgs_iter_free(iter);
    1172                 :            :   }
    1173                 :          0 : }
    1174                 :            : 
    1175                 :            : static void
    1176                 :          0 : pkg_remove_backup_files(struct pkginfo *pkg, struct fsys_namenode_list *newfileslist)
    1177                 :            : {
    1178                 :            :   struct fsys_namenode_list *cfile;
    1179                 :            : 
    1180         [ #  # ]:          0 :   for (cfile = newfileslist; cfile; cfile = cfile->next) {
    1181                 :            :     struct fsys_namenode *usenode;
    1182                 :            : 
    1183         [ #  # ]:          0 :     if (cfile->namenode->flags & FNNF_NEW_CONFF)
    1184                 :          0 :       continue;
    1185                 :            : 
    1186                 :          0 :     usenode = namenodetouse(cfile->namenode, pkg, &pkg->installed);
    1187                 :            : 
    1188                 :            :     /* Do not try to remove backups for the root directory. */
    1189         [ #  # ]:          0 :     if (strcmp(usenode->name, "/.") == 0)
    1190                 :          0 :       continue;
    1191                 :            : 
    1192                 :          0 :     varbuf_rollback(&fnametmp_state);
    1193                 :          0 :     varbuf_add_str(&fnametmpvb, usenode->name);
    1194                 :          0 :     varbuf_add_str(&fnametmpvb, DPKGTEMPEXT);
    1195                 :          0 :     varbuf_end_str(&fnametmpvb);
    1196                 :          0 :     path_remove_tree(fnametmpvb.buf);
    1197                 :            :   }
    1198                 :          0 : }
    1199                 :            : 
    1200                 :          0 : void process_archive(const char *filename) {
    1201                 :            :   static const struct tar_operations tf = {
    1202                 :            :     .read = tarfileread,
    1203                 :            :     .extract_file = tarobject,
    1204                 :            :     .link = tarobject,
    1205                 :            :     .symlink = tarobject,
    1206                 :            :     .mkdir = tarobject,
    1207                 :            :     .mknod = tarobject,
    1208                 :            :   };
    1209                 :            : 
    1210                 :            :   /* These need to be static so that we can pass their addresses to
    1211                 :            :    * push_cleanup as arguments to the cu_xxx routines; if an error occurs
    1212                 :            :    * we unwind the stack before processing the cleanup list, and these
    1213                 :            :    * variables had better still exist ... */
    1214                 :            :   static int p1[2];
    1215                 :            :   static enum pkgstatus oldversionstatus;
    1216                 :            :   static struct tarcontext tc;
    1217                 :            : 
    1218                 :            :   struct tar_archive tar;
    1219                 :            :   struct dpkg_error err;
    1220                 :            :   enum parsedbflags parsedb_flags;
    1221                 :            :   int rc;
    1222                 :            :   pid_t pid;
    1223                 :            :   struct pkginfo *pkg, *otherpkg;
    1224                 :            :   struct pkg_list *conflictor_iter;
    1225                 :          0 :   char *cidir = NULL;
    1226                 :            :   char *cidirrest;
    1227                 :            :   char *psize;
    1228                 :            :   const char *pfilename;
    1229                 :            :   struct fsys_namenode_queue newconffiles, newfiles_queue;
    1230                 :            :   struct stat stab;
    1231                 :            : 
    1232                 :          0 :   cleanup_pkg_failed= cleanup_conflictor_failed= 0;
    1233                 :            : 
    1234                 :          0 :   pfilename = summarize_filename(filename);
    1235                 :            : 
    1236         [ #  # ]:          0 :   if (stat(filename, &stab))
    1237                 :          0 :     ohshite(_("cannot access archive '%s'"), filename);
    1238                 :            : 
    1239                 :            :   /* We can't ‘tentatively-reassemble’ packages. */
    1240         [ #  # ]:          0 :   if (!f_noact) {
    1241         [ #  # ]:          0 :     if (!deb_reassemble(&filename, &pfilename))
    1242                 :          0 :       return;
    1243                 :            :   }
    1244                 :            : 
    1245                 :            :   /* Verify the package. */
    1246         [ #  # ]:          0 :   if (!f_nodebsig)
    1247                 :          0 :     deb_verify(filename);
    1248                 :            : 
    1249                 :            :   /* Get the control information directory. */
    1250                 :          0 :   cidir = get_control_dir(cidir);
    1251                 :          0 :   cidirrest = cidir + strlen(cidir);
    1252                 :          0 :   push_cleanup(cu_cidir, ~0, 2, (void *)cidir, (void *)cidirrest);
    1253                 :            : 
    1254                 :          0 :   pid = subproc_fork();
    1255         [ #  # ]:          0 :   if (pid == 0) {
    1256                 :          0 :     cidirrest[-1] = '\0';
    1257                 :          0 :     execlp(BACKEND, BACKEND, "--control", filename, cidir, NULL);
    1258                 :          0 :     ohshite(_("unable to execute %s (%s)"),
    1259                 :            :             _("package control information extraction"), BACKEND);
    1260                 :            :   }
    1261                 :          0 :   subproc_reap(pid, BACKEND " --control", 0);
    1262                 :            : 
    1263                 :            :   /* We want to guarantee the extracted files are on the disk, so that the
    1264                 :            :    * subsequent renames to the info database do not end up with old or zero
    1265                 :            :    * length files in case of a system crash. As neither dpkg-deb nor tar do
    1266                 :            :    * explicit fsync()s, we have to do them here.
    1267                 :            :    * XXX: This could be avoided by switching to an internal tar extractor. */
    1268                 :          0 :   dir_sync_contents(cidir);
    1269                 :            : 
    1270                 :          0 :   strcpy(cidirrest,CONTROLFILE);
    1271                 :            : 
    1272         [ #  # ]:          0 :   if (cipaction->arg_int == act_avail)
    1273                 :          0 :     parsedb_flags = pdb_parse_available;
    1274                 :            :   else
    1275                 :          0 :     parsedb_flags = pdb_parse_binary;
    1276                 :          0 :   parsedb_flags |= pdb_ignore_archives;
    1277         [ #  # ]:          0 :   if (in_force(FORCE_BAD_VERSION))
    1278                 :          0 :     parsedb_flags |= pdb_lax_version_parser;
    1279                 :            : 
    1280                 :          0 :   parsedb(cidir, parsedb_flags, &pkg);
    1281                 :            : 
    1282         [ #  # ]:          0 :   if (!pkg->archives) {
    1283                 :          0 :     pkg->archives = nfmalloc(sizeof(*pkg->archives));
    1284                 :          0 :     pkg->archives->next = NULL;
    1285                 :          0 :     pkg->archives->name = NULL;
    1286                 :          0 :     pkg->archives->msdosname = NULL;
    1287                 :          0 :     pkg->archives->md5sum = NULL;
    1288                 :            :   }
    1289                 :            :   /* Always nfmalloc. Otherwise, we may overwrite some other field (like
    1290                 :            :    * md5sum). */
    1291                 :          0 :   psize = nfmalloc(30);
    1292                 :          0 :   sprintf(psize, "%jd", (intmax_t)stab.st_size);
    1293                 :          0 :   pkg->archives->size = psize;
    1294                 :            : 
    1295         [ #  # ]:          0 :   if (cipaction->arg_int == act_avail) {
    1296                 :          0 :     printf(_("Recorded info about %s from %s.\n"),
    1297                 :          0 :            pkgbin_name(pkg, &pkg->available, pnaw_nonambig), pfilename);
    1298                 :          0 :     pop_cleanup(ehflag_normaltidy);
    1299                 :          0 :     return;
    1300                 :            :   }
    1301                 :            : 
    1302         [ #  # ]:          0 :   if (pkg->available.arch->type != DPKG_ARCH_ALL &&
    1303         [ #  # ]:          0 :       pkg->available.arch->type != DPKG_ARCH_NATIVE &&
    1304         [ #  # ]:          0 :       pkg->available.arch->type != DPKG_ARCH_FOREIGN)
    1305                 :          0 :     forcibleerr(FORCE_ARCHITECTURE,
    1306                 :          0 :                 _("package architecture (%s) does not match system (%s)"),
    1307                 :          0 :                 pkg->available.arch->name,
    1308                 :          0 :                 dpkg_arch_get(DPKG_ARCH_NATIVE)->name);
    1309                 :            : 
    1310                 :          0 :   clear_deconfigure_queue();
    1311                 :          0 :   clear_istobes();
    1312                 :            : 
    1313         [ #  # ]:          0 :   if (wanttoinstall(pkg)) {
    1314                 :          0 :     pkg_set_want(pkg, PKG_WANT_INSTALL);
    1315                 :            :   } else {
    1316                 :          0 :     pop_cleanup(ehflag_normaltidy);
    1317                 :          0 :     return;
    1318                 :            :   }
    1319                 :            : 
    1320                 :            :   /* Deconfigure other instances from a pkgset if they are not in sync. */
    1321         [ #  # ]:          0 :   for (otherpkg = &pkg->set->pkg; otherpkg; otherpkg = otherpkg->arch_next) {
    1322         [ #  # ]:          0 :     if (otherpkg == pkg)
    1323                 :          0 :       continue;
    1324         [ #  # ]:          0 :     if (otherpkg->status <= PKG_STAT_HALFCONFIGURED)
    1325                 :          0 :       continue;
    1326                 :            : 
    1327         [ #  # ]:          0 :     if (dpkg_version_compare(&pkg->available.version,
    1328                 :          0 :                              &otherpkg->installed.version))
    1329                 :          0 :       enqueue_deconfigure(otherpkg, NULL, PKG_WANT_UNKNOWN);
    1330                 :            :   }
    1331                 :            : 
    1332                 :          0 :   pkg_check_depcon(pkg, pfilename);
    1333                 :            : 
    1334                 :          0 :   ensure_allinstfiles_available();
    1335                 :          0 :   fsys_hash_init();
    1336                 :          0 :   trig_file_interests_ensure();
    1337                 :            : 
    1338                 :          0 :   printf(_("Preparing to unpack %s ...\n"), pfilename);
    1339                 :            : 
    1340         [ #  # ]:          0 :   if (pkg->status != PKG_STAT_NOTINSTALLED &&
    1341         [ #  # ]:          0 :       pkg->status != PKG_STAT_CONFIGFILES) {
    1342                 :          0 :     log_action("upgrade", pkg, &pkg->installed);
    1343                 :            :   } else {
    1344                 :          0 :     log_action("install", pkg, &pkg->available);
    1345                 :            :   }
    1346                 :            : 
    1347         [ #  # ]:          0 :   if (f_noact) {
    1348                 :          0 :     pop_cleanup(ehflag_normaltidy);
    1349                 :          0 :     return;
    1350                 :            :   }
    1351                 :            : 
    1352                 :            :   /*
    1353                 :            :    * OK, we're going ahead.
    1354                 :            :    */
    1355                 :            : 
    1356                 :          0 :   trig_activate_packageprocessing(pkg);
    1357                 :          0 :   strcpy(cidirrest, TRIGGERSCIFILE);
    1358                 :          0 :   trig_parse_ci(cidir, NULL, trig_cicb_statuschange_activate, pkg, &pkg->available);
    1359                 :            : 
    1360                 :            :   /* Read the conffiles, and copy the hashes across. */
    1361                 :          0 :   newconffiles.head = NULL;
    1362                 :          0 :   newconffiles.tail = &newconffiles.head;
    1363                 :          0 :   push_cleanup(cu_fileslist, ~0, 0);
    1364                 :          0 :   strcpy(cidirrest,CONFFILESFILE);
    1365                 :          0 :   deb_parse_conffiles(pkg, cidir, &newconffiles);
    1366                 :            : 
    1367                 :            :   /* All the old conffiles are marked with a flag, so that we don't delete
    1368                 :            :    * them if they seem to disappear completely. */
    1369                 :          0 :   pkg_conffiles_mark_old(pkg);
    1370                 :          0 :   for (conflictor_iter = conflictors.head;
    1371         [ #  # ]:          0 :        conflictor_iter;
    1372                 :          0 :        conflictor_iter = conflictor_iter->next)
    1373                 :          0 :     pkg_conffiles_mark_old(conflictor_iter->pkg);
    1374                 :            : 
    1375                 :          0 :   oldversionstatus= pkg->status;
    1376                 :            : 
    1377         [ #  # ]:          0 :   if (oldversionstatus > PKG_STAT_INSTALLED)
    1378                 :          0 :     internerr("package %s state %d is out-of-bounds",
    1379                 :            :               pkg_name(pkg, pnaw_always), oldversionstatus);
    1380                 :            : 
    1381                 :          0 :   debug(dbg_general,"process_archive oldversionstatus=%s",
    1382                 :          0 :         statusstrings[oldversionstatus]);
    1383                 :            : 
    1384         [ #  # ]:          0 :   if (oldversionstatus == PKG_STAT_HALFCONFIGURED ||
    1385         [ #  # ]:          0 :       oldversionstatus == PKG_STAT_TRIGGERSAWAITED ||
    1386         [ #  # ]:          0 :       oldversionstatus == PKG_STAT_TRIGGERSPENDING ||
    1387         [ #  # ]:          0 :       oldversionstatus == PKG_STAT_INSTALLED) {
    1388                 :          0 :     pkg_set_eflags(pkg, PKG_EFLAG_REINSTREQ);
    1389                 :          0 :     pkg_set_status(pkg, PKG_STAT_HALFCONFIGURED);
    1390                 :          0 :     modstatdb_note(pkg);
    1391                 :          0 :     push_cleanup(cu_prermupgrade, ~ehflag_normaltidy, 1, (void *)pkg);
    1392                 :          0 :     maintscript_fallback(pkg, PRERMFILE, "pre-removal", cidir, cidirrest,
    1393                 :            :                          "upgrade", "failed-upgrade");
    1394                 :          0 :     pkg_set_status(pkg, PKG_STAT_UNPACKED);
    1395                 :          0 :     oldversionstatus = PKG_STAT_UNPACKED;
    1396                 :          0 :     modstatdb_note(pkg);
    1397                 :            :   }
    1398                 :            : 
    1399                 :          0 :   pkg_deconfigure_others(pkg);
    1400                 :            : 
    1401                 :          0 :   for (conflictor_iter = conflictors.head;
    1402         [ #  # ]:          0 :        conflictor_iter;
    1403                 :          0 :        conflictor_iter = conflictor_iter->next) {
    1404                 :          0 :     struct pkginfo *conflictor = conflictor_iter->pkg;
    1405                 :            : 
    1406         [ #  # ]:          0 :     if (!(conflictor->status == PKG_STAT_HALFCONFIGURED ||
    1407         [ #  # ]:          0 :           conflictor->status == PKG_STAT_TRIGGERSAWAITED ||
    1408         [ #  # ]:          0 :           conflictor->status == PKG_STAT_TRIGGERSPENDING ||
    1409         [ #  # ]:          0 :           conflictor->status == PKG_STAT_INSTALLED))
    1410                 :          0 :       continue;
    1411                 :            : 
    1412                 :          0 :     trig_activate_packageprocessing(conflictor);
    1413                 :          0 :     pkg_set_status(conflictor, PKG_STAT_HALFCONFIGURED);
    1414                 :          0 :     modstatdb_note(conflictor);
    1415                 :          0 :     push_cleanup(cu_prerminfavour, ~ehflag_normaltidy,
    1416                 :            :                  2, conflictor, pkg);
    1417                 :          0 :     maintscript_installed(conflictor, PRERMFILE, "pre-removal",
    1418                 :            :                           "remove", "in-favour",
    1419                 :          0 :                           pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
    1420                 :          0 :                           versiondescribe(&pkg->available.version,
    1421                 :            :                                           vdew_nonambig),
    1422                 :            :                           NULL);
    1423                 :          0 :     pkg_set_status(conflictor, PKG_STAT_HALFINSTALLED);
    1424                 :          0 :     modstatdb_note(conflictor);
    1425                 :            :   }
    1426                 :            : 
    1427                 :          0 :   pkg_set_eflags(pkg, PKG_EFLAG_REINSTREQ);
    1428         [ #  # ]:          0 :   if (pkg->status == PKG_STAT_NOTINSTALLED) {
    1429                 :          0 :     pkg->installed.version= pkg->available.version;
    1430                 :          0 :     pkg->installed.multiarch = pkg->available.multiarch;
    1431                 :            :   }
    1432                 :          0 :   pkg_set_status(pkg, PKG_STAT_HALFINSTALLED);
    1433                 :          0 :   modstatdb_note(pkg);
    1434         [ #  # ]:          0 :   if (oldversionstatus == PKG_STAT_NOTINSTALLED) {
    1435                 :          0 :     push_cleanup(cu_preinstverynew, ~ehflag_normaltidy,
    1436                 :            :                  3,(void*)pkg,(void*)cidir,(void*)cidirrest);
    1437                 :          0 :     maintscript_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest,
    1438                 :            :                     "install", NULL);
    1439         [ #  # ]:          0 :   } else if (oldversionstatus == PKG_STAT_CONFIGFILES) {
    1440                 :          0 :     push_cleanup(cu_preinstnew, ~ehflag_normaltidy,
    1441                 :            :                  3,(void*)pkg,(void*)cidir,(void*)cidirrest);
    1442                 :          0 :     maintscript_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest,
    1443                 :            :                     "install",
    1444                 :          0 :                     versiondescribe(&pkg->installed.version, vdew_nonambig),
    1445                 :          0 :                     versiondescribe(&pkg->available.version, vdew_nonambig),
    1446                 :            :                     NULL);
    1447                 :            :   } else {
    1448                 :          0 :     push_cleanup(cu_preinstupgrade, ~ehflag_normaltidy,
    1449                 :            :                  4,(void*)pkg,(void*)cidir,(void*)cidirrest,(void*)&oldversionstatus);
    1450                 :          0 :     maintscript_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest,
    1451                 :            :                     "upgrade",
    1452                 :          0 :                     versiondescribe(&pkg->installed.version, vdew_nonambig),
    1453                 :          0 :                     versiondescribe(&pkg->available.version, vdew_nonambig),
    1454                 :            :                     NULL);
    1455                 :            :   }
    1456                 :            : 
    1457         [ #  # ]:          0 :   if (oldversionstatus == PKG_STAT_NOTINSTALLED ||
    1458         [ #  # ]:          0 :       oldversionstatus == PKG_STAT_CONFIGFILES) {
    1459                 :          0 :     printf(_("Unpacking %s (%s) ...\n"),
    1460                 :          0 :            pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
    1461                 :          0 :            versiondescribe(&pkg->available.version, vdew_nonambig));
    1462                 :            :   } else {
    1463                 :          0 :     printf(_("Unpacking %s (%s) over (%s) ...\n"),
    1464                 :          0 :            pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
    1465                 :          0 :            versiondescribe(&pkg->available.version, vdew_nonambig),
    1466                 :          0 :            versiondescribe(&pkg->installed.version, vdew_nonambig));
    1467                 :            :   }
    1468                 :            : 
    1469                 :            :   /*
    1470                 :            :    * Now we unpack the archive, backing things up as we go.
    1471                 :            :    * For each file, we check to see if it already exists.
    1472                 :            :    * There are several possibilities:
    1473                 :            :    *
    1474                 :            :    * + We are trying to install a non-directory ...
    1475                 :            :    *  - It doesn't exist. In this case we simply extract it.
    1476                 :            :    *  - It is a plain file, device, symlink, &c. We do an ‘atomic
    1477                 :            :    *    overwrite’ using link() and rename(), but leave a backup copy.
    1478                 :            :    *    Later, when we delete the backup, we remove it from any other
    1479                 :            :    *    packages' lists.
    1480                 :            :    *  - It is a directory. In this case it depends on whether we're
    1481                 :            :    *    trying to install a symlink or something else.
    1482                 :            :    *   = If we're not trying to install a symlink we move the directory
    1483                 :            :    *     aside and extract the node. Later, when we recursively remove
    1484                 :            :    *     the backed-up directory, we remove it from any other packages'
    1485                 :            :    *     lists.
    1486                 :            :    *   = If we are trying to install a symlink we do nothing - ie,
    1487                 :            :    *     dpkg will never replace a directory tree with a symlink. This
    1488                 :            :    *     is to avoid embarrassing effects such as replacing a directory
    1489                 :            :    *     tree with a link to a link to the original directory tree.
    1490                 :            :    * + We are trying to install a directory ...
    1491                 :            :    *  - It doesn't exist. We create it with the appropriate modes.
    1492                 :            :    *  - It exists as a directory or a symlink to one. We do nothing.
    1493                 :            :    *  - It is a plain file or a symlink (other than to a directory).
    1494                 :            :    *    We move it aside and create the directory. Later, when we
    1495                 :            :    *    delete the backup, we remove it from any other packages' lists.
    1496                 :            :    *
    1497                 :            :    *                   Install non-dir   Install symlink   Install dir
    1498                 :            :    *  Exists not               X               X                X
    1499                 :            :    *  File/node/symlink       LXR             LXR              BXR
    1500                 :            :    *  Directory               BXR              -                -
    1501                 :            :    *
    1502                 :            :    *    X: extract file/node/link/directory
    1503                 :            :    *   LX: atomic overwrite leaving backup
    1504                 :            :    *    B: ordinary backup
    1505                 :            :    *    R: later remove from other packages' lists
    1506                 :            :    *    -: do nothing
    1507                 :            :    *
    1508                 :            :    * After we've done this we go through the remaining things in the
    1509                 :            :    * lists of packages we're trying to remove (including the old
    1510                 :            :    * version of the current package). This happens in reverse order,
    1511                 :            :    * so that we process files before the directories (or symlinks-to-
    1512                 :            :    * directories) containing them.
    1513                 :            :    *
    1514                 :            :    * + If the thing is a conffile then we leave it alone for the purge
    1515                 :            :    *   operation.
    1516                 :            :    * + Otherwise, there are several possibilities too:
    1517                 :            :    *  - The listed thing does not exist. We ignore it.
    1518                 :            :    *  - The listed thing is a directory or a symlink to a directory.
    1519                 :            :    *    We delete it only if it isn't listed in any other package.
    1520                 :            :    *  - The listed thing is not a directory, but was part of the package
    1521                 :            :    *    that was upgraded, we check to make sure the files aren't the
    1522                 :            :    *    same ones from the old package by checking dev/inode
    1523                 :            :    *  - The listed thing is not a directory or a symlink to one (ie,
    1524                 :            :    *    it's a plain file, device, pipe, &c, or a symlink to one, or a
    1525                 :            :    *    dangling symlink). We delete it.
    1526                 :            :    *
    1527                 :            :    * The removed packages' list becomes empty (of course, the new
    1528                 :            :    * version of the package we're installing will have a new list,
    1529                 :            :    * which replaces the old version's list).
    1530                 :            :    *
    1531                 :            :    * If at any stage we remove a file from a package's list, and the
    1532                 :            :    * package isn't one we're already processing, and the package's
    1533                 :            :    * list becomes empty as a result, we ‘vanish’ the package. This
    1534                 :            :    * means that we run its postrm with the ‘disappear’ argument, and
    1535                 :            :    * put the package in the ‘not-installed’ state. If it had any
    1536                 :            :    * conffiles, their hashes and ownership will have been transferred
    1537                 :            :    * already, so we just ignore those and forget about them from the
    1538                 :            :    * point of view of the disappearing package.
    1539                 :            :    *
    1540                 :            :    * NOTE THAT THE OLD POSTRM IS RUN AFTER THE NEW PREINST, since the
    1541                 :            :    * files get replaced ‘as we go’.
    1542                 :            :    */
    1543                 :            : 
    1544                 :          0 :   m_pipe(p1);
    1545                 :          0 :   push_cleanup(cu_closepipe, ehflag_bombout, 1, (void *)&p1[0]);
    1546                 :          0 :   pid = subproc_fork();
    1547         [ #  # ]:          0 :   if (pid == 0) {
    1548                 :          0 :     m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
    1549                 :          0 :     execlp(BACKEND, BACKEND, "--fsys-tarfile", filename, NULL);
    1550                 :          0 :     ohshite(_("unable to execute %s (%s)"),
    1551                 :            :             _("package filesystem archive extraction"), BACKEND);
    1552                 :            :   }
    1553                 :          0 :   close(p1[1]);
    1554                 :          0 :   p1[1] = -1;
    1555                 :            : 
    1556                 :          0 :   newfiles_queue.head = NULL;
    1557                 :          0 :   newfiles_queue.tail = &newfiles_queue.head;
    1558                 :          0 :   tc.newfiles_queue = &newfiles_queue;
    1559                 :          0 :   push_cleanup(cu_fileslist, ~0, 0);
    1560                 :          0 :   tc.pkg= pkg;
    1561                 :          0 :   tc.backendpipe= p1[0];
    1562                 :          0 :   tc.pkgset_getting_in_sync = pkgset_getting_in_sync(pkg);
    1563                 :            : 
    1564                 :            :   /* Setup the tar archive. */
    1565                 :          0 :   tar.err = DPKG_ERROR_OBJECT;
    1566                 :          0 :   tar.ctx = &tc;
    1567                 :          0 :   tar.ops = &tf;
    1568                 :            : 
    1569                 :          0 :   rc = tar_extractor(&tar);
    1570         [ #  # ]:          0 :   if (rc)
    1571                 :          0 :     dpkg_error_print(&tar.err,
    1572                 :          0 :                      _("corrupted filesystem tarfile in package archive"));
    1573         [ #  # ]:          0 :   if (fd_skip(p1[0], -1, &err) < 0)
    1574                 :          0 :     ohshit(_("cannot zap possible trailing zeros from dpkg-deb: %s"), err.str);
    1575                 :          0 :   close(p1[0]);
    1576                 :          0 :   p1[0] = -1;
    1577                 :          0 :   subproc_reap(pid, BACKEND " --fsys-tarfile", SUBPROC_NOPIPE);
    1578                 :            : 
    1579                 :          0 :   tar_deferred_extract(newfiles_queue.head, pkg);
    1580                 :            : 
    1581         [ #  # ]:          0 :   if (oldversionstatus == PKG_STAT_HALFINSTALLED ||
    1582         [ #  # ]:          0 :       oldversionstatus == PKG_STAT_UNPACKED) {
    1583                 :            :     /* Packages that were in ‘installed’ and ‘postinstfailed’ have been
    1584                 :            :      * reduced to ‘unpacked’ by now, by the running of the prerm script. */
    1585                 :          0 :     pkg_set_status(pkg, PKG_STAT_HALFINSTALLED);
    1586                 :          0 :     modstatdb_note(pkg);
    1587                 :          0 :     push_cleanup(cu_postrmupgrade, ~ehflag_normaltidy, 1, (void *)pkg);
    1588                 :          0 :     maintscript_fallback(pkg, POSTRMFILE, "post-removal", cidir, cidirrest,
    1589                 :            :                          "upgrade", "failed-upgrade");
    1590                 :            :   }
    1591                 :            : 
    1592                 :            :   /* If anything goes wrong while tidying up it's a bit late to do
    1593                 :            :    * anything about it. However, we don't install the new status
    1594                 :            :    * info yet, so that a future dpkg installation will put everything
    1595                 :            :    * right (we hope).
    1596                 :            :    *
    1597                 :            :    * If something does go wrong later the ‘conflictor’ package will be
    1598                 :            :    * left in the ‘removal_failed’ state. Removing or installing it
    1599                 :            :    * will be impossible if it was required because of the conflict with
    1600                 :            :    * the package we're installing now and (presumably) the dependency
    1601                 :            :    * by other packages. This means that the files it contains in
    1602                 :            :    * common with this package will hang around until we successfully
    1603                 :            :    * get this package installed, after which point we can trust the
    1604                 :            :    * conflicting package's file list, which will have been updated to
    1605                 :            :    * remove any files in this package. */
    1606                 :          0 :   push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
    1607                 :            : 
    1608                 :            :   /* Now we delete all the files that were in the old version of
    1609                 :            :    * the package only, except (old or new) conffiles, which we leave
    1610                 :            :    * alone. */
    1611                 :          0 :   pkg_remove_old_files(pkg, &newfiles_queue, &newconffiles);
    1612                 :            : 
    1613                 :            :   /* OK, now we can write the updated files-in-this package list,
    1614                 :            :    * since we've done away (hopefully) with all the old junk. */
    1615                 :          0 :   write_filelist_except(pkg, &pkg->available, newfiles_queue.head, 0);
    1616                 :            : 
    1617                 :            :   /* Trigger interests may have changed.
    1618                 :            :    * Firstly we go through the old list of interests deleting them.
    1619                 :            :    * Then we go through the new list adding them. */
    1620                 :          0 :   strcpy(cidirrest, TRIGGERSCIFILE);
    1621                 :          0 :   trig_parse_ci(pkg_infodb_get_file(pkg, &pkg->installed, TRIGGERSCIFILE),
    1622                 :          0 :                 trig_cicb_interest_delete, NULL, pkg, &pkg->installed);
    1623                 :          0 :   trig_parse_ci(cidir, trig_cicb_interest_add, NULL, pkg, &pkg->available);
    1624                 :          0 :   trig_file_interests_save();
    1625                 :            : 
    1626                 :            :   /* We also install the new maintainer scripts, and any other
    1627                 :            :    * cruft that may have come along with the package. First
    1628                 :            :    * we go through the existing scripts replacing or removing
    1629                 :            :    * them as appropriate; then we go through the new scripts
    1630                 :            :    * (any that are left) and install them. */
    1631                 :          0 :   debug(dbg_general, "process_archive updating info directory");
    1632                 :          0 :   pkg_infodb_update(pkg, cidir, cidirrest);
    1633                 :            : 
    1634                 :            :   /* We store now the checksums dynamically computed while unpacking. */
    1635                 :          0 :   write_filehash_except(pkg, &pkg->available, newfiles_queue.head, 0);
    1636                 :            : 
    1637                 :            :   /*
    1638                 :            :    * Update the status database.
    1639                 :            :    *
    1640                 :            :    * This involves copying each field across from the ‘available’
    1641                 :            :    * to the ‘installed’ half of the pkg structure.
    1642                 :            :    * For some of the fields we have to do a complicated construction
    1643                 :            :    * operation; for others we can just copy the value.
    1644                 :            :    * We tackle the fields in the order they appear, so that
    1645                 :            :    * we don't miss any out :-).
    1646                 :            :    * At least we don't have to copy any strings that are referred
    1647                 :            :    * to, because these are never modified and never freed.
    1648                 :            :    */
    1649                 :          0 :   pkg_update_fields(pkg, &newconffiles);
    1650                 :            : 
    1651                 :            :   /* In case this was an architecture cross-grade, the in-core pkgset might
    1652                 :            :    * be in an inconsistent state, with two pkginfo entries having the same
    1653                 :            :    * architecture, so let's fix that. Note that this does not lose data,
    1654                 :            :    * as the pkg.available member parsed from the binary should replace the
    1655                 :            :    * to be cleared duplicate in the other instance. */
    1656         [ #  # ]:          0 :   for (otherpkg = &pkg->set->pkg; otherpkg; otherpkg = otherpkg->arch_next) {
    1657         [ #  # ]:          0 :     if (otherpkg == pkg)
    1658                 :          0 :       continue;
    1659         [ #  # ]:          0 :     if (otherpkg->installed.arch != pkg->installed.arch)
    1660                 :          0 :       continue;
    1661                 :            : 
    1662         [ #  # ]:          0 :     if (otherpkg->status != PKG_STAT_NOTINSTALLED)
    1663                 :          0 :       internerr("other package %s instance in state %s instead of not-installed",
    1664                 :            :                 pkg_name(otherpkg, pnaw_always), pkg_status_name(otherpkg));
    1665                 :            : 
    1666                 :          0 :     pkg_blank(otherpkg);
    1667                 :            :   }
    1668                 :            : 
    1669                 :            :   /* Check for disappearing packages:
    1670                 :            :    * We go through all the packages on the system looking for ones
    1671                 :            :    * whose files are entirely part of the one we've just unpacked
    1672                 :            :    * (and which actually *have* some files!).
    1673                 :            :    *
    1674                 :            :    * Any that we find are removed - we run the postrm with ‘disappear’
    1675                 :            :    * as an argument, and remove their info/... files and status info.
    1676                 :            :    * Conffiles are ignored (the new package had better do something
    1677                 :            :    * with them!). */
    1678                 :          0 :   pkg_disappear_others(pkg);
    1679                 :            : 
    1680                 :            :   /* Delete files from any other packages' lists.
    1681                 :            :    * We have to do this before we claim this package is in any
    1682                 :            :    * sane kind of state, as otherwise we might delete by mistake
    1683                 :            :    * a file that we overwrote, when we remove the package which
    1684                 :            :    * had the version we overwrote. To prevent this we make
    1685                 :            :    * sure that we don't claim this package is OK until we
    1686                 :            :    * have claimed ‘ownership’ of all its files. */
    1687                 :          0 :   pkg_remove_files_from_others(pkg, newfiles_queue.head);
    1688                 :            : 
    1689                 :            :   /* Right, the package we've unpacked is now in a reasonable state.
    1690                 :            :    * The only thing that we have left to do with it is remove
    1691                 :            :    * backup files, and we can leave the user to fix that if and when
    1692                 :            :    * it happens (we leave the reinstall required flag, of course). */
    1693                 :          0 :   pkg_set_status(pkg, PKG_STAT_UNPACKED);
    1694                 :          0 :   modstatdb_note(pkg);
    1695                 :            : 
    1696                 :            :   /* Now we delete all the backup files that we made when
    1697                 :            :    * extracting the archive - except for files listed as conffiles
    1698                 :            :    * in the new package.
    1699                 :            :    * This time we count it as an error if something goes wrong.
    1700                 :            :    *
    1701                 :            :    * Note that we don't ever delete things that were in the old
    1702                 :            :    * package as a conffile and don't appear at all in the new.
    1703                 :            :    * They stay recorded as obsolete conffiles and will eventually
    1704                 :            :    * (if not taken over by another package) be forgotten. */
    1705                 :          0 :   pkg_remove_backup_files(pkg, newfiles_queue.head);
    1706                 :            : 
    1707                 :            :   /* OK, we're now fully done with the main package.
    1708                 :            :    * This is quite a nice state, so we don't unwind past here. */
    1709                 :          0 :   pkg_reset_eflags(pkg);
    1710                 :          0 :   modstatdb_note(pkg);
    1711                 :          0 :   push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
    1712                 :            : 
    1713                 :            :   /* Only the removal of the conflictor left to do.
    1714                 :            :    * The files list for the conflictor is still a little inconsistent in-core,
    1715                 :            :    * as we have not yet updated the filename->packages mappings; however,
    1716                 :            :    * the package->filenames mapping is. */
    1717         [ #  # ]:          0 :   while (!pkg_queue_is_empty(&conflictors)) {
    1718                 :          0 :     struct pkginfo *conflictor = pkg_queue_pop(&conflictors);
    1719                 :            : 
    1720                 :            :     /* We need to have the most up-to-date info about which files are
    1721                 :            :      * what ... */
    1722                 :          0 :     ensure_allinstfiles_available();
    1723                 :          0 :     printf(_("Removing %s (%s), to allow configuration of %s (%s) ...\n"),
    1724                 :            :            pkg_name(conflictor, pnaw_nonambig),
    1725                 :          0 :            versiondescribe(&conflictor->installed.version, vdew_nonambig),
    1726                 :            :            pkg_name(pkg, pnaw_nonambig),
    1727                 :          0 :            versiondescribe(&pkg->installed.version, vdew_nonambig));
    1728                 :          0 :     removal_bulk(conflictor);
    1729                 :            :   }
    1730                 :            : 
    1731         [ #  # ]:          0 :   if (cipaction->arg_int == act_install)
    1732                 :          0 :     enqueue_package_mark_seen(pkg);
    1733                 :            : }

Generated by: LCOV version 1.16