packages.c 24 KB

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