libdpkg: Deindent an else clause
[dpkg.git] / src / main / depcon.c
blobe8efdd3bec00b70d38f4919d6e577bc1f5a9adc9
1 /*
2 * dpkg - main program for package management
3 * depcon.c - dependency and conflict checking
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>
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.
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.
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/>.
24 #include <config.h>
25 #include <compat.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
30 #include <errno.h>
31 #include <stdlib.h>
32 #include <unistd.h>
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>
40 #include "main.h"
42 struct deppossi_pkg_iterator {
43 struct deppossi *possi;
44 struct pkginfo *pkg_next;
45 enum which_pkgbin which_pkgbin;
48 struct deppossi_pkg_iterator *
49 deppossi_pkg_iter_new(struct deppossi *possi, enum which_pkgbin wpb)
51 struct deppossi_pkg_iterator *iter;
53 iter = m_malloc(sizeof(*iter));
54 iter->possi = possi;
55 iter->pkg_next = &possi->ed->pkg;
56 iter->which_pkgbin = wpb;
58 return iter;
61 struct pkginfo *
62 deppossi_pkg_iter_next(struct deppossi_pkg_iterator *iter)
64 struct pkginfo *pkg_cur;
65 struct pkgbin *pkgbin;
67 while ((pkg_cur = iter->pkg_next)) {
68 iter->pkg_next = pkg_cur->arch_next;
70 switch (iter->which_pkgbin) {
71 case wpb_installed:
72 pkgbin = &pkg_cur->installed;
73 break;
74 case wpb_available:
75 pkgbin = &pkg_cur->available;
76 break;
77 case wpb_by_istobe:
78 if (pkg_cur->clientdata &&
79 pkg_cur->clientdata->istobe == PKG_ISTOBE_INSTALLNEW)
80 pkgbin = &pkg_cur->available;
81 else
82 pkgbin = &pkg_cur->installed;
83 break;
84 default:
85 internerr("unknown which_pkgbin %d", iter->which_pkgbin);
88 if (archsatisfied(pkgbin, iter->possi))
89 return pkg_cur;
92 return NULL;
95 void
96 deppossi_pkg_iter_free(struct deppossi_pkg_iterator *iter)
98 free(iter);
101 struct cyclesofarlink {
102 struct cyclesofarlink *prev;
103 struct pkginfo *pkg;
104 struct deppossi *possi;
107 static bool findbreakcyclerecursive(struct pkginfo *pkg,
108 struct cyclesofarlink *sofar);
110 static bool
111 foundcyclebroken(struct cyclesofarlink *thislink, struct cyclesofarlink *sofar,
112 struct pkginfo *dependedon, struct deppossi *possi)
114 struct cyclesofarlink *sol;
116 if(!possi)
117 return false;
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 for (sol = sofar; sol && sol->pkg != dependedon; sol = sol->prev);
125 /* If not, we do a recursive search on it to see what we find. */
126 if (!sol)
127 return findbreakcyclerecursive(dependedon, thislink);
129 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 sofar= thislink;
139 for (sol = sofar; !(sol != sofar && sol->pkg == dependedon); sol = sol->prev) {
140 if (!pkg_infodb_has_file(sol->pkg, &sol->pkg->installed, POSTINSTFILE))
141 break;
144 /* Now we have either a package with no postinst, or the other
145 * occurrence of the current package in the list. */
146 sol->possi->cyclebreak = true;
148 debug(dbg_depcon, "cycle broken at %s -> %s",
149 pkg_name(sol->possi->up->up, pnaw_always), sol->possi->ed->name);
151 return true;
155 * Cycle breaking works recursively down the package dependency tree.
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.
160 static bool
161 findbreakcyclerecursive(struct pkginfo *pkg, struct cyclesofarlink *sofar)
163 struct cyclesofarlink thislink, *sol;
164 struct dependency *dep;
165 struct deppossi *possi, *providelink;
166 struct pkginfo *provider, *pkg_pos;
168 if (pkg->clientdata->color == PKG_CYCLE_BLACK)
169 return false;
170 pkg->clientdata->color = PKG_CYCLE_GRAY;
172 if (debug_has_flag(dbg_depcondetail)) {
173 struct varbuf str_pkgs = VARBUF_INIT;
175 for (sol = sofar; sol; sol = sol->prev) {
176 varbuf_add_str(&str_pkgs, " <- ");
177 varbuf_add_pkgbin_name(&str_pkgs, sol->pkg, &sol->pkg->installed, pnaw_nonambig);
179 varbuf_end_str(&str_pkgs);
180 debug(dbg_depcondetail, "findbreakcyclerecursive %s %s",
181 pkg_name(pkg, pnaw_always), str_pkgs.buf);
182 varbuf_destroy(&str_pkgs);
184 thislink.pkg= pkg;
185 thislink.prev = sofar;
186 thislink.possi = NULL;
187 for (dep= pkg->installed.depends; dep; dep= dep->next) {
188 if (dep->type != dep_depends && dep->type != dep_predepends) continue;
189 for (possi= dep->list; possi; possi= possi->next) {
190 struct deppossi_pkg_iterator *possi_iter;
192 /* Don't find the same cycles again. */
193 if (possi->cyclebreak) continue;
194 thislink.possi= possi;
196 possi_iter = deppossi_pkg_iter_new(possi, wpb_installed);
197 while ((pkg_pos = deppossi_pkg_iter_next(possi_iter)))
198 if (foundcyclebroken(&thislink, sofar, pkg_pos, possi)) {
199 deppossi_pkg_iter_free(possi_iter);
200 return true;
202 deppossi_pkg_iter_free(possi_iter);
204 /* Right, now we try all the providers ... */
205 for (providelink = possi->ed->depended.installed;
206 providelink;
207 providelink = providelink->rev_next) {
208 if (providelink->up->type != dep_provides) continue;
209 provider= providelink->up->up;
210 if (provider->clientdata->istobe == PKG_ISTOBE_NORMAL)
211 continue;
212 /* We don't break things at ‘provides’ links, so ‘possi’ is
213 * still the one we use. */
214 if (foundcyclebroken(&thislink, sofar, provider, possi))
215 return true;
219 /* Nope, we didn't find a cycle to break. */
220 pkg->clientdata->color = PKG_CYCLE_BLACK;
221 return false;
224 bool
225 findbreakcycle(struct pkginfo *pkg)
227 struct pkg_hash_iter *iter;
228 struct pkginfo *tpkg;
230 /* Clear the visited flag of all packages before we traverse them. */
231 iter = pkg_hash_iter_new();
232 while ((tpkg = pkg_hash_iter_next_pkg(iter))) {
233 ensure_package_clientdata(tpkg);
234 tpkg->clientdata->color = PKG_CYCLE_WHITE;
236 pkg_hash_iter_free(iter);
238 return findbreakcyclerecursive(pkg, NULL);
241 void describedepcon(struct varbuf *addto, struct dependency *dep) {
242 struct varbuf depstr = VARBUF_INIT;
244 varbufdependency(&depstr, dep);
245 varbuf_end_str(&depstr);
247 switch (dep->type) {
248 case dep_depends:
249 varbuf_printf(addto, _("%s depends on %s"),
250 pkg_name(dep->up, pnaw_nonambig), depstr.buf);
251 break;
252 case dep_predepends:
253 varbuf_printf(addto, _("%s pre-depends on %s"),
254 pkg_name(dep->up, pnaw_nonambig), depstr.buf);
255 break;
256 case dep_recommends:
257 varbuf_printf(addto, _("%s recommends %s"),
258 pkg_name(dep->up, pnaw_nonambig), depstr.buf);
259 break;
260 case dep_suggests:
261 varbuf_printf(addto, _("%s suggests %s"),
262 pkg_name(dep->up, pnaw_nonambig), depstr.buf);
263 break;
264 case dep_breaks:
265 varbuf_printf(addto, _("%s breaks %s"),
266 pkg_name(dep->up, pnaw_nonambig), depstr.buf);
267 break;
268 case dep_conflicts:
269 varbuf_printf(addto, _("%s conflicts with %s"),
270 pkg_name(dep->up, pnaw_nonambig), depstr.buf);
271 break;
272 case dep_enhances:
273 varbuf_printf(addto, _("%s enhances %s"),
274 pkg_name(dep->up, pnaw_nonambig), depstr.buf);
275 break;
276 default:
277 internerr("unknown deptype '%d'", dep->type);
280 varbuf_destroy(&depstr);
284 * *whynot must already have been initialized; it need not be
285 * empty though - it will be reset before use.
287 * If depisok returns false for ‘not OK’ it will contain a description,
288 * newline-terminated BUT NOT NUL-TERMINATED, of the reason.
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.
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.
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.
306 bool
307 depisok(struct dependency *dep, struct varbuf *whynot,
308 struct pkginfo **canfixbyremove, struct pkginfo **canfixbytrigaw,
309 bool allowunconfigd)
311 struct deppossi *possi;
312 struct deppossi *provider;
313 struct pkginfo *pkg_pos;
315 /* Use this buffer so that when internationalization comes along we
316 * don't have to rewrite the code completely, only redo the sprintf strings
317 * (assuming we have the fancy argument-number-specifiers).
318 * Allow 250x3 for package names, versions, &c, + 250 for ourselves. */
319 char linebuf[1024];
321 if (dep->type != dep_depends &&
322 dep->type != dep_predepends &&
323 dep->type != dep_breaks &&
324 dep->type != dep_conflicts &&
325 dep->type != dep_recommends &&
326 dep->type != dep_suggests &&
327 dep->type != dep_enhances)
328 internerr("unknown dependency type %d", dep->type);
330 if (canfixbyremove)
331 *canfixbyremove = NULL;
332 if (canfixbytrigaw)
333 *canfixbytrigaw = NULL;
335 /* The dependency is always OK if we're trying to remove the depend*ing*
336 * package. */
337 switch (dep->up->clientdata->istobe) {
338 case PKG_ISTOBE_REMOVE:
339 case PKG_ISTOBE_DECONFIGURE:
340 return true;
341 case PKG_ISTOBE_NORMAL:
342 /* Only installed packages can be made dependency problems. */
343 switch (dep->up->status) {
344 case PKG_STAT_INSTALLED:
345 case PKG_STAT_TRIGGERSPENDING:
346 case PKG_STAT_TRIGGERSAWAITED:
347 break;
348 case PKG_STAT_HALFCONFIGURED:
349 case PKG_STAT_UNPACKED:
350 case PKG_STAT_HALFINSTALLED:
351 if (dep->type == dep_predepends ||
352 dep->type == dep_conflicts ||
353 dep->type == dep_breaks)
354 break;
355 /* Fall through. */
356 case PKG_STAT_CONFIGFILES:
357 case PKG_STAT_NOTINSTALLED:
358 return true;
359 default:
360 internerr("unknown status depending '%d'", dep->up->status);
362 break;
363 case PKG_ISTOBE_INSTALLNEW:
364 case PKG_ISTOBE_PREINSTALL:
365 break;
366 default:
367 internerr("unknown istobe depending '%d'", dep->up->clientdata->istobe);
370 /* Describe the dependency, in case we have to moan about it. */
371 varbuf_reset(whynot);
372 varbuf_add_char(whynot, ' ');
373 describedepcon(whynot, dep);
374 varbuf_add_char(whynot, '\n');
376 /* TODO: Check dep_enhances as well. */
377 if (dep->type == dep_depends || dep->type == dep_predepends ||
378 dep->type == dep_recommends || dep->type == dep_suggests ) {
379 /* Go through the alternatives. As soon as we find one that
380 * we like, we return ‘true’ straight away. Otherwise, when we get to
381 * the end we'll have accumulated all the reasons in whynot and
382 * can return ‘false’. */
384 for (possi= dep->list; possi; possi= possi->next) {
385 struct deppossi_pkg_iterator *possi_iter;
387 possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
388 while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
389 switch (pkg_pos->clientdata->istobe) {
390 case PKG_ISTOBE_REMOVE:
391 sprintf(linebuf, _(" %.250s is to be removed.\n"),
392 pkg_name(pkg_pos, pnaw_nonambig));
393 break;
394 case PKG_ISTOBE_DECONFIGURE:
395 sprintf(linebuf, _(" %.250s is to be deconfigured.\n"),
396 pkg_name(pkg_pos, pnaw_nonambig));
397 break;
398 case PKG_ISTOBE_INSTALLNEW:
399 if (versionsatisfied(&pkg_pos->available, possi)) {
400 deppossi_pkg_iter_free(possi_iter);
401 return true;
403 sprintf(linebuf, _(" %.250s is to be installed, but is version "
404 "%.250s.\n"),
405 pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
406 versiondescribe(&pkg_pos->available.version, vdew_nonambig));
407 break;
408 case PKG_ISTOBE_NORMAL:
409 case PKG_ISTOBE_PREINSTALL:
410 switch (pkg_pos->status) {
411 case PKG_STAT_INSTALLED:
412 case PKG_STAT_TRIGGERSPENDING:
413 if (versionsatisfied(&pkg_pos->installed, possi)) {
414 deppossi_pkg_iter_free(possi_iter);
415 return true;
417 sprintf(linebuf, _(" %.250s is installed, but is version "
418 "%.250s.\n"),
419 pkg_name(pkg_pos, pnaw_nonambig),
420 versiondescribe(&pkg_pos->installed.version, vdew_nonambig));
421 break;
422 case PKG_STAT_NOTINSTALLED:
423 /* Don't say anything about this yet - it might be a virtual package.
424 * Later on, if nothing has put anything in linebuf, we know that it
425 * isn't and issue a diagnostic then. */
426 *linebuf = '\0';
427 break;
428 case PKG_STAT_TRIGGERSAWAITED:
429 if (canfixbytrigaw && versionsatisfied(&pkg_pos->installed, possi))
430 *canfixbytrigaw = pkg_pos;
431 /* Fall through. */
432 case PKG_STAT_UNPACKED:
433 case PKG_STAT_HALFCONFIGURED:
434 if (allowunconfigd) {
435 if (!dpkg_version_is_informative(&pkg_pos->configversion)) {
436 sprintf(linebuf, _(" %.250s is unpacked, but has never been "
437 "configured.\n"),
438 pkg_name(pkg_pos, pnaw_nonambig));
439 break;
440 } else if (!versionsatisfied(&pkg_pos->installed, possi)) {
441 sprintf(linebuf, _(" %.250s is unpacked, but is version "
442 "%.250s.\n"),
443 pkg_name(pkg_pos, pnaw_nonambig),
444 versiondescribe(&pkg_pos->installed.version,
445 vdew_nonambig));
446 break;
447 } else if (!dpkg_version_relate(&pkg_pos->configversion,
448 possi->verrel,
449 &possi->version)) {
450 sprintf(linebuf, _(" %.250s latest configured version is "
451 "%.250s.\n"),
452 pkg_name(pkg_pos, pnaw_nonambig),
453 versiondescribe(&pkg_pos->configversion, vdew_nonambig));
454 break;
455 } else {
456 deppossi_pkg_iter_free(possi_iter);
457 return true;
460 /* Fall through. */
461 default:
462 sprintf(linebuf, _(" %.250s is %s.\n"),
463 pkg_name(pkg_pos, pnaw_nonambig),
464 gettext(statusstrings[pkg_pos->status]));
465 break;
467 break;
468 default:
469 internerr("unknown istobe depended '%d'", pkg_pos->clientdata->istobe);
471 varbuf_add_str(whynot, linebuf);
473 deppossi_pkg_iter_free(possi_iter);
475 /* See if the package we're about to install Provides it. */
476 for (provider = possi->ed->depended.available;
477 provider;
478 provider = provider->rev_next) {
479 if (provider->up->type != dep_provides) continue;
480 if (!pkg_virtual_deppossi_satisfied(possi, provider))
481 continue;
482 if (provider->up->up->clientdata->istobe == PKG_ISTOBE_INSTALLNEW)
483 return true;
486 /* Now look at the packages already on the system. */
487 for (provider = possi->ed->depended.installed;
488 provider;
489 provider = provider->rev_next) {
490 if (provider->up->type != dep_provides) continue;
491 if (!pkg_virtual_deppossi_satisfied(possi, provider))
492 continue;
494 switch (provider->up->up->clientdata->istobe) {
495 case PKG_ISTOBE_INSTALLNEW:
496 /* Don't pay any attention to the Provides field of the
497 * currently-installed version of the package we're trying
498 * to install. We dealt with that by using the available
499 * information above. */
500 continue;
501 case PKG_ISTOBE_REMOVE:
502 sprintf(linebuf, _(" %.250s provides %.250s but is to be removed.\n"),
503 pkg_name(provider->up->up, pnaw_nonambig),
504 possi->ed->name);
505 break;
506 case PKG_ISTOBE_DECONFIGURE:
507 sprintf(linebuf, _(" %.250s provides %.250s but is to be deconfigured.\n"),
508 pkg_name(provider->up->up, pnaw_nonambig),
509 possi->ed->name);
510 break;
511 case PKG_ISTOBE_NORMAL:
512 case PKG_ISTOBE_PREINSTALL:
513 if (provider->up->up->status == PKG_STAT_INSTALLED ||
514 provider->up->up->status == PKG_STAT_TRIGGERSPENDING)
515 return true;
516 if (provider->up->up->status == PKG_STAT_TRIGGERSAWAITED)
517 *canfixbytrigaw = provider->up->up;
518 sprintf(linebuf, _(" %.250s provides %.250s but is %s.\n"),
519 pkg_name(provider->up->up, pnaw_nonambig),
520 possi->ed->name,
521 gettext(statusstrings[provider->up->up->status]));
522 break;
523 default:
524 internerr("unknown istobe provider '%d'",
525 provider->up->up->clientdata->istobe);
527 varbuf_add_str(whynot, linebuf);
530 if (!*linebuf) {
531 /* If the package wasn't installed at all, and we haven't said
532 * yet why this isn't satisfied, we should say so now. */
533 sprintf(linebuf, _(" %.250s is not installed.\n"), possi->ed->name);
534 varbuf_add_str(whynot, linebuf);
538 return false;
539 } else {
540 int nconflicts;
542 /* It's conflicts or breaks. There's only one main alternative,
543 * but we also have to consider Providers. We return ‘false’ as soon
544 * as we find something that matches the conflict, and only describe
545 * it then. If we get to the end without finding anything we return
546 * ‘true’. */
548 possi= dep->list;
549 nconflicts= 0;
551 if (possi->ed != possi->up->up->set) {
552 struct deppossi_pkg_iterator *possi_iter;
554 /* If the package conflicts with or breaks itself it must mean
555 * other packages which provide the same virtual name. We
556 * therefore don't look at the real package and go on to the
557 * virtual ones. */
559 possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
560 while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
561 switch (pkg_pos->clientdata->istobe) {
562 case PKG_ISTOBE_REMOVE:
563 break;
564 case PKG_ISTOBE_INSTALLNEW:
565 if (!versionsatisfied(&pkg_pos->available, possi))
566 break;
567 sprintf(linebuf, _(" %.250s (version %.250s) is to be installed.\n"),
568 pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
569 versiondescribe(&pkg_pos->available.version, vdew_nonambig));
570 varbuf_add_str(whynot, linebuf);
571 if (!canfixbyremove) {
572 deppossi_pkg_iter_free(possi_iter);
573 return false;
575 nconflicts++;
576 *canfixbyremove = pkg_pos;
577 break;
578 case PKG_ISTOBE_DECONFIGURE:
579 if (dep->type == dep_breaks)
580 break; /* Already deconfiguring this. */
581 /* Fall through. */
582 case PKG_ISTOBE_NORMAL:
583 case PKG_ISTOBE_PREINSTALL:
584 switch (pkg_pos->status) {
585 case PKG_STAT_NOTINSTALLED:
586 case PKG_STAT_CONFIGFILES:
587 break;
588 case PKG_STAT_HALFINSTALLED:
589 case PKG_STAT_UNPACKED:
590 case PKG_STAT_HALFCONFIGURED:
591 if (dep->type == dep_breaks)
592 break; /* No problem. */
593 /* Fall through. */
594 case PKG_STAT_INSTALLED:
595 case PKG_STAT_TRIGGERSPENDING:
596 case PKG_STAT_TRIGGERSAWAITED:
597 if (!versionsatisfied(&pkg_pos->installed, possi))
598 break;
599 sprintf(linebuf, _(" %.250s (version %.250s) is present and %s.\n"),
600 pkg_name(pkg_pos, pnaw_nonambig),
601 versiondescribe(&pkg_pos->installed.version, vdew_nonambig),
602 gettext(statusstrings[pkg_pos->status]));
603 varbuf_add_str(whynot, linebuf);
604 if (!canfixbyremove) {
605 deppossi_pkg_iter_free(possi_iter);
606 return false;
608 nconflicts++;
609 *canfixbyremove = pkg_pos;
611 break;
612 default:
613 internerr("unknown istobe conflict '%d'", pkg_pos->clientdata->istobe);
616 deppossi_pkg_iter_free(possi_iter);
619 /* See if the package we're about to install Provides it. */
620 for (provider = possi->ed->depended.available;
621 provider;
622 provider = provider->rev_next) {
623 if (provider->up->type != dep_provides) continue;
624 if (provider->up->up->clientdata->istobe != PKG_ISTOBE_INSTALLNEW)
625 continue;
626 if (provider->up->up->set == dep->up->set)
627 continue; /* Conflicts and provides the same. */
628 if (!pkg_virtual_deppossi_satisfied(possi, provider))
629 continue;
630 sprintf(linebuf, _(" %.250s provides %.250s and is to be installed.\n"),
631 pkgbin_name(provider->up->up, &provider->up->up->available,
632 pnaw_nonambig), possi->ed->name);
633 varbuf_add_str(whynot, linebuf);
634 /* We can't remove the one we're about to install: */
635 if (canfixbyremove)
636 *canfixbyremove = NULL;
637 return false;
640 /* Now look at the packages already on the system. */
641 for (provider = possi->ed->depended.installed;
642 provider;
643 provider = provider->rev_next) {
644 if (provider->up->type != dep_provides) continue;
646 if (provider->up->up->set == dep->up->set)
647 continue; /* Conflicts and provides the same. */
649 if (!pkg_virtual_deppossi_satisfied(possi, provider))
650 continue;
652 switch (provider->up->up->clientdata->istobe) {
653 case PKG_ISTOBE_INSTALLNEW:
654 /* Don't pay any attention to the Provides field of the
655 * currently-installed version of the package we're trying
656 * to install. We dealt with that package by using the
657 * available information above. */
658 continue;
659 case PKG_ISTOBE_REMOVE:
660 continue;
661 case PKG_ISTOBE_DECONFIGURE:
662 if (dep->type == dep_breaks)
663 continue; /* Already deconfiguring. */
664 /* Fall through. */
665 case PKG_ISTOBE_NORMAL:
666 case PKG_ISTOBE_PREINSTALL:
667 switch (provider->up->up->status) {
668 case PKG_STAT_NOTINSTALLED:
669 case PKG_STAT_CONFIGFILES:
670 continue;
671 case PKG_STAT_HALFINSTALLED:
672 case PKG_STAT_UNPACKED:
673 case PKG_STAT_HALFCONFIGURED:
674 if (dep->type == dep_breaks)
675 break; /* No problem. */
676 /* Fall through. */
677 case PKG_STAT_INSTALLED:
678 case PKG_STAT_TRIGGERSPENDING:
679 case PKG_STAT_TRIGGERSAWAITED:
680 sprintf(linebuf,
681 _(" %.250s provides %.250s and is present and %s.\n"),
682 pkg_name(provider->up->up, pnaw_nonambig), possi->ed->name,
683 gettext(statusstrings[provider->up->up->status]));
684 varbuf_add_str(whynot, linebuf);
685 if (!canfixbyremove)
686 return false;
687 nconflicts++;
688 *canfixbyremove= provider->up->up;
689 break;
691 break;
692 default:
693 internerr("unknown istobe conflict provider '%d'",
694 provider->up->up->clientdata->istobe);
698 if (!nconflicts)
699 return true;
700 if (nconflicts > 1)
701 *canfixbyremove = NULL;
702 return false;
704 } /* if (dependency) {...} else {...} */