packages.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. /*
  2. * dpkg - main program for package management
  3. * packages.c - common to actions that process packages
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ian@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. #include <config.h>
  24. #include <compat.h>
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <assert.h>
  28. #include <ctype.h>
  29. #include <string.h>
  30. #include <fcntl.h>
  31. #include <dirent.h>
  32. #include <unistd.h>
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <dpkg/i18n.h>
  36. #include <dpkg/dpkg.h>
  37. #include <dpkg/dpkg-db.h>
  38. #include <dpkg/pkg-list.h>
  39. #include <dpkg/pkg-queue.h>
  40. #include <dpkg/string.h>
  41. #include <dpkg/options.h>
  42. #include "filesdb.h"
  43. #include "infodb.h"
  44. #include "main.h"
  45. static struct pkginfo *progress_bytrigproc;
  46. static struct pkg_queue queue = PKG_QUEUE_INIT;
  47. int sincenothing = 0, dependtry = 0;
  48. void
  49. enqueue_package(struct pkginfo *pkg)
  50. {
  51. pkg_queue_push(&queue, pkg);
  52. }
  53. static void
  54. enqueue_pending(void)
  55. {
  56. struct pkgiterator *it;
  57. struct pkginfo *pkg;
  58. it = pkg_db_iter_new();
  59. while ((pkg = pkg_db_iter_next_pkg(it)) != NULL) {
  60. switch (cipaction->arg_int) {
  61. case act_configure:
  62. if (!(pkg->status == PKG_STAT_UNPACKED ||
  63. pkg->status == PKG_STAT_HALFCONFIGURED ||
  64. pkg->trigpend_head))
  65. continue;
  66. if (pkg->want != PKG_WANT_INSTALL)
  67. continue;
  68. break;
  69. case act_triggers:
  70. if (!pkg->trigpend_head)
  71. continue;
  72. if (pkg->want != PKG_WANT_INSTALL)
  73. continue;
  74. break;
  75. case act_remove:
  76. case act_purge:
  77. if (pkg->want != PKG_WANT_PURGE) {
  78. if (pkg->want != PKG_WANT_DEINSTALL)
  79. continue;
  80. if (pkg->status == PKG_STAT_CONFIGFILES)
  81. continue;
  82. }
  83. if (pkg->status == PKG_STAT_NOTINSTALLED)
  84. continue;
  85. break;
  86. default:
  87. internerr("unknown action '%d'", cipaction->arg_int);
  88. }
  89. enqueue_package(pkg);
  90. }
  91. pkg_db_iter_free(it);
  92. }
  93. static void
  94. enqueue_specified(const char *const *argv)
  95. {
  96. const char *thisarg;
  97. while ((thisarg = *argv++) != NULL) {
  98. struct pkginfo *pkg;
  99. pkg = dpkg_options_parse_pkgname(cipaction, thisarg);
  100. if (pkg->status == PKG_STAT_NOTINSTALLED &&
  101. str_match_end(pkg->set->name, DEBEXT)) {
  102. badusage(_("you must specify packages by their own names, "
  103. "not by quoting the names of the files they come in"));
  104. }
  105. enqueue_package(pkg);
  106. }
  107. }
  108. int
  109. packages(const char *const *argv)
  110. {
  111. trigproc_install_hooks();
  112. modstatdb_open(f_noact ? msdbrw_readonly :
  113. fc_nonroot ? msdbrw_write :
  114. msdbrw_needsuperuser);
  115. checkpath();
  116. pkg_infodb_upgrade();
  117. log_message("startup packages %s", cipaction->olong);
  118. if (f_pending) {
  119. if (*argv)
  120. badusage(_("--%s --pending does not take any non-option arguments"),cipaction->olong);
  121. enqueue_pending();
  122. } else {
  123. if (!*argv)
  124. badusage(_("--%s needs at least one package name argument"), cipaction->olong);
  125. enqueue_specified(argv);
  126. }
  127. ensure_diversions();
  128. process_queue();
  129. trigproc_run_deferred();
  130. modstatdb_shutdown();
  131. return 0;
  132. }
  133. void process_queue(void) {
  134. struct pkg_list *rundown;
  135. struct pkginfo *volatile pkg;
  136. volatile enum action action_todo;
  137. jmp_buf ejbuf;
  138. enum pkg_istobe istobe = PKG_ISTOBE_NORMAL;
  139. if (abort_processing)
  140. return;
  141. clear_istobes();
  142. switch (cipaction->arg_int) {
  143. case act_triggers:
  144. case act_configure:
  145. case act_install:
  146. istobe = PKG_ISTOBE_INSTALLNEW;
  147. break;
  148. case act_remove:
  149. case act_purge:
  150. istobe = PKG_ISTOBE_REMOVE;
  151. break;
  152. default:
  153. internerr("unknown action '%d'", cipaction->arg_int);
  154. }
  155. for (rundown = queue.head; rundown; rundown = rundown->next) {
  156. ensure_package_clientdata(rundown->pkg);
  157. if (rundown->pkg->clientdata->istobe == istobe) {
  158. /* Erase the queue entry - this is a second copy! */
  159. switch (cipaction->arg_int) {
  160. case act_triggers:
  161. case act_configure: case act_remove: case act_purge:
  162. printf(_("Package %s listed more than once, only processing once.\n"),
  163. pkg_name(rundown->pkg, pnaw_nonambig));
  164. break;
  165. case act_install:
  166. printf(_("More than one copy of package %s has been unpacked\n"
  167. " in this run ! Only configuring it once.\n"),
  168. pkg_name(rundown->pkg, pnaw_nonambig));
  169. break;
  170. default:
  171. internerr("unknown action '%d'", cipaction->arg_int);
  172. }
  173. rundown->pkg = NULL;
  174. } else {
  175. rundown->pkg->clientdata->istobe= istobe;
  176. }
  177. }
  178. while (!pkg_queue_is_empty(&queue)) {
  179. pkg = pkg_queue_pop(&queue);
  180. if (!pkg)
  181. continue; /* Duplicate, which we removed earlier. */
  182. action_todo = cipaction->arg_int;
  183. if (sincenothing++ > queue.length * 2 + 2) {
  184. if (progress_bytrigproc && progress_bytrigproc->trigpend_head) {
  185. enqueue_package(pkg);
  186. pkg = progress_bytrigproc;
  187. action_todo = act_configure;
  188. } else {
  189. dependtry++;
  190. sincenothing = 0;
  191. assert(dependtry <= 4);
  192. }
  193. }
  194. if (pkg->status > PKG_STAT_INSTALLED)
  195. internerr("package status (%d) > PKG_STAT_INSTALLED", pkg->status);
  196. if (setjmp(ejbuf)) {
  197. /* Give up on it from the point of view of other packages, i.e. reset
  198. * istobe. */
  199. pkg->clientdata->istobe = PKG_ISTOBE_NORMAL;
  200. pop_error_context(ehflag_bombout);
  201. if (abort_processing)
  202. return;
  203. continue;
  204. }
  205. push_error_context_jump(&ejbuf, print_error_perpackage,
  206. pkg_name(pkg, pnaw_nonambig));
  207. switch (action_todo) {
  208. case act_triggers:
  209. if (!pkg->trigpend_head)
  210. ohshit(_("package %.250s is not ready for trigger processing\n"
  211. " (current status `%.250s' with no pending triggers)"),
  212. pkg_name(pkg, pnaw_nonambig), pkg_status_name(pkg));
  213. /* Fall through. */
  214. case act_install:
  215. /* Don't try to configure pkgs that we've just disappeared. */
  216. if (pkg->status == PKG_STAT_NOTINSTALLED)
  217. break;
  218. /* Fall through. */
  219. case act_configure:
  220. /* Do whatever is most needed. */
  221. if (pkg->trigpend_head)
  222. trigproc(pkg);
  223. else
  224. deferred_configure(pkg);
  225. break;
  226. case act_remove: case act_purge:
  227. deferred_remove(pkg);
  228. break;
  229. default:
  230. internerr("unknown action '%d'", cipaction->arg_int);
  231. }
  232. m_output(stdout, _("<standard output>"));
  233. m_output(stderr, _("<standard error>"));
  234. pop_error_context(ehflag_normaltidy);
  235. }
  236. assert(!queue.length);
  237. }
  238. /*** Dependency processing - common to --configure and --remove. ***/
  239. /*
  240. * The algorithm for deciding what to configure or remove first is as
  241. * follows:
  242. *
  243. * Loop through all packages doing a ‘try 1’ until we've been round and
  244. * nothing has been done, then do ‘try 2’ and ‘try 3’ likewise.
  245. *
  246. * When configuring, in each try we check to see whether all
  247. * dependencies of this package are done. If so we do it. If some of
  248. * the dependencies aren't done yet but will be later we defer the
  249. * package, otherwise it is an error.
  250. *
  251. * When removing, in each try we check to see whether there are any
  252. * packages that would have dependencies missing if we removed this
  253. * one. If not we remove it now. If some of these packages are
  254. * themselves scheduled for removal we defer the package until they
  255. * have been done.
  256. *
  257. * The criteria for satisfying a dependency vary with the various
  258. * tries. In try 1 we treat the dependencies as absolute. In try 2 we
  259. * check break any cycles in the dependency graph involving the package
  260. * we are trying to process before trying to process the package
  261. * normally. In try 3 (which should only be reached if
  262. * --force-depends-version is set) we ignore version number clauses in
  263. * Depends lines. In try 4 (only reached if --force-depends is set) we
  264. * say "ok" regardless.
  265. *
  266. * If we are configuring and one of the packages we depend on is
  267. * awaiting configuration but wasn't specified in the argument list we
  268. * will add it to the argument list if --configure-any is specified.
  269. * In this case we note this as having "done something" so that we
  270. * don't needlessly escalate to higher levels of dependency checking
  271. * and breaking.
  272. */
  273. enum found_status {
  274. FOUND_NONE = 0,
  275. FOUND_DEFER = 1,
  276. FOUND_FORCED = 2,
  277. FOUND_OK = 3,
  278. };
  279. /*
  280. * Return values:
  281. * 0: cannot be satisfied.
  282. * 1: defer: may be satisfied later, when other packages are better or
  283. * at higher dependtry due to --force
  284. * will set *fixbytrig to package whose trigger processing would help
  285. * if applicable (and leave it alone otherwise).
  286. * 2: not satisfied but forcing
  287. * (*interestingwarnings >= 0 on exit? caller is to print oemsgs).
  288. * 3: satisfied now.
  289. */
  290. static enum found_status
  291. deppossi_ok_found(struct pkginfo *possdependee, struct pkginfo *requiredby,
  292. struct pkginfo *removing, struct deppossi *provider,
  293. struct pkginfo **fixbytrig,
  294. bool *matched, struct deppossi *checkversion,
  295. int *interestingwarnings, struct varbuf *oemsgs)
  296. {
  297. enum found_status thisf;
  298. if (ignore_depends(possdependee)) {
  299. debug(dbg_depcondetail," ignoring depended package so ok and found");
  300. return FOUND_OK;
  301. }
  302. thisf = FOUND_NONE;
  303. if (possdependee == removing) {
  304. if (provider) {
  305. varbuf_printf(oemsgs,
  306. _(" Package %s which provides %s is to be removed.\n"),
  307. pkg_name(possdependee, pnaw_nonambig),
  308. provider->ed->name);
  309. } else {
  310. varbuf_printf(oemsgs, _(" Package %s is to be removed.\n"),
  311. pkg_name(possdependee, pnaw_nonambig));
  312. }
  313. *matched = true;
  314. debug(dbg_depcondetail," removing possdependee, returning %d",thisf);
  315. return thisf;
  316. }
  317. switch (possdependee->status) {
  318. case PKG_STAT_UNPACKED:
  319. case PKG_STAT_HALFCONFIGURED:
  320. case PKG_STAT_TRIGGERSAWAITED:
  321. case PKG_STAT_TRIGGERSPENDING:
  322. case PKG_STAT_INSTALLED:
  323. if (checkversion) {
  324. if (provider) {
  325. debug(dbg_depcondetail, " checking package %s provided by pkg %s",
  326. checkversion->ed->name, pkg_name(possdependee, pnaw_always));
  327. if (!pkg_virtual_deppossi_satisfied(checkversion, provider)) {
  328. varbuf_printf(oemsgs,
  329. _(" Version of %s on system, provided by %s, is %s.\n"),
  330. checkversion->ed->name,
  331. pkg_name(possdependee, pnaw_always),
  332. versiondescribe(&provider->version, vdew_nonambig));
  333. if (fc_dependsversion)
  334. thisf = (dependtry >= 3) ? FOUND_FORCED : FOUND_DEFER;
  335. debug(dbg_depcondetail, " bad version");
  336. goto unsuitable;
  337. }
  338. } else {
  339. debug(dbg_depcondetail, " checking non-provided pkg %s",
  340. pkg_name(possdependee, pnaw_always));
  341. if (!versionsatisfied(&possdependee->installed, checkversion)) {
  342. varbuf_printf(oemsgs, _(" Version of %s on system is %s.\n"),
  343. pkg_name(possdependee, pnaw_nonambig),
  344. versiondescribe(&possdependee->installed.version,
  345. vdew_nonambig));
  346. if (fc_dependsversion)
  347. thisf = (dependtry >= 3) ? FOUND_FORCED : FOUND_DEFER;
  348. debug(dbg_depcondetail, " bad version");
  349. goto unsuitable;
  350. }
  351. }
  352. }
  353. if (possdependee->status == PKG_STAT_INSTALLED ||
  354. possdependee->status == PKG_STAT_TRIGGERSPENDING) {
  355. debug(dbg_depcondetail," is installed, ok and found");
  356. return FOUND_OK;
  357. }
  358. if (possdependee->status == PKG_STAT_TRIGGERSAWAITED) {
  359. assert(possdependee->trigaw.head);
  360. if (removing ||
  361. !(f_triggers ||
  362. possdependee->clientdata->istobe == PKG_ISTOBE_INSTALLNEW)) {
  363. if (provider) {
  364. varbuf_printf(oemsgs,
  365. _(" Package %s which provides %s awaits trigger processing.\n"),
  366. pkg_name(possdependee, pnaw_nonambig),
  367. provider->ed->name);
  368. } else {
  369. varbuf_printf(oemsgs,
  370. _(" Package %s awaits trigger processing.\n"),
  371. pkg_name(possdependee, pnaw_nonambig));
  372. }
  373. debug(dbg_depcondetail, " triggers-awaited, no fixbytrig");
  374. goto unsuitable;
  375. }
  376. /* We don't check the status of trigaw.head->pend here, just in case
  377. * we get into the pathological situation where Triggers-Awaited but
  378. * the named package doesn't actually have any pending triggers. In
  379. * that case we queue the non-pending package for trigger processing
  380. * anyway, and that trigger processing will be a noop except for
  381. * sorting out all of the packages which name it in Triggers-Awaited.
  382. *
  383. * (This situation can only arise if modstatdb_note success in
  384. * clearing the triggers-pending status of the pending package
  385. * but then fails to go on to update the awaiters.) */
  386. *fixbytrig = possdependee->trigaw.head->pend;
  387. debug(dbg_depcondetail,
  388. " triggers-awaited, fixbytrig '%s', defer",
  389. pkg_name(*fixbytrig, pnaw_always));
  390. return FOUND_DEFER;
  391. }
  392. if (possdependee->clientdata &&
  393. possdependee->clientdata->istobe == PKG_ISTOBE_INSTALLNEW) {
  394. debug(dbg_depcondetail," unpacked/halfconfigured, defer");
  395. return FOUND_DEFER;
  396. } else if (!removing && fc_configureany &&
  397. !skip_due_to_hold(possdependee) &&
  398. !(possdependee->status == PKG_STAT_HALFCONFIGURED)) {
  399. notice(_("also configuring '%s' (required by '%s')"),
  400. pkg_name(possdependee, pnaw_nonambig),
  401. pkg_name(requiredby, pnaw_nonambig));
  402. enqueue_package(possdependee);
  403. sincenothing = 0;
  404. return FOUND_DEFER;
  405. } else {
  406. if (provider) {
  407. varbuf_printf(oemsgs,
  408. _(" Package %s which provides %s is not configured yet.\n"),
  409. pkg_name(possdependee, pnaw_nonambig),
  410. provider->ed->name);
  411. } else {
  412. varbuf_printf(oemsgs, _(" Package %s is not configured yet.\n"),
  413. pkg_name(possdependee, pnaw_nonambig));
  414. }
  415. debug(dbg_depcondetail, " not configured/able");
  416. goto unsuitable;
  417. }
  418. default:
  419. if (provider) {
  420. varbuf_printf(oemsgs,
  421. _(" Package %s which provides %s is not installed.\n"),
  422. pkg_name(possdependee, pnaw_nonambig),
  423. provider->ed->name);
  424. } else {
  425. varbuf_printf(oemsgs, _(" Package %s is not installed.\n"),
  426. pkg_name(possdependee, pnaw_nonambig));
  427. }
  428. debug(dbg_depcondetail, " not installed");
  429. goto unsuitable;
  430. }
  431. unsuitable:
  432. debug(dbg_depcondetail, " returning %d", thisf);
  433. (*interestingwarnings)++;
  434. return thisf;
  435. }
  436. static void
  437. breaks_check_one(struct varbuf *aemsgs, enum dep_check *ok,
  438. struct deppossi *breaks, struct pkginfo *broken,
  439. struct pkginfo *breaker, struct deppossi *virtbroken)
  440. {
  441. struct varbuf depmsg = VARBUF_INIT;
  442. debug(dbg_depcondetail, " checking breaker %s virtbroken %s",
  443. pkg_name(breaker, pnaw_always),
  444. virtbroken ? virtbroken->ed->name : "<none>");
  445. if (breaker->status == PKG_STAT_NOTINSTALLED ||
  446. breaker->status == PKG_STAT_CONFIGFILES)
  447. return;
  448. if (broken == breaker) return;
  449. if (!versionsatisfied(&broken->installed, breaks)) return;
  450. /* The test below can only trigger if dep_breaks start having
  451. * arch qualifiers different from “any”. */
  452. if (!archsatisfied(&broken->installed, breaks))
  453. return;
  454. if (ignore_depends(breaker)) return;
  455. if (virtbroken && ignore_depends(&virtbroken->ed->pkg))
  456. return;
  457. if (virtbroken && !pkg_virtual_deppossi_satisfied(breaks, virtbroken))
  458. return;
  459. varbufdependency(&depmsg, breaks->up);
  460. varbuf_end_str(&depmsg);
  461. varbuf_printf(aemsgs, _(" %s (%s) breaks %s and is %s.\n"),
  462. pkg_name(breaker, pnaw_nonambig),
  463. versiondescribe(&breaker->installed.version, vdew_nonambig),
  464. depmsg.buf, gettext(statusstrings[breaker->status]));
  465. varbuf_destroy(&depmsg);
  466. if (virtbroken) {
  467. varbuf_printf(aemsgs, _(" %s (%s) provides %s.\n"),
  468. pkg_name(broken, pnaw_nonambig),
  469. versiondescribe(&broken->installed.version, vdew_nonambig),
  470. virtbroken->ed->name);
  471. } else if (breaks->verrel != DPKG_RELATION_NONE) {
  472. varbuf_printf(aemsgs, _(" Version of %s to be configured is %s.\n"),
  473. pkg_name(broken, pnaw_nonambig),
  474. versiondescribe(&broken->installed.version, vdew_nonambig));
  475. if (fc_dependsversion) return;
  476. }
  477. if (force_breaks(breaks)) return;
  478. *ok = DEP_CHECK_HALT;
  479. }
  480. static void
  481. breaks_check_target(struct varbuf *aemsgs, enum dep_check *ok,
  482. struct pkginfo *broken, struct pkgset *target,
  483. struct deppossi *virtbroken)
  484. {
  485. struct deppossi *possi;
  486. for (possi = target->depended.installed; possi; possi = possi->rev_next) {
  487. if (possi->up->type != dep_breaks) continue;
  488. breaks_check_one(aemsgs, ok, possi, broken, possi->up->up, virtbroken);
  489. }
  490. }
  491. enum dep_check
  492. breakses_ok(struct pkginfo *pkg, struct varbuf *aemsgs)
  493. {
  494. struct dependency *dep;
  495. struct deppossi *virtbroken;
  496. enum dep_check ok = DEP_CHECK_OK;
  497. debug(dbg_depcon, " checking Breaks");
  498. breaks_check_target(aemsgs, &ok, pkg, pkg->set, NULL);
  499. for (dep= pkg->installed.depends; dep; dep= dep->next) {
  500. if (dep->type != dep_provides) continue;
  501. virtbroken = dep->list;
  502. debug(dbg_depcondetail, " checking virtbroken %s", virtbroken->ed->name);
  503. breaks_check_target(aemsgs, &ok, pkg, virtbroken->ed, virtbroken);
  504. }
  505. return ok;
  506. }
  507. /*
  508. * Checks [Pre]-Depends only.
  509. */
  510. enum dep_check
  511. dependencies_ok(struct pkginfo *pkg, struct pkginfo *removing,
  512. struct varbuf *aemsgs)
  513. {
  514. /* Valid values: 2 = ok, 1 = defer, 0 = halt. */
  515. enum dep_check ok;
  516. /* Valid values: 0 = none, 1 = defer, 2 = withwarning, 3 = ok. */
  517. enum found_status found, thisf;
  518. int interestingwarnings;
  519. bool matched, anycannotfixbytrig;
  520. struct varbuf oemsgs = VARBUF_INIT;
  521. struct dependency *dep;
  522. struct deppossi *possi, *provider;
  523. struct pkginfo *possfixbytrig, *canfixbytrig;
  524. interestingwarnings= 0;
  525. ok = DEP_CHECK_OK;
  526. debug(dbg_depcon,"checking dependencies of %s (- %s)",
  527. pkg_name(pkg, pnaw_always),
  528. removing ? pkg_name(removing, pnaw_always) : "<none>");
  529. anycannotfixbytrig = false;
  530. canfixbytrig = NULL;
  531. for (dep= pkg->installed.depends; dep; dep= dep->next) {
  532. if (dep->type != dep_depends && dep->type != dep_predepends) continue;
  533. debug(dbg_depcondetail," checking group ...");
  534. matched = false;
  535. varbuf_reset(&oemsgs);
  536. found = FOUND_NONE;
  537. possfixbytrig = NULL;
  538. for (possi = dep->list; found != FOUND_OK && possi; possi = possi->next) {
  539. struct deppossi_pkg_iterator *possi_iter;
  540. struct pkginfo *pkg_pos;
  541. debug(dbg_depcondetail," checking possibility -> %s",possi->ed->name);
  542. if (possi->cyclebreak) {
  543. debug(dbg_depcondetail," break cycle so ok and found");
  544. found = FOUND_OK;
  545. break;
  546. }
  547. thisf = FOUND_NONE;
  548. possi_iter = deppossi_pkg_iter_new(possi, wpb_installed);
  549. while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
  550. thisf = deppossi_ok_found(pkg_pos, pkg, removing, NULL,
  551. &possfixbytrig, &matched, possi,
  552. &interestingwarnings, &oemsgs);
  553. if (thisf > found)
  554. found = thisf;
  555. if (found == FOUND_OK)
  556. break;
  557. }
  558. deppossi_pkg_iter_free(possi_iter);
  559. if (found != FOUND_OK) {
  560. for (provider = possi->ed->depended.installed;
  561. found != FOUND_OK && provider;
  562. provider = provider->rev_next) {
  563. if (provider->up->type != dep_provides)
  564. continue;
  565. debug(dbg_depcondetail, " checking provider %s",
  566. pkg_name(provider->up->up, pnaw_always));
  567. if (!deparchsatisfied(&provider->up->up->installed, provider->arch,
  568. possi)) {
  569. debug(dbg_depcondetail, " provider does not satisfy arch");
  570. continue;
  571. }
  572. thisf = deppossi_ok_found(provider->up->up, pkg, removing, provider,
  573. &possfixbytrig, &matched, possi,
  574. &interestingwarnings, &oemsgs);
  575. if (thisf == FOUND_DEFER && provider->up->up == pkg && !removing) {
  576. /* IOW, if the pkg satisfies its own dep (via a provide), then
  577. * we let it pass, even if it isn't configured yet (as we're
  578. * installing it). */
  579. thisf = FOUND_OK;
  580. }
  581. if (thisf > found)
  582. found = thisf;
  583. }
  584. }
  585. debug(dbg_depcondetail," found %d",found);
  586. if (thisf > found) found= thisf;
  587. }
  588. if (fc_depends) {
  589. thisf = (dependtry >= 4) ? FOUND_FORCED : FOUND_DEFER;
  590. if (thisf > found) {
  591. found = thisf;
  592. debug(dbg_depcondetail, " rescued by force-depends, found %d", found);
  593. }
  594. }
  595. debug(dbg_depcondetail, " found %d matched %d possfixbytrig %s",
  596. found, matched,
  597. possfixbytrig ? pkg_name(possfixbytrig, pnaw_always) : "-");
  598. if (removing && !matched) continue;
  599. switch (found) {
  600. case FOUND_NONE:
  601. anycannotfixbytrig = true;
  602. ok = DEP_CHECK_HALT;
  603. /* Fall through. */
  604. case FOUND_FORCED:
  605. varbuf_add_str(aemsgs, " ");
  606. varbuf_add_pkgbin_name(aemsgs, pkg, &pkg->installed, pnaw_nonambig);
  607. varbuf_add_str(aemsgs, _(" depends on "));
  608. varbufdependency(aemsgs, dep);
  609. if (interestingwarnings) {
  610. /* Don't print the line about the package to be removed if
  611. * that's the only line. */
  612. varbuf_end_str(&oemsgs);
  613. varbuf_add_str(aemsgs, _("; however:\n"));
  614. varbuf_add_str(aemsgs, oemsgs.buf);
  615. } else {
  616. varbuf_add_str(aemsgs, ".\n");
  617. }
  618. break;
  619. case FOUND_DEFER:
  620. if (possfixbytrig)
  621. canfixbytrig = possfixbytrig;
  622. else
  623. anycannotfixbytrig = true;
  624. if (ok > DEP_CHECK_DEFER)
  625. ok = DEP_CHECK_DEFER;
  626. break;
  627. case FOUND_OK:
  628. break;
  629. default:
  630. internerr("unknown value for found '%d'", found);
  631. }
  632. }
  633. if (ok == DEP_CHECK_HALT &&
  634. (pkg->clientdata && pkg->clientdata->istobe == PKG_ISTOBE_REMOVE))
  635. ok = DEP_CHECK_DEFER;
  636. if (!anycannotfixbytrig && canfixbytrig)
  637. progress_bytrigproc = canfixbytrig;
  638. varbuf_destroy(&oemsgs);
  639. debug(dbg_depcon,"ok %d msgs >>%.*s<<", ok, (int)aemsgs->used, aemsgs->buf);
  640. return ok;
  641. }