LCOV - code coverage report
Current view: top level - src/main - depcon.c (source / functions) Coverage Total Hit
Test: dpkg 1.22.7-3-g89f48 C code coverage Lines: 0.0 % 356 0
Test Date: 2024-07-17 02:53:43 Functions: 0.0 % 8 0
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0.0 % 225 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 :     debug(dbg_depcondetail, "findbreakcyclerecursive %s %s",
     180                 :             :           pkg_name(pkg, pnaw_always), varbuf_str(&str_pkgs));
     181                 :           0 :     varbuf_destroy(&str_pkgs);
     182                 :             :   }
     183                 :           0 :   thislink.pkg= pkg;
     184                 :           0 :   thislink.prev = sofar;
     185                 :           0 :   thislink.possi = NULL;
     186         [ #  # ]:           0 :   for (dep= pkg->installed.depends; dep; dep= dep->next) {
     187   [ #  #  #  # ]:           0 :     if (dep->type != dep_depends && dep->type != dep_predepends) continue;
     188         [ #  # ]:           0 :     for (possi= dep->list; possi; possi= possi->next) {
     189                 :             :       struct deppossi_pkg_iterator *possi_iter;
     190                 :             : 
     191                 :             :       /* Don't find the same cycles again. */
     192         [ #  # ]:           0 :       if (possi->cyclebreak) continue;
     193                 :           0 :       thislink.possi= possi;
     194                 :             : 
     195                 :           0 :       possi_iter = deppossi_pkg_iter_new(possi, wpb_installed);
     196         [ #  # ]:           0 :       while ((pkg_pos = deppossi_pkg_iter_next(possi_iter)))
     197         [ #  # ]:           0 :         if (foundcyclebroken(&thislink, sofar, pkg_pos, possi)) {
     198                 :           0 :           deppossi_pkg_iter_free(possi_iter);
     199                 :           0 :           return true;
     200                 :             :         }
     201                 :           0 :       deppossi_pkg_iter_free(possi_iter);
     202                 :             : 
     203                 :             :       /* Right, now we try all the providers ... */
     204                 :           0 :       for (providelink = possi->ed->depended.installed;
     205         [ #  # ]:           0 :            providelink;
     206                 :           0 :            providelink = providelink->rev_next) {
     207         [ #  # ]:           0 :         if (providelink->up->type != dep_provides) continue;
     208                 :           0 :         provider= providelink->up->up;
     209         [ #  # ]:           0 :         if (provider->clientdata->istobe == PKG_ISTOBE_NORMAL)
     210                 :           0 :           continue;
     211                 :             :         /* We don't break things at ‘provides’ links, so ‘possi’ is
     212                 :             :          * still the one we use. */
     213         [ #  # ]:           0 :         if (foundcyclebroken(&thislink, sofar, provider, possi))
     214                 :           0 :           return true;
     215                 :             :       }
     216                 :             :     }
     217                 :             :   }
     218                 :             :   /* Nope, we didn't find a cycle to break. */
     219                 :           0 :   pkg->clientdata->color = PKG_CYCLE_BLACK;
     220                 :           0 :   return false;
     221                 :             : }
     222                 :             : 
     223                 :             : bool
     224                 :           0 : findbreakcycle(struct pkginfo *pkg)
     225                 :             : {
     226                 :             :   struct pkg_hash_iter *iter;
     227                 :             :   struct pkginfo *tpkg;
     228                 :             : 
     229                 :             :   /* Clear the visited flag of all packages before we traverse them. */
     230                 :           0 :   iter = pkg_hash_iter_new();
     231         [ #  # ]:           0 :   while ((tpkg = pkg_hash_iter_next_pkg(iter))) {
     232                 :           0 :     ensure_package_clientdata(tpkg);
     233                 :           0 :     tpkg->clientdata->color = PKG_CYCLE_WHITE;
     234                 :             :   }
     235                 :           0 :   pkg_hash_iter_free(iter);
     236                 :             : 
     237                 :           0 :   return findbreakcyclerecursive(pkg, NULL);
     238                 :             : }
     239                 :             : 
     240                 :           0 : void describedepcon(struct varbuf *addto, struct dependency *dep) {
     241                 :           0 :   struct varbuf depstr = VARBUF_INIT;
     242                 :             : 
     243                 :           0 :   varbufdependency(&depstr, dep);
     244                 :             : 
     245   [ #  #  #  #  :           0 :   switch (dep->type) {
             #  #  #  # ]
     246                 :           0 :   case dep_depends:
     247                 :           0 :     varbuf_printf(addto, _("%s depends on %s"),
     248                 :             :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     249                 :           0 :     break;
     250                 :           0 :   case dep_predepends:
     251                 :           0 :     varbuf_printf(addto, _("%s pre-depends on %s"),
     252                 :             :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     253                 :           0 :     break;
     254                 :           0 :   case dep_recommends:
     255                 :           0 :     varbuf_printf(addto, _("%s recommends %s"),
     256                 :             :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     257                 :           0 :     break;
     258                 :           0 :   case dep_suggests:
     259                 :           0 :     varbuf_printf(addto, _("%s suggests %s"),
     260                 :             :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     261                 :           0 :     break;
     262                 :           0 :   case dep_breaks:
     263                 :           0 :     varbuf_printf(addto, _("%s breaks %s"),
     264                 :             :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     265                 :           0 :     break;
     266                 :           0 :   case dep_conflicts:
     267                 :           0 :     varbuf_printf(addto, _("%s conflicts with %s"),
     268                 :             :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     269                 :           0 :     break;
     270                 :           0 :   case dep_enhances:
     271                 :           0 :     varbuf_printf(addto, _("%s enhances %s"),
     272                 :             :                   pkg_name(dep->up, pnaw_nonambig), depstr.buf);
     273                 :           0 :     break;
     274                 :           0 :   default:
     275                 :           0 :     internerr("unknown deptype '%d'", dep->type);
     276                 :             :   }
     277                 :             : 
     278                 :           0 :   varbuf_destroy(&depstr);
     279                 :           0 : }
     280                 :             : 
     281                 :             : /*
     282                 :             :  * *whynot must already have been initialized; it need not be
     283                 :             :  * empty though - it will be reset before use.
     284                 :             :  *
     285                 :             :  * If depisok returns false for ‘not OK’ it will contain a description,
     286                 :             :  * newline and NUL terminated, of the reason.
     287                 :             :  *
     288                 :             :  * If depisok returns true it will contain garbage.
     289                 :             :  * allowunconfigd should be non-zero during the ‘Pre-Depends’ checking
     290                 :             :  * before a package is unpacked, when it is sufficient for the package
     291                 :             :  * to be unpacked provided that both the unpacked and previously-configured
     292                 :             :  * versions are acceptable.
     293                 :             :  *
     294                 :             :  * On false return (‘not OK’), *canfixbyremove refers to a package which
     295                 :             :  * if removed (dep_conflicts) or deconfigured (dep_breaks) will fix
     296                 :             :  * the problem. Caller may pass NULL for canfixbyremove and need not
     297                 :             :  * initialize *canfixbyremove.
     298                 :             :  *
     299                 :             :  * On false return (‘not OK’), *canfixbytrigaw refers to a package which
     300                 :             :  * can fix the problem if all the packages listed in Triggers-Awaited have
     301                 :             :  * their triggers processed. Caller may pass NULL for canfixbytrigaw and
     302                 :             :  * need not initialize *canfixbytrigaw.
     303                 :             :  */
     304                 :             : bool
     305                 :           0 : depisok(struct dependency *dep, struct varbuf *whynot,
     306                 :             :         struct pkginfo **canfixbyremove, struct pkginfo **canfixbytrigaw,
     307                 :             :         bool allowunconfigd)
     308                 :             : {
     309                 :             :   struct deppossi *possi;
     310                 :             :   struct deppossi *provider;
     311                 :             :   struct pkginfo *pkg_pos;
     312                 :             : 
     313                 :             :   /* Use this buffer so that when internationalization comes along we
     314                 :             :    * don't have to rewrite the code completely, only redo the sprintf strings
     315                 :             :    * (assuming we have the fancy argument-number-specifiers).
     316                 :             :    * Allow 250x3 for package names, versions, &c, + 250 for ourselves. */
     317                 :             :   char linebuf[1024];
     318                 :             : 
     319         [ #  # ]:           0 :   if (dep->type != dep_depends &&
     320         [ #  # ]:           0 :       dep->type != dep_predepends &&
     321         [ #  # ]:           0 :       dep->type != dep_breaks &&
     322         [ #  # ]:           0 :       dep->type != dep_conflicts &&
     323         [ #  # ]:           0 :       dep->type != dep_recommends &&
     324         [ #  # ]:           0 :       dep->type != dep_suggests &&
     325         [ #  # ]:           0 :       dep->type != dep_enhances)
     326                 :           0 :     internerr("unknown dependency type %d", dep->type);
     327                 :             : 
     328         [ #  # ]:           0 :   if (canfixbyremove)
     329                 :           0 :     *canfixbyremove = NULL;
     330         [ #  # ]:           0 :   if (canfixbytrigaw)
     331                 :           0 :     *canfixbytrigaw = NULL;
     332                 :             : 
     333                 :             :   /* The dependency is always OK if we're trying to remove the depend*ing*
     334                 :             :    * package. */
     335   [ #  #  #  # ]:           0 :   switch (dep->up->clientdata->istobe) {
     336                 :           0 :   case PKG_ISTOBE_REMOVE:
     337                 :             :   case PKG_ISTOBE_DECONFIGURE:
     338                 :           0 :     return true;
     339                 :           0 :   case PKG_ISTOBE_NORMAL:
     340                 :             :     /* Only installed packages can be made dependency problems. */
     341   [ #  #  #  # ]:           0 :     switch (dep->up->status) {
     342                 :           0 :     case PKG_STAT_INSTALLED:
     343                 :             :     case PKG_STAT_TRIGGERSPENDING:
     344                 :             :     case PKG_STAT_TRIGGERSAWAITED:
     345                 :           0 :       break;
     346                 :           0 :     case PKG_STAT_HALFCONFIGURED:
     347                 :             :     case PKG_STAT_UNPACKED:
     348                 :             :     case PKG_STAT_HALFINSTALLED:
     349         [ #  # ]:           0 :       if (dep->type == dep_predepends ||
     350         [ #  # ]:           0 :           dep->type == dep_conflicts ||
     351         [ #  # ]:           0 :           dep->type == dep_breaks)
     352                 :             :         break;
     353                 :             :       /* Fall through. */
     354                 :             :     case PKG_STAT_CONFIGFILES:
     355                 :             :     case PKG_STAT_NOTINSTALLED:
     356                 :           0 :       return true;
     357                 :           0 :     default:
     358                 :           0 :       internerr("unknown status depending '%d'", dep->up->status);
     359                 :             :     }
     360                 :           0 :     break;
     361                 :           0 :   case PKG_ISTOBE_INSTALLNEW:
     362                 :             :   case PKG_ISTOBE_PREINSTALL:
     363                 :           0 :     break;
     364                 :           0 :   default:
     365                 :           0 :     internerr("unknown istobe depending '%d'", dep->up->clientdata->istobe);
     366                 :             :   }
     367                 :             : 
     368                 :             :   /* Describe the dependency, in case we have to moan about it. */
     369                 :           0 :   varbuf_reset(whynot);
     370                 :           0 :   varbuf_add_char(whynot, ' ');
     371                 :           0 :   describedepcon(whynot, dep);
     372                 :           0 :   varbuf_add_char(whynot, '\n');
     373                 :             : 
     374                 :             :   /* TODO: Check dep_enhances as well. */
     375   [ #  #  #  # ]:           0 :   if (dep->type == dep_depends || dep->type == dep_predepends ||
     376   [ #  #  #  # ]:           0 :       dep->type == dep_recommends || dep->type == dep_suggests ) {
     377                 :             :     /* Go through the alternatives. As soon as we find one that
     378                 :             :      * we like, we return ‘true’ straight away. Otherwise, when we get to
     379                 :             :      * the end we'll have accumulated all the reasons in whynot and
     380                 :             :      * can return ‘false’. */
     381                 :             : 
     382         [ #  # ]:           0 :     for (possi= dep->list; possi; possi= possi->next) {
     383                 :             :       struct deppossi_pkg_iterator *possi_iter;
     384                 :             : 
     385                 :           0 :       possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
     386         [ #  # ]:           0 :       while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
     387   [ #  #  #  #  :           0 :         switch (pkg_pos->clientdata->istobe) {
                      # ]
     388                 :           0 :         case PKG_ISTOBE_REMOVE:
     389                 :           0 :           sprintf(linebuf, _("  %.250s is to be removed.\n"),
     390                 :             :                   pkg_name(pkg_pos, pnaw_nonambig));
     391                 :           0 :           break;
     392                 :           0 :         case PKG_ISTOBE_DECONFIGURE:
     393                 :           0 :           sprintf(linebuf, _("  %.250s is to be deconfigured.\n"),
     394                 :             :                   pkg_name(pkg_pos, pnaw_nonambig));
     395                 :           0 :           break;
     396                 :           0 :         case PKG_ISTOBE_INSTALLNEW:
     397         [ #  # ]:           0 :           if (versionsatisfied(&pkg_pos->available, possi)) {
     398                 :           0 :             deppossi_pkg_iter_free(possi_iter);
     399                 :           0 :             return true;
     400                 :             :           }
     401                 :           0 :           sprintf(linebuf, _("  %.250s is to be installed, but is version "
     402                 :             :                              "%.250s.\n"),
     403                 :             :                   pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
     404                 :           0 :                   versiondescribe(&pkg_pos->available.version, vdew_nonambig));
     405                 :           0 :           break;
     406                 :           0 :         case PKG_ISTOBE_NORMAL:
     407                 :             :         case PKG_ISTOBE_PREINSTALL:
     408   [ #  #  #  #  :           0 :           switch (pkg_pos->status) {
                      # ]
     409                 :           0 :           case PKG_STAT_INSTALLED:
     410                 :             :           case PKG_STAT_TRIGGERSPENDING:
     411         [ #  # ]:           0 :             if (versionsatisfied(&pkg_pos->installed, possi)) {
     412                 :           0 :               deppossi_pkg_iter_free(possi_iter);
     413                 :           0 :               return true;
     414                 :             :             }
     415                 :           0 :             sprintf(linebuf, _("  %.250s is installed, but is version "
     416                 :             :                                "%.250s.\n"),
     417                 :             :                     pkg_name(pkg_pos, pnaw_nonambig),
     418                 :           0 :                     versiondescribe(&pkg_pos->installed.version, vdew_nonambig));
     419                 :           0 :             break;
     420                 :           0 :           case PKG_STAT_NOTINSTALLED:
     421                 :             :             /* Don't say anything about this yet - it might be a virtual package.
     422                 :             :              * Later on, if nothing has put anything in linebuf, we know that it
     423                 :             :              * isn't and issue a diagnostic then. */
     424                 :           0 :             *linebuf = '\0';
     425                 :           0 :             break;
     426                 :           0 :           case PKG_STAT_TRIGGERSAWAITED:
     427   [ #  #  #  # ]:           0 :               if (canfixbytrigaw && versionsatisfied(&pkg_pos->installed, possi))
     428                 :           0 :                 *canfixbytrigaw = pkg_pos;
     429                 :             :               /* Fall through. */
     430                 :             :           case PKG_STAT_UNPACKED:
     431                 :             :           case PKG_STAT_HALFCONFIGURED:
     432         [ #  # ]:           0 :             if (allowunconfigd) {
     433         [ #  # ]:           0 :               if (!dpkg_version_is_informative(&pkg_pos->configversion)) {
     434                 :           0 :                 sprintf(linebuf, _("  %.250s is unpacked, but has never been "
     435                 :             :                                    "configured.\n"),
     436                 :             :                         pkg_name(pkg_pos, pnaw_nonambig));
     437                 :           0 :                 break;
     438         [ #  # ]:           0 :               } else if (!versionsatisfied(&pkg_pos->installed, possi)) {
     439                 :           0 :                 sprintf(linebuf, _("  %.250s is unpacked, but is version "
     440                 :             :                                    "%.250s.\n"),
     441                 :             :                         pkg_name(pkg_pos, pnaw_nonambig),
     442                 :           0 :                         versiondescribe(&pkg_pos->installed.version,
     443                 :             :                                         vdew_nonambig));
     444                 :           0 :                 break;
     445         [ #  # ]:           0 :               } else if (!dpkg_version_relate(&pkg_pos->configversion,
     446                 :             :                                               possi->verrel,
     447                 :           0 :                                               &possi->version)) {
     448                 :           0 :                 sprintf(linebuf, _("  %.250s latest configured version is "
     449                 :             :                                    "%.250s.\n"),
     450                 :             :                         pkg_name(pkg_pos, pnaw_nonambig),
     451                 :           0 :                         versiondescribe(&pkg_pos->configversion, vdew_nonambig));
     452                 :           0 :                 break;
     453                 :             :               } else {
     454                 :           0 :                 deppossi_pkg_iter_free(possi_iter);
     455                 :           0 :                 return true;
     456                 :             :               }
     457                 :             :             }
     458                 :             :             /* Fall through. */
     459                 :             :           default:
     460                 :           0 :             sprintf(linebuf, _("  %.250s is %s.\n"),
     461                 :             :                     pkg_name(pkg_pos, pnaw_nonambig),
     462                 :           0 :                     gettext(statusstrings[pkg_pos->status]));
     463                 :           0 :             break;
     464                 :             :           }
     465                 :           0 :           break;
     466                 :           0 :         default:
     467                 :           0 :           internerr("unknown istobe depended '%d'", pkg_pos->clientdata->istobe);
     468                 :             :         }
     469                 :           0 :         varbuf_add_str(whynot, linebuf);
     470                 :             :       }
     471                 :           0 :       deppossi_pkg_iter_free(possi_iter);
     472                 :             : 
     473                 :             :         /* See if the package we're about to install Provides it. */
     474                 :           0 :         for (provider = possi->ed->depended.available;
     475         [ #  # ]:           0 :              provider;
     476                 :           0 :              provider = provider->rev_next) {
     477         [ #  # ]:           0 :           if (provider->up->type != dep_provides) continue;
     478         [ #  # ]:           0 :           if (!pkg_virtual_deppossi_satisfied(possi, provider))
     479                 :           0 :             continue;
     480         [ #  # ]:           0 :           if (provider->up->up->clientdata->istobe == PKG_ISTOBE_INSTALLNEW)
     481                 :           0 :             return true;
     482                 :             :         }
     483                 :             : 
     484                 :             :         /* Now look at the packages already on the system. */
     485                 :           0 :         for (provider = possi->ed->depended.installed;
     486         [ #  # ]:           0 :              provider;
     487                 :           0 :              provider = provider->rev_next) {
     488         [ #  # ]:           0 :           if (provider->up->type != dep_provides) continue;
     489         [ #  # ]:           0 :           if (!pkg_virtual_deppossi_satisfied(possi, provider))
     490                 :           0 :             continue;
     491                 :             : 
     492   [ #  #  #  #  :           0 :           switch (provider->up->up->clientdata->istobe) {
                      # ]
     493                 :           0 :           case PKG_ISTOBE_INSTALLNEW:
     494                 :             :             /* Don't pay any attention to the Provides field of the
     495                 :             :              * currently-installed version of the package we're trying
     496                 :             :              * to install. We dealt with that by using the available
     497                 :             :              * information above. */
     498                 :           0 :             continue;
     499                 :           0 :           case PKG_ISTOBE_REMOVE:
     500                 :           0 :             sprintf(linebuf, _("  %.250s provides %.250s but is to be removed.\n"),
     501                 :           0 :                     pkg_name(provider->up->up, pnaw_nonambig),
     502                 :           0 :                     possi->ed->name);
     503                 :           0 :             break;
     504                 :           0 :           case PKG_ISTOBE_DECONFIGURE:
     505                 :           0 :             sprintf(linebuf, _("  %.250s provides %.250s but is to be deconfigured.\n"),
     506                 :           0 :                     pkg_name(provider->up->up, pnaw_nonambig),
     507                 :           0 :                     possi->ed->name);
     508                 :           0 :             break;
     509                 :           0 :           case PKG_ISTOBE_NORMAL:
     510                 :             :           case PKG_ISTOBE_PREINSTALL:
     511         [ #  # ]:           0 :             if (provider->up->up->status == PKG_STAT_INSTALLED ||
     512         [ #  # ]:           0 :                 provider->up->up->status == PKG_STAT_TRIGGERSPENDING)
     513                 :           0 :               return true;
     514         [ #  # ]:           0 :             if (provider->up->up->status == PKG_STAT_TRIGGERSAWAITED)
     515                 :           0 :               *canfixbytrigaw = provider->up->up;
     516                 :           0 :             sprintf(linebuf, _("  %.250s provides %.250s but is %s.\n"),
     517                 :           0 :                     pkg_name(provider->up->up, pnaw_nonambig),
     518                 :           0 :                     possi->ed->name,
     519                 :           0 :                     gettext(statusstrings[provider->up->up->status]));
     520                 :           0 :             break;
     521                 :           0 :           default:
     522                 :           0 :             internerr("unknown istobe provider '%d'",
     523                 :             :                       provider->up->up->clientdata->istobe);
     524                 :             :           }
     525                 :           0 :           varbuf_add_str(whynot, linebuf);
     526                 :             :         }
     527                 :             : 
     528         [ #  # ]:           0 :         if (!*linebuf) {
     529                 :             :           /* If the package wasn't installed at all, and we haven't said
     530                 :             :            * yet why this isn't satisfied, we should say so now. */
     531                 :           0 :           sprintf(linebuf, _("  %.250s is not installed.\n"), possi->ed->name);
     532                 :           0 :           varbuf_add_str(whynot, linebuf);
     533                 :             :         }
     534                 :             :     }
     535                 :             : 
     536                 :           0 :     return false;
     537                 :             :   } else {
     538                 :             :     int nconflicts;
     539                 :             : 
     540                 :             :     /* It's conflicts or breaks. There's only one main alternative,
     541                 :             :      * but we also have to consider Providers. We return ‘false’ as soon
     542                 :             :      * as we find something that matches the conflict, and only describe
     543                 :             :      * it then. If we get to the end without finding anything we return
     544                 :             :      * ‘true’. */
     545                 :             : 
     546                 :           0 :     possi= dep->list;
     547                 :           0 :     nconflicts= 0;
     548                 :             : 
     549         [ #  # ]:           0 :     if (possi->ed != possi->up->up->set) {
     550                 :             :       struct deppossi_pkg_iterator *possi_iter;
     551                 :             : 
     552                 :             :       /* If the package conflicts with or breaks itself it must mean
     553                 :             :        * other packages which provide the same virtual name. We
     554                 :             :        * therefore don't look at the real package and go on to the
     555                 :             :        * virtual ones. */
     556                 :             : 
     557                 :           0 :       possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
     558         [ #  # ]:           0 :       while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
     559   [ #  #  #  #  :           0 :         switch (pkg_pos->clientdata->istobe) {
                      # ]
     560                 :           0 :         case PKG_ISTOBE_REMOVE:
     561                 :           0 :           break;
     562                 :           0 :         case PKG_ISTOBE_INSTALLNEW:
     563         [ #  # ]:           0 :           if (!versionsatisfied(&pkg_pos->available, possi))
     564                 :           0 :             break;
     565                 :           0 :           sprintf(linebuf, _("  %.250s (version %.250s) is to be installed.\n"),
     566                 :             :                   pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
     567                 :           0 :                   versiondescribe(&pkg_pos->available.version, vdew_nonambig));
     568                 :           0 :           varbuf_add_str(whynot, linebuf);
     569         [ #  # ]:           0 :           if (!canfixbyremove) {
     570                 :           0 :             deppossi_pkg_iter_free(possi_iter);
     571                 :           0 :             return false;
     572                 :             :           }
     573                 :           0 :           nconflicts++;
     574                 :           0 :           *canfixbyremove = pkg_pos;
     575                 :           0 :           break;
     576                 :           0 :         case PKG_ISTOBE_DECONFIGURE:
     577         [ #  # ]:           0 :           if (dep->type == dep_breaks)
     578                 :           0 :             break; /* Already deconfiguring this. */
     579                 :             :           /* Fall through. */
     580                 :             :         case PKG_ISTOBE_NORMAL:
     581                 :             :         case PKG_ISTOBE_PREINSTALL:
     582   [ #  #  #  # ]:           0 :           switch (pkg_pos->status) {
     583                 :           0 :           case PKG_STAT_NOTINSTALLED:
     584                 :             :           case PKG_STAT_CONFIGFILES:
     585                 :           0 :             break;
     586                 :           0 :           case PKG_STAT_HALFINSTALLED:
     587                 :             :           case PKG_STAT_UNPACKED:
     588                 :             :           case PKG_STAT_HALFCONFIGURED:
     589         [ #  # ]:           0 :             if (dep->type == dep_breaks)
     590                 :           0 :               break; /* No problem. */
     591                 :             :             /* Fall through. */
     592                 :             :           case PKG_STAT_INSTALLED:
     593                 :             :           case PKG_STAT_TRIGGERSPENDING:
     594                 :             :           case PKG_STAT_TRIGGERSAWAITED:
     595         [ #  # ]:           0 :             if (!versionsatisfied(&pkg_pos->installed, possi))
     596                 :           0 :               break;
     597                 :           0 :             sprintf(linebuf, _("  %.250s (version %.250s) is present and %s.\n"),
     598                 :             :                     pkg_name(pkg_pos, pnaw_nonambig),
     599                 :           0 :                     versiondescribe(&pkg_pos->installed.version, vdew_nonambig),
     600                 :           0 :                     gettext(statusstrings[pkg_pos->status]));
     601                 :           0 :             varbuf_add_str(whynot, linebuf);
     602         [ #  # ]:           0 :             if (!canfixbyremove) {
     603                 :           0 :               deppossi_pkg_iter_free(possi_iter);
     604                 :           0 :               return false;
     605                 :             :             }
     606                 :           0 :             nconflicts++;
     607                 :           0 :             *canfixbyremove = pkg_pos;
     608                 :             :           }
     609                 :           0 :           break;
     610                 :           0 :         default:
     611                 :           0 :           internerr("unknown istobe conflict '%d'", pkg_pos->clientdata->istobe);
     612                 :             :         }
     613                 :             :       }
     614                 :           0 :       deppossi_pkg_iter_free(possi_iter);
     615                 :             :     }
     616                 :             : 
     617                 :             :       /* See if the package we're about to install Provides it. */
     618                 :           0 :       for (provider = possi->ed->depended.available;
     619         [ #  # ]:           0 :            provider;
     620                 :           0 :            provider = provider->rev_next) {
     621         [ #  # ]:           0 :         if (provider->up->type != dep_provides) continue;
     622         [ #  # ]:           0 :         if (provider->up->up->clientdata->istobe != PKG_ISTOBE_INSTALLNEW)
     623                 :           0 :           continue;
     624         [ #  # ]:           0 :         if (provider->up->up->set == dep->up->set)
     625                 :           0 :           continue; /* Conflicts and provides the same. */
     626         [ #  # ]:           0 :         if (!pkg_virtual_deppossi_satisfied(possi, provider))
     627                 :           0 :           continue;
     628                 :           0 :         sprintf(linebuf, _("  %.250s provides %.250s and is to be installed.\n"),
     629                 :           0 :                 pkgbin_name(provider->up->up, &provider->up->up->available,
     630                 :           0 :                             pnaw_nonambig), possi->ed->name);
     631                 :           0 :         varbuf_add_str(whynot, linebuf);
     632                 :             :         /* We can't remove the one we're about to install: */
     633         [ #  # ]:           0 :         if (canfixbyremove)
     634                 :           0 :           *canfixbyremove = NULL;
     635                 :           0 :         return false;
     636                 :             :       }
     637                 :             : 
     638                 :             :       /* Now look at the packages already on the system. */
     639                 :           0 :       for (provider = possi->ed->depended.installed;
     640         [ #  # ]:           0 :            provider;
     641                 :           0 :            provider = provider->rev_next) {
     642         [ #  # ]:           0 :         if (provider->up->type != dep_provides) continue;
     643                 :             : 
     644         [ #  # ]:           0 :         if (provider->up->up->set == dep->up->set)
     645                 :           0 :           continue; /* Conflicts and provides the same. */
     646                 :             : 
     647         [ #  # ]:           0 :         if (!pkg_virtual_deppossi_satisfied(possi, provider))
     648                 :           0 :           continue;
     649                 :             : 
     650   [ #  #  #  #  :           0 :         switch (provider->up->up->clientdata->istobe) {
                      # ]
     651                 :           0 :         case PKG_ISTOBE_INSTALLNEW:
     652                 :             :           /* Don't pay any attention to the Provides field of the
     653                 :             :            * currently-installed version of the package we're trying
     654                 :             :            * to install. We dealt with that package by using the
     655                 :             :            * available information above. */
     656                 :           0 :           continue;
     657                 :           0 :         case PKG_ISTOBE_REMOVE:
     658                 :           0 :           continue;
     659                 :           0 :         case PKG_ISTOBE_DECONFIGURE:
     660         [ #  # ]:           0 :           if (dep->type == dep_breaks)
     661                 :           0 :             continue; /* Already deconfiguring. */
     662                 :             :           /* Fall through. */
     663                 :             :         case PKG_ISTOBE_NORMAL:
     664                 :             :         case PKG_ISTOBE_PREINSTALL:
     665   [ #  #  #  # ]:           0 :           switch (provider->up->up->status) {
     666                 :           0 :           case PKG_STAT_NOTINSTALLED:
     667                 :             :           case PKG_STAT_CONFIGFILES:
     668                 :           0 :             continue;
     669                 :           0 :           case PKG_STAT_HALFINSTALLED:
     670                 :             :           case PKG_STAT_UNPACKED:
     671                 :             :           case PKG_STAT_HALFCONFIGURED:
     672         [ #  # ]:           0 :             if (dep->type == dep_breaks)
     673                 :           0 :               break; /* No problem. */
     674                 :             :             /* Fall through. */
     675                 :             :           case PKG_STAT_INSTALLED:
     676                 :             :           case PKG_STAT_TRIGGERSPENDING:
     677                 :             :           case PKG_STAT_TRIGGERSAWAITED:
     678                 :           0 :             sprintf(linebuf,
     679                 :           0 :                     _("  %.250s provides %.250s and is present and %s.\n"),
     680                 :           0 :                     pkg_name(provider->up->up, pnaw_nonambig), possi->ed->name,
     681                 :           0 :                     gettext(statusstrings[provider->up->up->status]));
     682                 :           0 :             varbuf_add_str(whynot, linebuf);
     683         [ #  # ]:           0 :             if (!canfixbyremove)
     684                 :           0 :               return false;
     685                 :           0 :             nconflicts++;
     686                 :           0 :             *canfixbyremove= provider->up->up;
     687                 :           0 :             break;
     688                 :             :           }
     689                 :           0 :           break;
     690                 :           0 :         default:
     691                 :           0 :           internerr("unknown istobe conflict provider '%d'",
     692                 :             :                     provider->up->up->clientdata->istobe);
     693                 :             :         }
     694                 :             :       }
     695                 :             : 
     696         [ #  # ]:           0 :     if (!nconflicts)
     697                 :           0 :       return true;
     698         [ #  # ]:           0 :     if (nconflicts > 1)
     699                 :           0 :       *canfixbyremove = NULL;
     700                 :           0 :     return false;
     701                 :             : 
     702                 :             :   } /* if (dependency) {...} else {...} */
     703                 :             : }
        

Generated by: LCOV version 2.0-1