depcon.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * dpkg - main program for package management
  3. * depcon.c - dependency and conflict checking
  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 <errno.h>
  29. #include <stdlib.h>
  30. #include <unistd.h>
  31. #include <dpkg/i18n.h>
  32. #include <dpkg/dpkg.h>
  33. #include <dpkg/dpkg-db.h>
  34. #include "filesdb.h"
  35. #include "infodb.h"
  36. #include "main.h"
  37. struct deppossi_pkg_iterator {
  38. struct deppossi *possi;
  39. struct pkginfo *pkg_next;
  40. enum which_pkgbin which_pkgbin;
  41. };
  42. struct deppossi_pkg_iterator *
  43. deppossi_pkg_iter_new(struct deppossi *possi, enum which_pkgbin wpb)
  44. {
  45. struct deppossi_pkg_iterator *iter;
  46. iter = m_malloc(sizeof(*iter));
  47. iter->possi = possi;
  48. iter->pkg_next = &possi->ed->pkg;
  49. iter->which_pkgbin = wpb;
  50. return iter;
  51. }
  52. struct pkginfo *
  53. deppossi_pkg_iter_next(struct deppossi_pkg_iterator *iter)
  54. {
  55. struct pkginfo *pkg_cur;
  56. struct pkgbin *pkgbin;
  57. while ((pkg_cur = iter->pkg_next)) {
  58. iter->pkg_next = pkg_cur->arch_next;
  59. switch (iter->which_pkgbin) {
  60. case wpb_installed:
  61. pkgbin = &pkg_cur->installed;
  62. break;
  63. case wpb_available:
  64. pkgbin = &pkg_cur->available;
  65. break;
  66. case wpb_by_istobe:
  67. if (pkg_cur->clientdata->istobe == PKG_ISTOBE_INSTALLNEW)
  68. pkgbin = &pkg_cur->available;
  69. else
  70. pkgbin = &pkg_cur->installed;
  71. break;
  72. default:
  73. internerr("unknown which_pkgbin %d", iter->which_pkgbin);
  74. }
  75. if (archsatisfied(pkgbin, iter->possi))
  76. return pkg_cur;
  77. }
  78. return NULL;
  79. }
  80. void
  81. deppossi_pkg_iter_free(struct deppossi_pkg_iterator *iter)
  82. {
  83. free(iter);
  84. }
  85. struct cyclesofarlink {
  86. struct cyclesofarlink *prev;
  87. struct pkginfo *pkg;
  88. struct deppossi *possi;
  89. };
  90. static bool findbreakcyclerecursive(struct pkginfo *pkg,
  91. struct cyclesofarlink *sofar);
  92. static bool
  93. foundcyclebroken(struct cyclesofarlink *thislink, struct cyclesofarlink *sofar,
  94. struct pkginfo *dependedon, struct deppossi *possi)
  95. {
  96. struct cyclesofarlink *sol;
  97. if(!possi)
  98. return false;
  99. /* We're investigating the dependency ‘possi’ to see if it
  100. * is part of a loop. To this end we look to see whether the
  101. * depended-on package is already one of the packages whose
  102. * dependencies we're searching. */
  103. for (sol = sofar; sol && sol->pkg != dependedon; sol = sol->prev);
  104. /* If not, we do a recursive search on it to see what we find. */
  105. if (!sol)
  106. return findbreakcyclerecursive(dependedon, thislink);
  107. debug(dbg_depcon,"found cycle");
  108. /* Right, we now break one of the links. We prefer to break
  109. * a dependency of a package without a postinst script, as
  110. * this is a null operation. If this is not possible we break
  111. * the other link in the recursive calling tree which mentions
  112. * this package (this being the first package involved in the
  113. * cycle). It doesn't particularly matter which we pick, but if
  114. * we break the earliest dependency we came across we may be
  115. * able to do something straight away when findbreakcycle returns. */
  116. sofar= thislink;
  117. for (sol = sofar; !(sol != sofar && sol->pkg == dependedon); sol = sol->prev) {
  118. if (!pkg_infodb_has_file(sol->pkg, &sol->pkg->installed, POSTINSTFILE))
  119. break;
  120. }
  121. /* Now we have either a package with no postinst, or the other
  122. * occurrence of the current package in the list. */
  123. sol->possi->cyclebreak = true;
  124. debug(dbg_depcon, "cycle broken at %s -> %s",
  125. pkg_name(sol->possi->up->up, pnaw_always), sol->possi->ed->name);
  126. return true;
  127. }
  128. /**
  129. * Cycle breaking works recursively down the package dependency tree.
  130. *
  131. * ‘sofar’ is the list of packages we've descended down already - if we
  132. * encounter any of its packages again in a dependency we have found a cycle.
  133. */
  134. static bool
  135. findbreakcyclerecursive(struct pkginfo *pkg, struct cyclesofarlink *sofar)
  136. {
  137. struct cyclesofarlink thislink, *sol;
  138. struct dependency *dep;
  139. struct deppossi *possi, *providelink;
  140. struct pkginfo *provider, *pkg_pos;
  141. if (pkg->clientdata->color == PKG_CYCLE_BLACK)
  142. return false;
  143. pkg->clientdata->color = PKG_CYCLE_GRAY;
  144. if (debug_has_flag(dbg_depcondetail)) {
  145. struct varbuf str_pkgs = VARBUF_INIT;
  146. for (sol = sofar; sol; sol = sol->prev) {
  147. varbuf_add_str(&str_pkgs, " <- ");
  148. varbuf_add_pkgbin_name(&str_pkgs, sol->pkg, &sol->pkg->installed, pnaw_nonambig);
  149. }
  150. varbuf_end_str(&str_pkgs);
  151. debug(dbg_depcondetail, "findbreakcyclerecursive %s %s",
  152. pkg_name(pkg, pnaw_always), str_pkgs.buf);
  153. varbuf_destroy(&str_pkgs);
  154. }
  155. thislink.pkg= pkg;
  156. thislink.prev = sofar;
  157. thislink.possi = NULL;
  158. for (dep= pkg->installed.depends; dep; dep= dep->next) {
  159. if (dep->type != dep_depends && dep->type != dep_predepends) continue;
  160. for (possi= dep->list; possi; possi= possi->next) {
  161. struct deppossi_pkg_iterator *possi_iter;
  162. /* Don't find the same cycles again. */
  163. if (possi->cyclebreak) continue;
  164. thislink.possi= possi;
  165. possi_iter = deppossi_pkg_iter_new(possi, wpb_installed);
  166. while ((pkg_pos = deppossi_pkg_iter_next(possi_iter)))
  167. if (foundcyclebroken(&thislink, sofar, pkg_pos, possi)) {
  168. deppossi_pkg_iter_free(possi_iter);
  169. return true;
  170. }
  171. deppossi_pkg_iter_free(possi_iter);
  172. /* Right, now we try all the providers ... */
  173. for (providelink = possi->ed->depended.installed;
  174. providelink;
  175. providelink = providelink->rev_next) {
  176. if (providelink->up->type != dep_provides) continue;
  177. provider= providelink->up->up;
  178. if (provider->clientdata->istobe == PKG_ISTOBE_NORMAL)
  179. continue;
  180. /* We don't break things at ‘provides’ links, so ‘possi’ is
  181. * still the one we use. */
  182. if (foundcyclebroken(&thislink, sofar, provider, possi))
  183. return true;
  184. }
  185. }
  186. }
  187. /* Nope, we didn't find a cycle to break. */
  188. pkg->clientdata->color = PKG_CYCLE_BLACK;
  189. return false;
  190. }
  191. bool
  192. findbreakcycle(struct pkginfo *pkg)
  193. {
  194. struct pkgiterator *iter;
  195. struct pkginfo *tpkg;
  196. /* Clear the visited flag of all packages before we traverse them. */
  197. iter = pkg_db_iter_new();
  198. while ((tpkg = pkg_db_iter_next_pkg(iter))) {
  199. ensure_package_clientdata(tpkg);
  200. tpkg->clientdata->color = PKG_CYCLE_WHITE;
  201. }
  202. pkg_db_iter_free(iter);
  203. return findbreakcyclerecursive(pkg, NULL);
  204. }
  205. void describedepcon(struct varbuf *addto, struct dependency *dep) {
  206. const char *fmt;
  207. struct varbuf depstr = VARBUF_INIT;
  208. switch (dep->type) {
  209. case dep_depends:
  210. fmt = _("%s depends on %s");
  211. break;
  212. case dep_predepends:
  213. fmt = _("%s pre-depends on %s");
  214. break;
  215. case dep_recommends:
  216. fmt = _("%s recommends %s");
  217. break;
  218. case dep_suggests:
  219. fmt = _("%s suggests %s");
  220. break;
  221. case dep_breaks:
  222. fmt = _("%s breaks %s");
  223. break;
  224. case dep_conflicts:
  225. fmt = _("%s conflicts with %s");
  226. break;
  227. case dep_enhances:
  228. fmt = _("%s enhances %s");
  229. break;
  230. default:
  231. internerr("unknown deptype '%d'", dep->type);
  232. }
  233. varbufdependency(&depstr, dep);
  234. varbuf_end_str(&depstr);
  235. varbuf_printf(addto, fmt, pkg_name(dep->up, pnaw_nonambig), depstr.buf);
  236. varbuf_destroy(&depstr);
  237. }
  238. /*
  239. * *whynot must already have been initialized; it need not be
  240. * empty though - it will be reset before use.
  241. *
  242. * If depisok returns false for ‘not OK’ it will contain a description,
  243. * newline-terminated BUT NOT NUL-TERMINATED, of the reason.
  244. *
  245. * If depisok returns true it will contain garbage.
  246. * allowunconfigd should be non-zero during the ‘Pre-Depends’ checking
  247. * before a package is unpacked, when it is sufficient for the package
  248. * to be unpacked provided that both the unpacked and previously-configured
  249. * versions are acceptable.
  250. *
  251. * On false return (‘not OK’), *canfixbyremove refers to a package which
  252. * if removed (dep_conflicts) or deconfigured (dep_breaks) will fix
  253. * the problem. Caller may pass NULL for canfixbyremove and need not
  254. * initialize *canfixbyremove.
  255. *
  256. * On false return (‘not OK’), *canfixbytrigaw refers to a package which
  257. * can fix the problem if all the packages listed in Triggers-Awaited have
  258. * their triggers processed. Caller may pass NULL for canfixbytrigaw and
  259. * need not initialize *canfixbytrigaw.
  260. */
  261. bool
  262. depisok(struct dependency *dep, struct varbuf *whynot,
  263. struct pkginfo **canfixbyremove, struct pkginfo **canfixbytrigaw,
  264. bool allowunconfigd)
  265. {
  266. struct deppossi *possi;
  267. struct deppossi *provider;
  268. struct pkginfo *pkg_pos;
  269. int nconflicts;
  270. /* Use this buffer so that when internationalisation comes along we
  271. * don't have to rewrite the code completely, only redo the sprintf strings
  272. * (assuming we have the fancy argument-number-specifiers).
  273. * Allow 250x3 for package names, versions, &c, + 250 for ourselves. */
  274. char linebuf[1024];
  275. assert(dep->type == dep_depends || dep->type == dep_predepends ||
  276. dep->type == dep_breaks || dep->type == dep_conflicts ||
  277. dep->type == dep_recommends || dep->type == dep_suggests ||
  278. dep->type == dep_enhances);
  279. if (canfixbyremove)
  280. *canfixbyremove = NULL;
  281. if (canfixbytrigaw)
  282. *canfixbytrigaw = NULL;
  283. /* The dependency is always OK if we're trying to remove the depend*ing*
  284. * package. */
  285. switch (dep->up->clientdata->istobe) {
  286. case PKG_ISTOBE_REMOVE:
  287. case PKG_ISTOBE_DECONFIGURE:
  288. return true;
  289. case PKG_ISTOBE_NORMAL:
  290. /* Only installed packages can be make dependency problems. */
  291. switch (dep->up->status) {
  292. case PKG_STAT_INSTALLED:
  293. case PKG_STAT_TRIGGERSPENDING:
  294. case PKG_STAT_TRIGGERSAWAITED:
  295. break;
  296. case PKG_STAT_HALFCONFIGURED:
  297. case PKG_STAT_UNPACKED:
  298. case PKG_STAT_HALFINSTALLED:
  299. if (dep->type == dep_predepends ||
  300. dep->type == dep_conflicts ||
  301. dep->type == dep_breaks)
  302. break;
  303. /* Fall through. */
  304. case PKG_STAT_CONFIGFILES:
  305. case PKG_STAT_NOTINSTALLED:
  306. return true;
  307. default:
  308. internerr("unknown status depending '%d'", dep->up->status);
  309. }
  310. break;
  311. case PKG_ISTOBE_INSTALLNEW:
  312. case PKG_ISTOBE_PREINSTALL:
  313. break;
  314. default:
  315. internerr("unknown istobe depending '%d'", dep->up->clientdata->istobe);
  316. }
  317. /* Describe the dependency, in case we have to moan about it. */
  318. varbuf_reset(whynot);
  319. varbuf_add_char(whynot, ' ');
  320. describedepcon(whynot, dep);
  321. varbuf_add_char(whynot, '\n');
  322. /* TODO: Check dep_enhances as well. */
  323. if (dep->type == dep_depends || dep->type == dep_predepends ||
  324. dep->type == dep_recommends || dep->type == dep_suggests ) {
  325. /* Go through the alternatives. As soon as we find one that
  326. * we like, we return ‘true’ straight away. Otherwise, when we get to
  327. * the end we'll have accumulated all the reasons in whynot and
  328. * can return ‘false’. */
  329. for (possi= dep->list; possi; possi= possi->next) {
  330. struct deppossi_pkg_iterator *possi_iter;
  331. possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
  332. while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
  333. switch (pkg_pos->clientdata->istobe) {
  334. case PKG_ISTOBE_REMOVE:
  335. sprintf(linebuf, _(" %.250s is to be removed.\n"),
  336. pkg_name(pkg_pos, pnaw_nonambig));
  337. break;
  338. case PKG_ISTOBE_DECONFIGURE:
  339. sprintf(linebuf, _(" %.250s is to be deconfigured.\n"),
  340. pkg_name(pkg_pos, pnaw_nonambig));
  341. break;
  342. case PKG_ISTOBE_INSTALLNEW:
  343. if (versionsatisfied(&pkg_pos->available, possi)) {
  344. deppossi_pkg_iter_free(possi_iter);
  345. return true;
  346. }
  347. sprintf(linebuf, _(" %.250s is to be installed, but is version "
  348. "%.250s.\n"),
  349. pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
  350. versiondescribe(&pkg_pos->available.version, vdew_nonambig));
  351. break;
  352. case PKG_ISTOBE_NORMAL:
  353. case PKG_ISTOBE_PREINSTALL:
  354. switch (pkg_pos->status) {
  355. case PKG_STAT_INSTALLED:
  356. case PKG_STAT_TRIGGERSPENDING:
  357. if (versionsatisfied(&pkg_pos->installed, possi)) {
  358. deppossi_pkg_iter_free(possi_iter);
  359. return true;
  360. }
  361. sprintf(linebuf, _(" %.250s is installed, but is version "
  362. "%.250s.\n"),
  363. pkg_name(pkg_pos, pnaw_nonambig),
  364. versiondescribe(&pkg_pos->installed.version, vdew_nonambig));
  365. break;
  366. case PKG_STAT_NOTINSTALLED:
  367. /* Don't say anything about this yet - it might be a virtual package.
  368. * Later on, if nothing has put anything in linebuf, we know that it
  369. * isn't and issue a diagnostic then. */
  370. *linebuf = '\0';
  371. break;
  372. case PKG_STAT_TRIGGERSAWAITED:
  373. if (canfixbytrigaw && versionsatisfied(&pkg_pos->installed, possi))
  374. *canfixbytrigaw = pkg_pos;
  375. /* Fall through. */
  376. case PKG_STAT_UNPACKED:
  377. case PKG_STAT_HALFCONFIGURED:
  378. if (allowunconfigd) {
  379. if (!dpkg_version_is_informative(&pkg_pos->configversion)) {
  380. sprintf(linebuf, _(" %.250s is unpacked, but has never been "
  381. "configured.\n"),
  382. pkg_name(pkg_pos, pnaw_nonambig));
  383. break;
  384. } else if (!versionsatisfied(&pkg_pos->installed, possi)) {
  385. sprintf(linebuf, _(" %.250s is unpacked, but is version "
  386. "%.250s.\n"),
  387. pkg_name(pkg_pos, pnaw_nonambig),
  388. versiondescribe(&pkg_pos->installed.version,
  389. vdew_nonambig));
  390. break;
  391. } else if (!dpkg_version_relate(&pkg_pos->configversion,
  392. possi->verrel,
  393. &possi->version)) {
  394. sprintf(linebuf, _(" %.250s latest configured version is "
  395. "%.250s.\n"),
  396. pkg_name(pkg_pos, pnaw_nonambig),
  397. versiondescribe(&pkg_pos->configversion, vdew_nonambig));
  398. break;
  399. } else {
  400. deppossi_pkg_iter_free(possi_iter);
  401. return true;
  402. }
  403. }
  404. /* Fall through. */
  405. default:
  406. sprintf(linebuf, _(" %.250s is %s.\n"),
  407. pkg_name(pkg_pos, pnaw_nonambig),
  408. gettext(statusstrings[pkg_pos->status]));
  409. break;
  410. }
  411. break;
  412. default:
  413. internerr("unknown istobe depended '%d'", pkg_pos->clientdata->istobe);
  414. }
  415. varbuf_add_str(whynot, linebuf);
  416. }
  417. deppossi_pkg_iter_free(possi_iter);
  418. /* See if the package we're about to install Provides it. */
  419. for (provider = possi->ed->depended.available;
  420. provider;
  421. provider = provider->rev_next) {
  422. if (provider->up->type != dep_provides) continue;
  423. if (!pkg_virtual_deppossi_satisfied(possi, provider))
  424. continue;
  425. if (provider->up->up->clientdata->istobe == PKG_ISTOBE_INSTALLNEW)
  426. return true;
  427. }
  428. /* Now look at the packages already on the system. */
  429. for (provider = possi->ed->depended.installed;
  430. provider;
  431. provider = provider->rev_next) {
  432. if (provider->up->type != dep_provides) continue;
  433. if (!pkg_virtual_deppossi_satisfied(possi, provider))
  434. continue;
  435. switch (provider->up->up->clientdata->istobe) {
  436. case PKG_ISTOBE_INSTALLNEW:
  437. /* Don't pay any attention to the Provides field of the
  438. * currently-installed version of the package we're trying
  439. * to install. We dealt with that by using the available
  440. * information above. */
  441. continue;
  442. case PKG_ISTOBE_REMOVE:
  443. sprintf(linebuf, _(" %.250s provides %.250s but is to be removed.\n"),
  444. pkg_name(provider->up->up, pnaw_nonambig),
  445. possi->ed->name);
  446. break;
  447. case PKG_ISTOBE_DECONFIGURE:
  448. sprintf(linebuf, _(" %.250s provides %.250s but is to be deconfigured.\n"),
  449. pkg_name(provider->up->up, pnaw_nonambig),
  450. possi->ed->name);
  451. break;
  452. case PKG_ISTOBE_NORMAL:
  453. case PKG_ISTOBE_PREINSTALL:
  454. if (provider->up->up->status == PKG_STAT_INSTALLED ||
  455. provider->up->up->status == PKG_STAT_TRIGGERSPENDING)
  456. return true;
  457. if (provider->up->up->status == PKG_STAT_TRIGGERSAWAITED)
  458. *canfixbytrigaw = provider->up->up;
  459. sprintf(linebuf, _(" %.250s provides %.250s but is %s.\n"),
  460. pkg_name(provider->up->up, pnaw_nonambig),
  461. possi->ed->name,
  462. gettext(statusstrings[provider->up->up->status]));
  463. break;
  464. default:
  465. internerr("unknown istobe provider '%d'",
  466. provider->up->up->clientdata->istobe);
  467. }
  468. varbuf_add_str(whynot, linebuf);
  469. }
  470. if (!*linebuf) {
  471. /* If the package wasn't installed at all, and we haven't said
  472. * yet why this isn't satisfied, we should say so now. */
  473. sprintf(linebuf, _(" %.250s is not installed.\n"), possi->ed->name);
  474. varbuf_add_str(whynot, linebuf);
  475. }
  476. }
  477. return false;
  478. } else {
  479. /* It's conflicts or breaks. There's only one main alternative,
  480. * but we also have to consider Providers. We return ‘false’ as soon
  481. * as we find something that matches the conflict, and only describe
  482. * it then. If we get to the end without finding anything we return
  483. * ‘true’. */
  484. possi= dep->list;
  485. nconflicts= 0;
  486. if (possi->ed != possi->up->up->set) {
  487. struct deppossi_pkg_iterator *possi_iter;
  488. /* If the package conflicts with or breaks itself it must mean
  489. * other packages which provide the same virtual name. We
  490. * therefore don't look at the real package and go on to the
  491. * virtual ones. */
  492. possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
  493. while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
  494. switch (pkg_pos->clientdata->istobe) {
  495. case PKG_ISTOBE_REMOVE:
  496. break;
  497. case PKG_ISTOBE_INSTALLNEW:
  498. if (!versionsatisfied(&pkg_pos->available, possi))
  499. break;
  500. sprintf(linebuf, _(" %.250s (version %.250s) is to be installed.\n"),
  501. pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
  502. versiondescribe(&pkg_pos->available.version, vdew_nonambig));
  503. varbuf_add_str(whynot, linebuf);
  504. if (!canfixbyremove) {
  505. deppossi_pkg_iter_free(possi_iter);
  506. return false;
  507. }
  508. nconflicts++;
  509. *canfixbyremove = pkg_pos;
  510. break;
  511. case PKG_ISTOBE_DECONFIGURE:
  512. if (dep->type == dep_breaks)
  513. break; /* Already deconfiguring this. */
  514. /* Fall through. */
  515. case PKG_ISTOBE_NORMAL:
  516. case PKG_ISTOBE_PREINSTALL:
  517. switch (pkg_pos->status) {
  518. case PKG_STAT_NOTINSTALLED:
  519. case PKG_STAT_CONFIGFILES:
  520. break;
  521. case PKG_STAT_HALFINSTALLED:
  522. case PKG_STAT_UNPACKED:
  523. case PKG_STAT_HALFCONFIGURED:
  524. if (dep->type == dep_breaks)
  525. break; /* No problem. */
  526. /* Fall through. */
  527. case PKG_STAT_INSTALLED:
  528. case PKG_STAT_TRIGGERSPENDING:
  529. case PKG_STAT_TRIGGERSAWAITED:
  530. if (!versionsatisfied(&pkg_pos->installed, possi))
  531. break;
  532. sprintf(linebuf, _(" %.250s (version %.250s) is present and %s.\n"),
  533. pkg_name(pkg_pos, pnaw_nonambig),
  534. versiondescribe(&pkg_pos->installed.version, vdew_nonambig),
  535. gettext(statusstrings[pkg_pos->status]));
  536. varbuf_add_str(whynot, linebuf);
  537. if (!canfixbyremove) {
  538. deppossi_pkg_iter_free(possi_iter);
  539. return false;
  540. }
  541. nconflicts++;
  542. *canfixbyremove = pkg_pos;
  543. }
  544. break;
  545. default:
  546. internerr("unknown istobe conflict '%d'", pkg_pos->clientdata->istobe);
  547. }
  548. }
  549. deppossi_pkg_iter_free(possi_iter);
  550. }
  551. /* See if the package we're about to install Provides it. */
  552. for (provider = possi->ed->depended.available;
  553. provider;
  554. provider = provider->rev_next) {
  555. if (provider->up->type != dep_provides) continue;
  556. if (provider->up->up->clientdata->istobe != PKG_ISTOBE_INSTALLNEW)
  557. continue;
  558. if (provider->up->up->set == dep->up->set)
  559. continue; /* Conflicts and provides the same. */
  560. if (!pkg_virtual_deppossi_satisfied(possi, provider))
  561. continue;
  562. sprintf(linebuf, _(" %.250s provides %.250s and is to be installed.\n"),
  563. pkgbin_name(provider->up->up, &provider->up->up->available,
  564. pnaw_nonambig), possi->ed->name);
  565. varbuf_add_str(whynot, linebuf);
  566. /* We can't remove the one we're about to install: */
  567. if (canfixbyremove)
  568. *canfixbyremove = NULL;
  569. return false;
  570. }
  571. /* Now look at the packages already on the system. */
  572. for (provider = possi->ed->depended.installed;
  573. provider;
  574. provider = provider->rev_next) {
  575. if (provider->up->type != dep_provides) continue;
  576. if (provider->up->up->set == dep->up->set)
  577. continue; /* Conflicts and provides the same. */
  578. if (!pkg_virtual_deppossi_satisfied(possi, provider))
  579. continue;
  580. switch (provider->up->up->clientdata->istobe) {
  581. case PKG_ISTOBE_INSTALLNEW:
  582. /* Don't pay any attention to the Provides field of the
  583. * currently-installed version of the package we're trying
  584. * to install. We dealt with that package by using the
  585. * available information above. */
  586. continue;
  587. case PKG_ISTOBE_REMOVE:
  588. continue;
  589. case PKG_ISTOBE_DECONFIGURE:
  590. if (dep->type == dep_breaks)
  591. continue; /* Already deconfiguring. */
  592. /* Fall through. */
  593. case PKG_ISTOBE_NORMAL:
  594. case PKG_ISTOBE_PREINSTALL:
  595. switch (provider->up->up->status) {
  596. case PKG_STAT_NOTINSTALLED:
  597. case PKG_STAT_CONFIGFILES:
  598. continue;
  599. case PKG_STAT_HALFINSTALLED:
  600. case PKG_STAT_UNPACKED:
  601. case PKG_STAT_HALFCONFIGURED:
  602. if (dep->type == dep_breaks)
  603. break; /* No problem. */
  604. /* Fall through. */
  605. case PKG_STAT_INSTALLED:
  606. case PKG_STAT_TRIGGERSPENDING:
  607. case PKG_STAT_TRIGGERSAWAITED:
  608. sprintf(linebuf,
  609. _(" %.250s provides %.250s and is present and %s.\n"),
  610. pkg_name(provider->up->up, pnaw_nonambig), possi->ed->name,
  611. gettext(statusstrings[provider->up->up->status]));
  612. varbuf_add_str(whynot, linebuf);
  613. if (!canfixbyremove)
  614. return false;
  615. nconflicts++;
  616. *canfixbyremove= provider->up->up;
  617. break;
  618. }
  619. break;
  620. default:
  621. internerr("unknown istobe conflict provider '%d'",
  622. provider->up->up->clientdata->istobe);
  623. }
  624. }
  625. if (!nconflicts)
  626. return true;
  627. if (nconflicts > 1)
  628. *canfixbyremove = NULL;
  629. return false;
  630. } /* if (dependency) {...} else {...} */
  631. }