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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * dpkg - main program for package management
       3                 :            :  * depcon.c - dependency and conflict checking
       4                 :            :  *
       5                 :            :  * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
       6                 :            :  * Copyright © 2006-2014 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                 :            : 
      30                 :            : #include <errno.h>
      31                 :            : #include <stdlib.h>
      32                 :            : #include <unistd.h>
      33                 :            : 
      34                 :            : #include <dpkg/i18n.h>
      35                 :            : #include <dpkg/dpkg.h>
      36                 :            : #include <dpkg/dpkg-db.h>
      37                 :            : #include <dpkg/db-ctrl.h>
      38                 :            : #include <dpkg/db-fsys.h>
      39                 :            : 
      40                 :            : #include "main.h"
      41                 :            : 
      42                 :            : struct deppossi_pkg_iterator {
      43                 :            :   struct deppossi *possi;
      44                 :            :   struct pkginfo *pkg_next;
      45                 :            :   enum which_pkgbin which_pkgbin;
      46                 :            : };
      47                 :            : 
      48                 :            : struct deppossi_pkg_iterator *
      49                 :          0 : deppossi_pkg_iter_new(struct deppossi *possi, enum which_pkgbin wpb)
      50                 :            : {
      51                 :            :   struct deppossi_pkg_iterator *iter;
      52                 :            : 
      53                 :          0 :   iter = m_malloc(sizeof(*iter));
      54                 :          0 :   iter->possi = possi;
      55                 :          0 :   iter->pkg_next = &possi->ed->pkg;
      56                 :          0 :   iter->which_pkgbin = wpb;
      57                 :            : 
      58                 :          0 :   return iter;
      59                 :            : }
      60                 :            : 
      61                 :            : struct pkginfo *
      62                 :          0 : deppossi_pkg_iter_next(struct deppossi_pkg_iterator *iter)
      63                 :            : {
      64                 :            :   struct pkginfo *pkg_cur;
      65                 :            :   struct pkgbin *pkgbin;
      66                 :            : 
      67         [ #  # ]:          0 :   while ((pkg_cur = iter->pkg_next)) {
      68                 :          0 :     iter->pkg_next = pkg_cur->arch_next;
      69                 :            : 
      70   [ #  #  #  # ]:          0 :     switch (iter->which_pkgbin) {
      71                 :          0 :     case wpb_installed:
      72                 :          0 :       pkgbin = &pkg_cur->installed;
      73                 :          0 :       break;
      74                 :          0 :     case wpb_available:
      75                 :          0 :       pkgbin = &pkg_cur->available;
      76                 :          0 :       break;
      77                 :          0 :     case wpb_by_istobe:
      78         [ #  # ]:          0 :       if (pkg_cur->clientdata &&
      79         [ #  # ]:          0 :           pkg_cur->clientdata->istobe == PKG_ISTOBE_INSTALLNEW)
      80                 :          0 :         pkgbin = &pkg_cur->available;
      81                 :            :       else
      82                 :          0 :         pkgbin = &pkg_cur->installed;
      83                 :          0 :       break;
      84                 :          0 :     default:
      85                 :          0 :       internerr("unknown which_pkgbin %d", iter->which_pkgbin);
      86                 :            :     }
      87                 :            : 
      88         [ #  # ]:          0 :     if (archsatisfied(pkgbin, iter->possi))
      89                 :          0 :       return pkg_cur;
      90                 :            :   }
      91                 :            : 
      92                 :          0 :   return NULL;
      93                 :            : }
      94                 :            : 
      95                 :            : void
      96                 :          0 : deppossi_pkg_iter_free(struct deppossi_pkg_iterator *iter)
      97                 :            : {
      98                 :          0 :   free(iter);
      99                 :          0 : }
     100                 :            : 
     101                 :            : struct cyclesofarlink {
     102                 :            :   struct cyclesofarlink *prev;
     103                 :            :   struct pkginfo *pkg;
     104                 :            :   struct deppossi *possi;
     105                 :            : };
     106                 :            : 
     107                 :            : static bool findbreakcyclerecursive(struct pkginfo *pkg,
     108                 :            :                                     struct cyclesofarlink *sofar);
     109                 :            : 
     110                 :            : static bool
     111                 :          0 : foundcyclebroken(struct cyclesofarlink *thislink, struct cyclesofarlink *sofar,
     112                 :            :                  struct pkginfo *dependedon, struct deppossi *possi)
     113                 :            : {
     114                 :            :   struct cyclesofarlink *sol;
     115                 :            : 
     116         [ #  # ]:          0 :   if(!possi)
     117                 :          0 :     return false;
     118                 :            : 
     119                 :            :   /* We're investigating the dependency ‘possi’ to see if it
     120                 :            :    * is part of a loop. To this end we look to see whether the
     121                 :            :    * depended-on package is already one of the packages whose
     122                 :            :    * dependencies we're searching. */
     123   [ #  #  #  # ]:          0 :   for (sol = sofar; sol && sol->pkg != dependedon; sol = sol->prev);
     124                 :            : 
     125                 :            :   /* If not, we do a recursive search on it to see what we find. */
     126         [ #  # ]:          0 :   if (!sol)
     127                 :          0 :     return findbreakcyclerecursive(dependedon, thislink);
     128                 :            : 
     129                 :          0 :   debug(dbg_depcon,"found cycle");
     130                 :            :   /* Right, we now break one of the links. We prefer to break
     131                 :            :    * a dependency of a package without a postinst script, as
     132                 :            :    * this is a null operation. If this is not possible we break
     133                 :            :    * the other link in the recursive calling tree which mentions
     134                 :            :    * this package (this being the first package involved in the
     135                 :            :    * cycle). It doesn't particularly matter which we pick, but if
     136                 :            :    * we break the earliest dependency we came across we may be
     137                 :            :    * able to do something straight away when findbreakcycle returns. */
     138                 :          0 :   sofar= thislink;
     139   [ #  #  #  # ]:          0 :   for (sol = sofar; !(sol != sofar && sol->pkg == dependedon); sol = sol->prev) {
     140         [ #  # ]:          0 :     if (!pkg_infodb_has_file(sol->pkg, &sol->pkg->installed, POSTINSTFILE))
     141                 :          0 :       break;
     142                 :            :   }
     143                 :            : 
     144                 :            :   /* Now we have either a package with no postinst, or the other
     145                 :            :    * occurrence of the current package in the list. */
     146                 :          0 :   sol->possi->cyclebreak = true;
     147                 :            : 
     148                 :          0 :   debug(dbg_depcon, "cycle broken at %s -> %s",
     149                 :          0 :         pkg_name(sol->possi->up->up, pnaw_always), sol->possi->ed->name);
     150                 :            : 
     151                 :          0 :   return true;
     152                 :            : }
     153                 :            : 
     154                 :            : /**
     155                 :            :  * Cycle breaking works recursively down the package dependency tree.
     156                 :            :  *
     157                 :            :  * ‘sofar’ is the list of packages we've descended down already - if we
     158                 :            :  * encounter any of its packages again in a dependency we have found a cycle.
     159                 :            :  */
     160                 :            : static bool
     161                 :          0 : findbreakcyclerecursive(struct pkginfo *pkg, struct cyclesofarlink *sofar)
     162                 :            : {
     163                 :            :   struct cyclesofarlink thislink, *sol;
     164                 :            :   struct dependency *dep;
     165                 :            :   struct deppossi *possi, *providelink;
     166                 :            :   struct pkginfo *provider, *pkg_pos;
     167                 :            : 
     168         [ #  # ]:          0 :   if (pkg->clientdata->color == PKG_CYCLE_BLACK)
     169                 :          0 :     return false;
     170                 :          0 :   pkg->clientdata->color = PKG_CYCLE_GRAY;
     171                 :            : 
     172         [ #  # ]:          0 :   if (debug_has_flag(dbg_depcondetail)) {
     173                 :          0 :     struct varbuf str_pkgs = VARBUF_INIT;
     174                 :            : 
     175         [ #  # ]:          0 :     for (sol = sofar; sol; sol = sol->prev) {
     176                 :          0 :       varbuf_add_str(&str_pkgs, " <- ");
     177                 :          0 :       varbuf_add_pkgbin_name(&str_pkgs, sol->pkg, &sol->pkg->installed, pnaw_nonambig);
     178                 :            :     }
     179                 :          0 :     varbuf_end_str(&str_pkgs);
     180                 :          0 :     debug(dbg_depcondetail, "findbreakcyclerecursive %s %s",
     181                 :            :           pkg_name(pkg, pnaw_always), str_pkgs.buf);
     182                 :          0 :     varbuf_destroy(&str_pkgs);
     183                 :            :   }
     184                 :          0 :   thislink.pkg= pkg;
     185                 :          0 :   thislink.prev = sofar;
     186                 :          0 :   thislink.possi = NULL;
     187         [ #  # ]:          0 :   for (dep= pkg->installed.depends; dep; dep= dep->next) {
     188   [ #  #  #  # ]:          0 :     if (dep->type != dep_depends && dep->type != dep_predepends) continue;
     189         [ #  # ]:          0 :     for (possi= dep->list; possi; possi= possi->next) {
     190                 :            :       struct deppossi_pkg_iterator *possi_iter;
     191                 :            : 
     192                 :            :       /* Don't find the same cycles again. */
     193         [ #  # ]:          0 :       if (possi->cyclebreak) continue;
     194                 :          0 :       thislink.possi= possi;
     195                 :            : 
     196                 :          0 :       possi_iter = deppossi_pkg_iter_new(possi, wpb_installed);
     197         [ #  # ]:          0 :       while ((pkg_pos = deppossi_pkg_iter_next(possi_iter)))
     198         [ #  # ]:          0 :         if (foundcyclebroken(&thislink, sofar, pkg_pos, possi)) {
     199                 :          0 :           deppossi_pkg_iter_free(possi_iter);
     200                 :          0 :           return true;
     201                 :            :         }
     202                 :          0 :       deppossi_pkg_iter_free(possi_iter);
     203                 :            : 
     204                 :            :       /* Right, now we try all the providers ... */
     205                 :          0 :       for (providelink = possi->ed->depended.installed;
     206         [ #  # ]:          0 :            providelink;
     207                 :          0 :            providelink = providelink->rev_next) {
     208         [ #  # ]:          0 :         if (providelink->up->type != dep_provides) continue;
     209                 :          0 :         provider= providelink->up->up;
     210         [ #  # ]:          0 :         if (provider->clientdata->istobe == PKG_ISTOBE_NORMAL)
     211                 :          0 :           continue;
     212                 :            :         /* We don't break things at ‘provides’ links, so ‘possi’ is
     213                 :            :          * still the one we use. */
     214         [ #  # ]:          0 :         if (foundcyclebroken(&thislink, sofar, provider, possi))
     215                 :          0 :           return true;
     216                 :            :       }
     217                 :            :     }
     218                 :            :   }
     219                 :            :   /* Nope, we didn't find a cycle to break. */
     220                 :          0 :   pkg->clientdata->color = PKG_CYCLE_BLACK;
     221                 :          0 :   return false;
     222                 :            : }
     223                 :            : 
     224                 :            : bool
     225                 :          0 : findbreakcycle(struct pkginfo *pkg)
     226                 :            : {
     227                 :            :   struct pkg_hash_iter *iter;
     228                 :            :   struct pkginfo *tpkg;
     229                 :            : 
     230                 :            :   /* Clear the visited flag of all packages before we traverse them. */
     231                 :          0 :   iter = pkg_hash_iter_new();
     232         [ #  # ]:          0 :   while ((tpkg = pkg_hash_iter_next_pkg(iter))) {
     233                 :          0 :     ensure_package_clientdata(tpkg);
     234                 :          0 :     tpkg->clientdata->color = PKG_CYCLE_WHITE;
     235                 :            :   }
     236                 :          0 :   pkg_hash_iter_free(iter);
     237                 :            : 
     238                 :          0 :   return findbreakcyclerecursive(pkg, NULL);
     239                 :            : }
     240                 :            : 
     241                 :          0 : void describedepcon(struct varbuf *addto, struct dependency *dep) {
     242                 :          0 :   struct varbuf depstr = VARBUF_INIT;
     243                 :            : 
     244                 :          0 :   varbufdependency(&depstr, dep);
     245                 :          0 :   varbuf_end_str(&depstr);
     246                 :            : 
     247   [ #  #  #  #  :          0 :   switch (dep->type) {
             #  #  #  # ]
     248                 :          0 :   case dep_depends:
     249                 :          0 :     varbuf_printf(addto, _("%s depends on %s"),
     250                 :            :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     251                 :          0 :     break;
     252                 :          0 :   case dep_predepends:
     253                 :          0 :     varbuf_printf(addto, _("%s pre-depends on %s"),
     254                 :            :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     255                 :          0 :     break;
     256                 :          0 :   case dep_recommends:
     257                 :          0 :     varbuf_printf(addto, _("%s recommends %s"),
     258                 :            :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     259                 :          0 :     break;
     260                 :          0 :   case dep_suggests:
     261                 :          0 :     varbuf_printf(addto, _("%s suggests %s"),
     262                 :            :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     263                 :          0 :     break;
     264                 :          0 :   case dep_breaks:
     265                 :          0 :     varbuf_printf(addto, _("%s breaks %s"),
     266                 :            :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     267                 :          0 :     break;
     268                 :          0 :   case dep_conflicts:
     269                 :          0 :     varbuf_printf(addto, _("%s conflicts with %s"),
     270                 :            :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     271                 :          0 :     break;
     272                 :          0 :   case dep_enhances:
     273                 :          0 :     varbuf_printf(addto, _("%s enhances %s"),
     274                 :            :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     275                 :          0 :     break;
     276                 :          0 :   default:
     277                 :          0 :     internerr("unknown deptype '%d'", dep->type);
     278                 :            :   }
     279                 :            : 
     280                 :          0 :   varbuf_destroy(&depstr);
     281                 :          0 : }
     282                 :            : 
     283                 :            : /*
     284                 :            :  * *whynot must already have been initialized; it need not be
     285                 :            :  * empty though - it will be reset before use.
     286                 :            :  *
     287                 :            :  * If depisok returns false for ‘not OK’ it will contain a description,
     288                 :            :  * newline-terminated BUT NOT NUL-TERMINATED, of the reason.
     289                 :            :  *
     290                 :            :  * If depisok returns true it will contain garbage.
     291                 :            :  * allowunconfigd should be non-zero during the ‘Pre-Depends’ checking
     292                 :            :  * before a package is unpacked, when it is sufficient for the package
     293                 :            :  * to be unpacked provided that both the unpacked and previously-configured
     294                 :            :  * versions are acceptable.
     295                 :            :  *
     296                 :            :  * On false return (‘not OK’), *canfixbyremove refers to a package which
     297                 :            :  * if removed (dep_conflicts) or deconfigured (dep_breaks) will fix
     298                 :            :  * the problem. Caller may pass NULL for canfixbyremove and need not
     299                 :            :  * initialize *canfixbyremove.
     300                 :            :  *
     301                 :            :  * On false return (‘not OK’), *canfixbytrigaw refers to a package which
     302                 :            :  * can fix the problem if all the packages listed in Triggers-Awaited have
     303                 :            :  * their triggers processed. Caller may pass NULL for canfixbytrigaw and
     304                 :            :  * need not initialize *canfixbytrigaw.
     305                 :            :  */
     306                 :            : bool
     307                 :          0 : depisok(struct dependency *dep, struct varbuf *whynot,
     308                 :            :         struct pkginfo **canfixbyremove, struct pkginfo **canfixbytrigaw,
     309                 :            :         bool allowunconfigd)
     310                 :            : {
     311                 :            :   struct deppossi *possi;
     312                 :            :   struct deppossi *provider;
     313                 :            :   struct pkginfo *pkg_pos;
     314                 :            :   int nconflicts;
     315                 :            : 
     316                 :            :   /* Use this buffer so that when internationalization comes along we
     317                 :            :    * don't have to rewrite the code completely, only redo the sprintf strings
     318                 :            :    * (assuming we have the fancy argument-number-specifiers).
     319                 :            :    * Allow 250x3 for package names, versions, &c, + 250 for ourselves. */
     320                 :            :   char linebuf[1024];
     321                 :            : 
     322         [ #  # ]:          0 :   if (dep->type != dep_depends &&
     323         [ #  # ]:          0 :       dep->type != dep_predepends &&
     324         [ #  # ]:          0 :       dep->type != dep_breaks &&
     325         [ #  # ]:          0 :       dep->type != dep_conflicts &&
     326         [ #  # ]:          0 :       dep->type != dep_recommends &&
     327         [ #  # ]:          0 :       dep->type != dep_suggests &&
     328         [ #  # ]:          0 :       dep->type != dep_enhances)
     329                 :          0 :     internerr("unknown dependency type %d", dep->type);
     330                 :            : 
     331         [ #  # ]:          0 :   if (canfixbyremove)
     332                 :          0 :     *canfixbyremove = NULL;
     333         [ #  # ]:          0 :   if (canfixbytrigaw)
     334                 :          0 :     *canfixbytrigaw = NULL;
     335                 :            : 
     336                 :            :   /* The dependency is always OK if we're trying to remove the depend*ing*
     337                 :            :    * package. */
     338   [ #  #  #  # ]:          0 :   switch (dep->up->clientdata->istobe) {
     339                 :          0 :   case PKG_ISTOBE_REMOVE:
     340                 :            :   case PKG_ISTOBE_DECONFIGURE:
     341                 :          0 :     return true;
     342                 :          0 :   case PKG_ISTOBE_NORMAL:
     343                 :            :     /* Only installed packages can be made dependency problems. */
     344   [ #  #  #  # ]:          0 :     switch (dep->up->status) {
     345                 :          0 :     case PKG_STAT_INSTALLED:
     346                 :            :     case PKG_STAT_TRIGGERSPENDING:
     347                 :            :     case PKG_STAT_TRIGGERSAWAITED:
     348                 :          0 :       break;
     349                 :          0 :     case PKG_STAT_HALFCONFIGURED:
     350                 :            :     case PKG_STAT_UNPACKED:
     351                 :            :     case PKG_STAT_HALFINSTALLED:
     352         [ #  # ]:          0 :       if (dep->type == dep_predepends ||
     353         [ #  # ]:          0 :           dep->type == dep_conflicts ||
     354         [ #  # ]:          0 :           dep->type == dep_breaks)
     355                 :            :         break;
     356                 :            :       /* Fall through. */
     357                 :            :     case PKG_STAT_CONFIGFILES:
     358                 :            :     case PKG_STAT_NOTINSTALLED:
     359                 :          0 :       return true;
     360                 :          0 :     default:
     361                 :          0 :       internerr("unknown status depending '%d'", dep->up->status);
     362                 :            :     }
     363                 :          0 :     break;
     364                 :          0 :   case PKG_ISTOBE_INSTALLNEW:
     365                 :            :   case PKG_ISTOBE_PREINSTALL:
     366                 :          0 :     break;
     367                 :          0 :   default:
     368                 :          0 :     internerr("unknown istobe depending '%d'", dep->up->clientdata->istobe);
     369                 :            :   }
     370                 :            : 
     371                 :            :   /* Describe the dependency, in case we have to moan about it. */
     372                 :          0 :   varbuf_reset(whynot);
     373                 :          0 :   varbuf_add_char(whynot, ' ');
     374                 :          0 :   describedepcon(whynot, dep);
     375                 :          0 :   varbuf_add_char(whynot, '\n');
     376                 :            : 
     377                 :            :   /* TODO: Check dep_enhances as well. */
     378   [ #  #  #  # ]:          0 :   if (dep->type == dep_depends || dep->type == dep_predepends ||
     379   [ #  #  #  # ]:          0 :       dep->type == dep_recommends || dep->type == dep_suggests ) {
     380                 :            :     /* Go through the alternatives. As soon as we find one that
     381                 :            :      * we like, we return ‘true’ straight away. Otherwise, when we get to
     382                 :            :      * the end we'll have accumulated all the reasons in whynot and
     383                 :            :      * can return ‘false’. */
     384                 :            : 
     385         [ #  # ]:          0 :     for (possi= dep->list; possi; possi= possi->next) {
     386                 :            :       struct deppossi_pkg_iterator *possi_iter;
     387                 :            : 
     388                 :          0 :       possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
     389         [ #  # ]:          0 :       while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
     390   [ #  #  #  #  :          0 :         switch (pkg_pos->clientdata->istobe) {
                      # ]
     391                 :          0 :         case PKG_ISTOBE_REMOVE:
     392                 :          0 :           sprintf(linebuf, _("  %.250s is to be removed.\n"),
     393                 :            :                   pkg_name(pkg_pos, pnaw_nonambig));
     394                 :          0 :           break;
     395                 :          0 :         case PKG_ISTOBE_DECONFIGURE:
     396                 :          0 :           sprintf(linebuf, _("  %.250s is to be deconfigured.\n"),
     397                 :            :                   pkg_name(pkg_pos, pnaw_nonambig));
     398                 :          0 :           break;
     399                 :          0 :         case PKG_ISTOBE_INSTALLNEW:
     400         [ #  # ]:          0 :           if (versionsatisfied(&pkg_pos->available, possi)) {
     401                 :          0 :             deppossi_pkg_iter_free(possi_iter);
     402                 :          0 :             return true;
     403                 :            :           }
     404                 :          0 :           sprintf(linebuf, _("  %.250s is to be installed, but is version "
     405                 :            :                              "%.250s.\n"),
     406                 :            :                   pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
     407                 :          0 :                   versiondescribe(&pkg_pos->available.version, vdew_nonambig));
     408                 :          0 :           break;
     409                 :          0 :         case PKG_ISTOBE_NORMAL:
     410                 :            :         case PKG_ISTOBE_PREINSTALL:
     411   [ #  #  #  #  :          0 :           switch (pkg_pos->status) {
                      # ]
     412                 :          0 :           case PKG_STAT_INSTALLED:
     413                 :            :           case PKG_STAT_TRIGGERSPENDING:
     414         [ #  # ]:          0 :             if (versionsatisfied(&pkg_pos->installed, possi)) {
     415                 :          0 :               deppossi_pkg_iter_free(possi_iter);
     416                 :          0 :               return true;
     417                 :            :             }
     418                 :          0 :             sprintf(linebuf, _("  %.250s is installed, but is version "
     419                 :            :                                "%.250s.\n"),
     420                 :            :                     pkg_name(pkg_pos, pnaw_nonambig),
     421                 :          0 :                     versiondescribe(&pkg_pos->installed.version, vdew_nonambig));
     422                 :          0 :             break;
     423                 :          0 :           case PKG_STAT_NOTINSTALLED:
     424                 :            :             /* Don't say anything about this yet - it might be a virtual package.
     425                 :            :              * Later on, if nothing has put anything in linebuf, we know that it
     426                 :            :              * isn't and issue a diagnostic then. */
     427                 :          0 :             *linebuf = '\0';
     428                 :          0 :             break;
     429                 :          0 :           case PKG_STAT_TRIGGERSAWAITED:
     430   [ #  #  #  # ]:          0 :               if (canfixbytrigaw && versionsatisfied(&pkg_pos->installed, possi))
     431                 :          0 :                 *canfixbytrigaw = pkg_pos;
     432                 :            :               /* Fall through. */
     433                 :            :           case PKG_STAT_UNPACKED:
     434                 :            :           case PKG_STAT_HALFCONFIGURED:
     435         [ #  # ]:          0 :             if (allowunconfigd) {
     436         [ #  # ]:          0 :               if (!dpkg_version_is_informative(&pkg_pos->configversion)) {
     437                 :          0 :                 sprintf(linebuf, _("  %.250s is unpacked, but has never been "
     438                 :            :                                    "configured.\n"),
     439                 :            :                         pkg_name(pkg_pos, pnaw_nonambig));
     440                 :          0 :                 break;
     441         [ #  # ]:          0 :               } else if (!versionsatisfied(&pkg_pos->installed, possi)) {
     442                 :          0 :                 sprintf(linebuf, _("  %.250s is unpacked, but is version "
     443                 :            :                                    "%.250s.\n"),
     444                 :            :                         pkg_name(pkg_pos, pnaw_nonambig),
     445                 :          0 :                         versiondescribe(&pkg_pos->installed.version,
     446                 :            :                                         vdew_nonambig));
     447                 :          0 :                 break;
     448         [ #  # ]:          0 :               } else if (!dpkg_version_relate(&pkg_pos->configversion,
     449                 :            :                                               possi->verrel,
     450                 :          0 :                                               &possi->version)) {
     451                 :          0 :                 sprintf(linebuf, _("  %.250s latest configured version is "
     452                 :            :                                    "%.250s.\n"),
     453                 :            :                         pkg_name(pkg_pos, pnaw_nonambig),
     454                 :          0 :                         versiondescribe(&pkg_pos->configversion, vdew_nonambig));
     455                 :          0 :                 break;
     456                 :            :               } else {
     457                 :          0 :                 deppossi_pkg_iter_free(possi_iter);
     458                 :          0 :                 return true;
     459                 :            :               }
     460                 :            :             }
     461                 :            :             /* Fall through. */
     462                 :            :           default:
     463                 :          0 :             sprintf(linebuf, _("  %.250s is %s.\n"),
     464                 :            :                     pkg_name(pkg_pos, pnaw_nonambig),
     465                 :          0 :                     gettext(statusstrings[pkg_pos->status]));
     466                 :          0 :             break;
     467                 :            :           }
     468                 :          0 :           break;
     469                 :          0 :         default:
     470                 :          0 :           internerr("unknown istobe depended '%d'", pkg_pos->clientdata->istobe);
     471                 :            :         }
     472                 :          0 :         varbuf_add_str(whynot, linebuf);
     473                 :            :       }
     474                 :          0 :       deppossi_pkg_iter_free(possi_iter);
     475                 :            : 
     476                 :            :         /* See if the package we're about to install Provides it. */
     477                 :          0 :         for (provider = possi->ed->depended.available;
     478         [ #  # ]:          0 :              provider;
     479                 :          0 :              provider = provider->rev_next) {
     480         [ #  # ]:          0 :           if (provider->up->type != dep_provides) continue;
     481         [ #  # ]:          0 :           if (!pkg_virtual_deppossi_satisfied(possi, provider))
     482                 :          0 :             continue;
     483         [ #  # ]:          0 :           if (provider->up->up->clientdata->istobe == PKG_ISTOBE_INSTALLNEW)
     484                 :          0 :             return true;
     485                 :            :         }
     486                 :            : 
     487                 :            :         /* Now look at the packages already on the system. */
     488                 :          0 :         for (provider = possi->ed->depended.installed;
     489         [ #  # ]:          0 :              provider;
     490                 :          0 :              provider = provider->rev_next) {
     491         [ #  # ]:          0 :           if (provider->up->type != dep_provides) continue;
     492         [ #  # ]:          0 :           if (!pkg_virtual_deppossi_satisfied(possi, provider))
     493                 :          0 :             continue;
     494                 :            : 
     495   [ #  #  #  #  :          0 :           switch (provider->up->up->clientdata->istobe) {
                      # ]
     496                 :          0 :           case PKG_ISTOBE_INSTALLNEW:
     497                 :            :             /* Don't pay any attention to the Provides field of the
     498                 :            :              * currently-installed version of the package we're trying
     499                 :            :              * to install. We dealt with that by using the available
     500                 :            :              * information above. */
     501                 :          0 :             continue;
     502                 :          0 :           case PKG_ISTOBE_REMOVE:
     503                 :          0 :             sprintf(linebuf, _("  %.250s provides %.250s but is to be removed.\n"),
     504                 :          0 :                     pkg_name(provider->up->up, pnaw_nonambig),
     505                 :          0 :                     possi->ed->name);
     506                 :          0 :             break;
     507                 :          0 :           case PKG_ISTOBE_DECONFIGURE:
     508                 :          0 :             sprintf(linebuf, _("  %.250s provides %.250s but is to be deconfigured.\n"),
     509                 :          0 :                     pkg_name(provider->up->up, pnaw_nonambig),
     510                 :          0 :                     possi->ed->name);
     511                 :          0 :             break;
     512                 :          0 :           case PKG_ISTOBE_NORMAL:
     513                 :            :           case PKG_ISTOBE_PREINSTALL:
     514         [ #  # ]:          0 :             if (provider->up->up->status == PKG_STAT_INSTALLED ||
     515         [ #  # ]:          0 :                 provider->up->up->status == PKG_STAT_TRIGGERSPENDING)
     516                 :          0 :               return true;
     517         [ #  # ]:          0 :             if (provider->up->up->status == PKG_STAT_TRIGGERSAWAITED)
     518                 :          0 :               *canfixbytrigaw = provider->up->up;
     519                 :          0 :             sprintf(linebuf, _("  %.250s provides %.250s but is %s.\n"),
     520                 :          0 :                     pkg_name(provider->up->up, pnaw_nonambig),
     521                 :          0 :                     possi->ed->name,
     522                 :          0 :                     gettext(statusstrings[provider->up->up->status]));
     523                 :          0 :             break;
     524                 :          0 :           default:
     525                 :          0 :             internerr("unknown istobe provider '%d'",
     526                 :            :                       provider->up->up->clientdata->istobe);
     527                 :            :           }
     528                 :          0 :           varbuf_add_str(whynot, linebuf);
     529                 :            :         }
     530                 :            : 
     531         [ #  # ]:          0 :         if (!*linebuf) {
     532                 :            :           /* If the package wasn't installed at all, and we haven't said
     533                 :            :            * yet why this isn't satisfied, we should say so now. */
     534                 :          0 :           sprintf(linebuf, _("  %.250s is not installed.\n"), possi->ed->name);
     535                 :          0 :           varbuf_add_str(whynot, linebuf);
     536                 :            :         }
     537                 :            :     }
     538                 :            : 
     539                 :          0 :     return false;
     540                 :            :   } else {
     541                 :            :     /* It's conflicts or breaks. There's only one main alternative,
     542                 :            :      * but we also have to consider Providers. We return ‘false’ as soon
     543                 :            :      * as we find something that matches the conflict, and only describe
     544                 :            :      * it then. If we get to the end without finding anything we return
     545                 :            :      * ‘true’. */
     546                 :            : 
     547                 :          0 :     possi= dep->list;
     548                 :          0 :     nconflicts= 0;
     549                 :            : 
     550         [ #  # ]:          0 :     if (possi->ed != possi->up->up->set) {
     551                 :            :       struct deppossi_pkg_iterator *possi_iter;
     552                 :            : 
     553                 :            :       /* If the package conflicts with or breaks itself it must mean
     554                 :            :        * other packages which provide the same virtual name. We
     555                 :            :        * therefore don't look at the real package and go on to the
     556                 :            :        * virtual ones. */
     557                 :            : 
     558                 :          0 :       possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
     559         [ #  # ]:          0 :       while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
     560   [ #  #  #  #  :          0 :         switch (pkg_pos->clientdata->istobe) {
                      # ]
     561                 :          0 :         case PKG_ISTOBE_REMOVE:
     562                 :          0 :           break;
     563                 :          0 :         case PKG_ISTOBE_INSTALLNEW:
     564         [ #  # ]:          0 :           if (!versionsatisfied(&pkg_pos->available, possi))
     565                 :          0 :             break;
     566                 :          0 :           sprintf(linebuf, _("  %.250s (version %.250s) is to be installed.\n"),
     567                 :            :                   pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
     568                 :          0 :                   versiondescribe(&pkg_pos->available.version, vdew_nonambig));
     569                 :          0 :           varbuf_add_str(whynot, linebuf);
     570         [ #  # ]:          0 :           if (!canfixbyremove) {
     571                 :          0 :             deppossi_pkg_iter_free(possi_iter);
     572                 :          0 :             return false;
     573                 :            :           }
     574                 :          0 :           nconflicts++;
     575                 :          0 :           *canfixbyremove = pkg_pos;
     576                 :          0 :           break;
     577                 :          0 :         case PKG_ISTOBE_DECONFIGURE:
     578         [ #  # ]:          0 :           if (dep->type == dep_breaks)
     579                 :          0 :             break; /* Already deconfiguring this. */
     580                 :            :           /* Fall through. */
     581                 :            :         case PKG_ISTOBE_NORMAL:
     582                 :            :         case PKG_ISTOBE_PREINSTALL:
     583   [ #  #  #  # ]:          0 :           switch (pkg_pos->status) {
     584                 :          0 :           case PKG_STAT_NOTINSTALLED:
     585                 :            :           case PKG_STAT_CONFIGFILES:
     586                 :          0 :             break;
     587                 :          0 :           case PKG_STAT_HALFINSTALLED:
     588                 :            :           case PKG_STAT_UNPACKED:
     589                 :            :           case PKG_STAT_HALFCONFIGURED:
     590         [ #  # ]:          0 :             if (dep->type == dep_breaks)
     591                 :          0 :               break; /* No problem. */
     592                 :            :             /* Fall through. */
     593                 :            :           case PKG_STAT_INSTALLED:
     594                 :            :           case PKG_STAT_TRIGGERSPENDING:
     595                 :            :           case PKG_STAT_TRIGGERSAWAITED:
     596         [ #  # ]:          0 :             if (!versionsatisfied(&pkg_pos->installed, possi))
     597                 :          0 :               break;
     598                 :          0 :             sprintf(linebuf, _("  %.250s (version %.250s) is present and %s.\n"),
     599                 :            :                     pkg_name(pkg_pos, pnaw_nonambig),
     600                 :          0 :                     versiondescribe(&pkg_pos->installed.version, vdew_nonambig),
     601                 :          0 :                     gettext(statusstrings[pkg_pos->status]));
     602                 :          0 :             varbuf_add_str(whynot, linebuf);
     603         [ #  # ]:          0 :             if (!canfixbyremove) {
     604                 :          0 :               deppossi_pkg_iter_free(possi_iter);
     605                 :          0 :               return false;
     606                 :            :             }
     607                 :          0 :             nconflicts++;
     608                 :          0 :             *canfixbyremove = pkg_pos;
     609                 :            :           }
     610                 :          0 :           break;
     611                 :          0 :         default:
     612                 :          0 :           internerr("unknown istobe conflict '%d'", pkg_pos->clientdata->istobe);
     613                 :            :         }
     614                 :            :       }
     615                 :          0 :       deppossi_pkg_iter_free(possi_iter);
     616                 :            :     }
     617                 :            : 
     618                 :            :       /* See if the package we're about to install Provides it. */
     619                 :          0 :       for (provider = possi->ed->depended.available;
     620         [ #  # ]:          0 :            provider;
     621                 :          0 :            provider = provider->rev_next) {
     622         [ #  # ]:          0 :         if (provider->up->type != dep_provides) continue;
     623         [ #  # ]:          0 :         if (provider->up->up->clientdata->istobe != PKG_ISTOBE_INSTALLNEW)
     624                 :          0 :           continue;
     625         [ #  # ]:          0 :         if (provider->up->up->set == dep->up->set)
     626                 :          0 :           continue; /* Conflicts and provides the same. */
     627         [ #  # ]:          0 :         if (!pkg_virtual_deppossi_satisfied(possi, provider))
     628                 :          0 :           continue;
     629                 :          0 :         sprintf(linebuf, _("  %.250s provides %.250s and is to be installed.\n"),
     630                 :          0 :                 pkgbin_name(provider->up->up, &provider->up->up->available,
     631                 :          0 :                             pnaw_nonambig), possi->ed->name);
     632                 :          0 :         varbuf_add_str(whynot, linebuf);
     633                 :            :         /* We can't remove the one we're about to install: */
     634         [ #  # ]:          0 :         if (canfixbyremove)
     635                 :          0 :           *canfixbyremove = NULL;
     636                 :          0 :         return false;
     637                 :            :       }
     638                 :            : 
     639                 :            :       /* Now look at the packages already on the system. */
     640                 :          0 :       for (provider = possi->ed->depended.installed;
     641         [ #  # ]:          0 :            provider;
     642                 :          0 :            provider = provider->rev_next) {
     643         [ #  # ]:          0 :         if (provider->up->type != dep_provides) continue;
     644                 :            : 
     645         [ #  # ]:          0 :         if (provider->up->up->set == dep->up->set)
     646                 :          0 :           continue; /* Conflicts and provides the same. */
     647                 :            : 
     648         [ #  # ]:          0 :         if (!pkg_virtual_deppossi_satisfied(possi, provider))
     649                 :          0 :           continue;
     650                 :            : 
     651   [ #  #  #  #  :          0 :         switch (provider->up->up->clientdata->istobe) {
                      # ]
     652                 :          0 :         case PKG_ISTOBE_INSTALLNEW:
     653                 :            :           /* Don't pay any attention to the Provides field of the
     654                 :            :            * currently-installed version of the package we're trying
     655                 :            :            * to install. We dealt with that package by using the
     656                 :            :            * available information above. */
     657                 :          0 :           continue;
     658                 :          0 :         case PKG_ISTOBE_REMOVE:
     659                 :          0 :           continue;
     660                 :          0 :         case PKG_ISTOBE_DECONFIGURE:
     661         [ #  # ]:          0 :           if (dep->type == dep_breaks)
     662                 :          0 :             continue; /* Already deconfiguring. */
     663                 :            :           /* Fall through. */
     664                 :            :         case PKG_ISTOBE_NORMAL:
     665                 :            :         case PKG_ISTOBE_PREINSTALL:
     666   [ #  #  #  # ]:          0 :           switch (provider->up->up->status) {
     667                 :          0 :           case PKG_STAT_NOTINSTALLED:
     668                 :            :           case PKG_STAT_CONFIGFILES:
     669                 :          0 :             continue;
     670                 :          0 :           case PKG_STAT_HALFINSTALLED:
     671                 :            :           case PKG_STAT_UNPACKED:
     672                 :            :           case PKG_STAT_HALFCONFIGURED:
     673         [ #  # ]:          0 :             if (dep->type == dep_breaks)
     674                 :          0 :               break; /* No problem. */
     675                 :            :             /* Fall through. */
     676                 :            :           case PKG_STAT_INSTALLED:
     677                 :            :           case PKG_STAT_TRIGGERSPENDING:
     678                 :            :           case PKG_STAT_TRIGGERSAWAITED:
     679                 :          0 :             sprintf(linebuf,
     680                 :          0 :                     _("  %.250s provides %.250s and is present and %s.\n"),
     681                 :          0 :                     pkg_name(provider->up->up, pnaw_nonambig), possi->ed->name,
     682                 :          0 :                     gettext(statusstrings[provider->up->up->status]));
     683                 :          0 :             varbuf_add_str(whynot, linebuf);
     684         [ #  # ]:          0 :             if (!canfixbyremove)
     685                 :          0 :               return false;
     686                 :          0 :             nconflicts++;
     687                 :          0 :             *canfixbyremove= provider->up->up;
     688                 :          0 :             break;
     689                 :            :           }
     690                 :          0 :           break;
     691                 :          0 :         default:
     692                 :          0 :           internerr("unknown istobe conflict provider '%d'",
     693                 :            :                     provider->up->up->clientdata->istobe);
     694                 :            :         }
     695                 :            :       }
     696                 :            : 
     697         [ #  # ]:          0 :     if (!nconflicts)
     698                 :          0 :       return true;
     699         [ #  # ]:          0 :     if (nconflicts > 1)
     700                 :          0 :       *canfixbyremove = NULL;
     701                 :          0 :     return false;
     702                 :            : 
     703                 :            :   } /* if (dependency) {...} else {...} */
     704                 :            : }

Generated by: LCOV version 1.16