packages.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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 pkgset *providing,
  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 (providing) {
  305. varbuf_printf(oemsgs,
  306. _(" Package %s which provides %s is to be removed.\n"),
  307. pkg_name(possdependee, pnaw_nonambig), providing->name);
  308. } else {
  309. varbuf_printf(oemsgs, _(" Package %s is to be removed.\n"),
  310. pkg_name(possdependee, pnaw_nonambig));
  311. }
  312. *matched = true;
  313. debug(dbg_depcondetail," removing possdependee, returning %d",thisf);
  314. return thisf;
  315. }
  316. switch (possdependee->status) {
  317. case PKG_STAT_UNPACKED:
  318. case PKG_STAT_HALFCONFIGURED:
  319. case PKG_STAT_TRIGGERSAWAITED:
  320. case PKG_STAT_TRIGGERSPENDING:
  321. case PKG_STAT_INSTALLED:
  322. if (checkversion && !versionsatisfied(&possdependee->installed,checkversion)) {
  323. varbuf_printf(oemsgs, _(" Version of %s on system is %s.\n"),
  324. pkg_name(possdependee, pnaw_nonambig),
  325. versiondescribe(&possdependee->installed.version,
  326. vdew_nonambig));
  327. assert(checkversion->verrel != DPKG_RELATION_NONE);
  328. if (fc_dependsversion)
  329. thisf = (dependtry >= 3) ? FOUND_FORCED : FOUND_DEFER;
  330. debug(dbg_depcondetail," bad version, returning %d",thisf);
  331. (*interestingwarnings)++;
  332. return thisf;
  333. }
  334. if (possdependee->status == PKG_STAT_INSTALLED ||
  335. possdependee->status == PKG_STAT_TRIGGERSPENDING) {
  336. debug(dbg_depcondetail," is installed, ok and found");
  337. return FOUND_OK;
  338. }
  339. if (possdependee->status == PKG_STAT_TRIGGERSAWAITED) {
  340. assert(possdependee->trigaw.head);
  341. if (removing ||
  342. !(f_triggers ||
  343. possdependee->clientdata->istobe == PKG_ISTOBE_INSTALLNEW)) {
  344. if (providing) {
  345. varbuf_printf(oemsgs,
  346. _(" Package %s which provides %s awaits trigger processing.\n"),
  347. pkg_name(possdependee, pnaw_nonambig), providing->name);
  348. } else {
  349. varbuf_printf(oemsgs,
  350. _(" Package %s awaits trigger processing.\n"),
  351. pkg_name(possdependee, pnaw_nonambig));
  352. }
  353. debug(dbg_depcondetail, " triggers-awaited, no fixbytrig");
  354. goto unsuitable;
  355. }
  356. /* We don't check the status of trigaw.head->pend here, just in case
  357. * we get into the pathological situation where Triggers-Awaited but
  358. * the named package doesn't actually have any pending triggers. In
  359. * that case we queue the non-pending package for trigger processing
  360. * anyway, and that trigger processing will be a noop except for
  361. * sorting out all of the packages which name it in Triggers-Awaited.
  362. *
  363. * (This situation can only arise if modstatdb_note success in
  364. * clearing the triggers-pending status of the pending package
  365. * but then fails to go on to update the awaiters.) */
  366. *fixbytrig = possdependee->trigaw.head->pend;
  367. debug(dbg_depcondetail,
  368. " triggers-awaited, fixbytrig '%s', defer",
  369. pkg_name(*fixbytrig, pnaw_always));
  370. return FOUND_DEFER;
  371. }
  372. if (possdependee->clientdata &&
  373. possdependee->clientdata->istobe == PKG_ISTOBE_INSTALLNEW) {
  374. debug(dbg_depcondetail," unpacked/halfconfigured, defer");
  375. return FOUND_DEFER;
  376. } else if (!removing && fc_configureany &&
  377. !skip_due_to_hold(possdependee) &&
  378. !(possdependee->status == PKG_STAT_HALFCONFIGURED)) {
  379. notice(_("also configuring '%s' (required by '%s')"),
  380. pkg_name(possdependee, pnaw_nonambig),
  381. pkg_name(requiredby, pnaw_nonambig));
  382. enqueue_package(possdependee);
  383. sincenothing = 0;
  384. return FOUND_DEFER;
  385. } else {
  386. if (providing) {
  387. varbuf_printf(oemsgs,
  388. _(" Package %s which provides %s is not configured yet.\n"),
  389. pkg_name(possdependee, pnaw_nonambig), providing->name);
  390. } else {
  391. varbuf_printf(oemsgs, _(" Package %s is not configured yet.\n"),
  392. pkg_name(possdependee, pnaw_nonambig));
  393. }
  394. debug(dbg_depcondetail, " not configured/able");
  395. goto unsuitable;
  396. }
  397. default:
  398. if (providing) {
  399. varbuf_printf(oemsgs,
  400. _(" Package %s which provides %s is not installed.\n"),
  401. pkg_name(possdependee, pnaw_nonambig), providing->name);
  402. } else {
  403. varbuf_printf(oemsgs, _(" Package %s is not installed.\n"),
  404. pkg_name(possdependee, pnaw_nonambig));
  405. }
  406. debug(dbg_depcondetail, " not installed");
  407. goto unsuitable;
  408. }
  409. unsuitable:
  410. debug(dbg_depcondetail, " returning %d", thisf);
  411. (*interestingwarnings)++;
  412. return thisf;
  413. }
  414. static void
  415. breaks_check_one(struct varbuf *aemsgs, enum dep_check *ok,
  416. struct deppossi *breaks, struct pkginfo *broken,
  417. struct pkginfo *breaker, struct pkgset *virtbroken)
  418. {
  419. struct varbuf depmsg = VARBUF_INIT;
  420. debug(dbg_depcondetail, " checking breaker %s virtbroken %s",
  421. pkg_name(breaker, pnaw_always),
  422. virtbroken ? virtbroken->name : "<none>");
  423. if (breaker->status == PKG_STAT_NOTINSTALLED ||
  424. breaker->status == PKG_STAT_CONFIGFILES)
  425. return;
  426. if (broken == breaker) return;
  427. if (!versionsatisfied(&broken->installed, breaks)) return;
  428. /* The test below can only trigger if dep_breaks start having
  429. * arch qualifiers different from “any”. */
  430. if (!archsatisfied(&broken->installed, breaks))
  431. return;
  432. if (ignore_depends(breaker)) return;
  433. if (virtbroken && ignore_depends(&virtbroken->pkg))
  434. return;
  435. varbufdependency(&depmsg, breaks->up);
  436. varbuf_end_str(&depmsg);
  437. varbuf_printf(aemsgs, _(" %s (%s) breaks %s and is %s.\n"),
  438. pkg_name(breaker, pnaw_nonambig),
  439. versiondescribe(&breaker->installed.version, vdew_nonambig),
  440. depmsg.buf, gettext(statusstrings[breaker->status]));
  441. varbuf_destroy(&depmsg);
  442. if (virtbroken) {
  443. varbuf_printf(aemsgs, _(" %s (%s) provides %s.\n"),
  444. pkg_name(broken, pnaw_nonambig),
  445. versiondescribe(&broken->installed.version, vdew_nonambig),
  446. virtbroken->name);
  447. } else if (breaks->verrel != DPKG_RELATION_NONE) {
  448. varbuf_printf(aemsgs, _(" Version of %s to be configured is %s.\n"),
  449. pkg_name(broken, pnaw_nonambig),
  450. versiondescribe(&broken->installed.version, vdew_nonambig));
  451. if (fc_dependsversion) return;
  452. }
  453. if (force_breaks(breaks)) return;
  454. *ok = DEP_CHECK_HALT;
  455. }
  456. static void
  457. breaks_check_target(struct varbuf *aemsgs, enum dep_check *ok,
  458. struct pkginfo *broken, struct pkgset *target,
  459. struct pkgset *virtbroken)
  460. {
  461. struct deppossi *possi;
  462. for (possi = target->depended.installed; possi; possi = possi->rev_next) {
  463. if (possi->up->type != dep_breaks) continue;
  464. if (virtbroken && possi->verrel != DPKG_RELATION_NONE)
  465. continue;
  466. breaks_check_one(aemsgs, ok, possi, broken, possi->up->up, virtbroken);
  467. }
  468. }
  469. enum dep_check
  470. breakses_ok(struct pkginfo *pkg, struct varbuf *aemsgs)
  471. {
  472. struct dependency *dep;
  473. struct pkgset *virtbroken;
  474. enum dep_check ok = DEP_CHECK_OK;
  475. debug(dbg_depcon, " checking Breaks");
  476. breaks_check_target(aemsgs, &ok, pkg, pkg->set, NULL);
  477. for (dep= pkg->installed.depends; dep; dep= dep->next) {
  478. if (dep->type != dep_provides) continue;
  479. virtbroken = dep->list->ed;
  480. debug(dbg_depcondetail, " checking virtbroken %s", virtbroken->name);
  481. breaks_check_target(aemsgs, &ok, pkg, virtbroken, virtbroken);
  482. }
  483. return ok;
  484. }
  485. /*
  486. * Checks [Pre]-Depends only.
  487. */
  488. enum dep_check
  489. dependencies_ok(struct pkginfo *pkg, struct pkginfo *removing,
  490. struct varbuf *aemsgs)
  491. {
  492. /* Valid values: 2 = ok, 1 = defer, 0 = halt. */
  493. enum dep_check ok;
  494. /* Valid values: 0 = none, 1 = defer, 2 = withwarning, 3 = ok. */
  495. enum found_status found, thisf;
  496. int interestingwarnings;
  497. bool matched, anycannotfixbytrig;
  498. struct varbuf oemsgs = VARBUF_INIT;
  499. struct dependency *dep;
  500. struct deppossi *possi, *provider;
  501. struct pkginfo *possfixbytrig, *canfixbytrig;
  502. interestingwarnings= 0;
  503. ok = DEP_CHECK_OK;
  504. debug(dbg_depcon,"checking dependencies of %s (- %s)",
  505. pkg_name(pkg, pnaw_always),
  506. removing ? pkg_name(removing, pnaw_always) : "<none>");
  507. anycannotfixbytrig = false;
  508. canfixbytrig = NULL;
  509. for (dep= pkg->installed.depends; dep; dep= dep->next) {
  510. if (dep->type != dep_depends && dep->type != dep_predepends) continue;
  511. debug(dbg_depcondetail," checking group ...");
  512. matched = false;
  513. varbuf_reset(&oemsgs);
  514. found = FOUND_NONE;
  515. possfixbytrig = NULL;
  516. for (possi = dep->list; found != FOUND_OK && possi; possi = possi->next) {
  517. struct deppossi_pkg_iterator *possi_iter;
  518. struct pkginfo *pkg_pos;
  519. debug(dbg_depcondetail," checking possibility -> %s",possi->ed->name);
  520. if (possi->cyclebreak) {
  521. debug(dbg_depcondetail," break cycle so ok and found");
  522. found = FOUND_OK;
  523. break;
  524. }
  525. thisf = FOUND_NONE;
  526. possi_iter = deppossi_pkg_iter_new(possi, wpb_installed);
  527. while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
  528. thisf = deppossi_ok_found(pkg_pos, pkg, removing, NULL,
  529. &possfixbytrig, &matched, possi,
  530. &interestingwarnings, &oemsgs);
  531. if (thisf > found)
  532. found = thisf;
  533. if (found == FOUND_OK)
  534. break;
  535. }
  536. deppossi_pkg_iter_free(possi_iter);
  537. if (found != FOUND_OK && possi->verrel == DPKG_RELATION_NONE) {
  538. for (provider = possi->ed->depended.installed;
  539. found != FOUND_OK && provider;
  540. provider = provider->rev_next) {
  541. if (provider->up->type != dep_provides)
  542. continue;
  543. debug(dbg_depcondetail, " checking provider %s",
  544. pkg_name(provider->up->up, pnaw_always));
  545. if (!deparchsatisfied(&provider->up->up->installed, provider->arch,
  546. possi)) {
  547. debug(dbg_depcondetail, " provider does not satisfy arch");
  548. continue;
  549. }
  550. thisf = deppossi_ok_found(provider->up->up, pkg, removing,
  551. possi->ed,
  552. &possfixbytrig, &matched, NULL,
  553. &interestingwarnings, &oemsgs);
  554. if (thisf > found)
  555. found = thisf;
  556. }
  557. }
  558. debug(dbg_depcondetail," found %d",found);
  559. if (thisf > found) found= thisf;
  560. }
  561. if (fc_depends) {
  562. thisf = (dependtry >= 4) ? FOUND_FORCED : FOUND_DEFER;
  563. if (thisf > found) {
  564. found = thisf;
  565. debug(dbg_depcondetail, " rescued by force-depends, found %d", found);
  566. }
  567. }
  568. debug(dbg_depcondetail, " found %d matched %d possfixbytrig %s",
  569. found, matched,
  570. possfixbytrig ? pkg_name(possfixbytrig, pnaw_always) : "-");
  571. if (removing && !matched) continue;
  572. switch (found) {
  573. case FOUND_NONE:
  574. anycannotfixbytrig = true;
  575. ok = DEP_CHECK_HALT;
  576. /* Fall through. */
  577. case FOUND_FORCED:
  578. varbuf_add_str(aemsgs, " ");
  579. varbuf_add_pkgbin_name(aemsgs, pkg, &pkg->installed, pnaw_nonambig);
  580. varbuf_add_str(aemsgs, _(" depends on "));
  581. varbufdependency(aemsgs, dep);
  582. if (interestingwarnings) {
  583. /* Don't print the line about the package to be removed if
  584. * that's the only line. */
  585. varbuf_end_str(&oemsgs);
  586. varbuf_add_str(aemsgs, _("; however:\n"));
  587. varbuf_add_str(aemsgs, oemsgs.buf);
  588. } else {
  589. varbuf_add_str(aemsgs, ".\n");
  590. }
  591. break;
  592. case FOUND_DEFER:
  593. if (possfixbytrig)
  594. canfixbytrig = possfixbytrig;
  595. else
  596. anycannotfixbytrig = true;
  597. if (ok > DEP_CHECK_DEFER)
  598. ok = DEP_CHECK_DEFER;
  599. break;
  600. case FOUND_OK:
  601. break;
  602. default:
  603. internerr("unknown value for found '%d'", found);
  604. }
  605. }
  606. if (ok == DEP_CHECK_HALT &&
  607. (pkg->clientdata && pkg->clientdata->istobe == PKG_ISTOBE_REMOVE))
  608. ok = DEP_CHECK_DEFER;
  609. if (!anycannotfixbytrig && canfixbytrig)
  610. progress_bytrigproc = canfixbytrig;
  611. varbuf_destroy(&oemsgs);
  612. debug(dbg_depcon,"ok %d msgs >>%.*s<<", ok, (int)aemsgs->used, aemsgs->buf);
  613. return ok;
  614. }