packages.c 25 KB

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