depcon.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * dpkg - main program for package management
  3. * depcon.c - dependency and conflict checking
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2006-2011 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 <http://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 == itb_installnew)
  68. pkgbin = &pkg_cur->available;
  69. else
  70. pkgbin = &pkg_cur->installed;
  71. break;
  72. default:
  73. internerr("bad value (%d) for wpb in deppossi_pkg_iter_next()",
  74. iter->which_pkgbin);
  75. }
  76. if (archsatisfied(pkgbin, iter->possi))
  77. return pkg_cur;
  78. }
  79. return NULL;
  80. }
  81. void
  82. deppossi_pkg_iter_free(struct deppossi_pkg_iterator *iter)
  83. {
  84. free(iter);
  85. }
  86. struct cyclesofarlink {
  87. struct cyclesofarlink *prev;
  88. struct pkginfo *pkg;
  89. struct deppossi *possi;
  90. };
  91. static bool findbreakcyclerecursive(struct pkginfo *pkg,
  92. struct cyclesofarlink *sofar);
  93. static bool
  94. foundcyclebroken(struct cyclesofarlink *thislink, struct cyclesofarlink *sofar,
  95. struct pkginfo *dependedon, struct deppossi *possi)
  96. {
  97. struct cyclesofarlink *sol;
  98. if(!possi)
  99. return false;
  100. /* We're investigating the dependency ‘possi’ to see if it
  101. * is part of a loop. To this end we look to see whether the
  102. * depended-on package is already one of the packages whose
  103. * dependencies we're searching. */
  104. for (sol = sofar; sol && sol->pkg != dependedon; sol = sol->prev);
  105. /* If not, we do a recursive search on it to see what we find. */
  106. if (!sol)
  107. return findbreakcyclerecursive(dependedon, thislink);
  108. debug(dbg_depcon,"found cycle");
  109. /* Right, we now break one of the links. We prefer to break
  110. * a dependency of a package without a postinst script, as
  111. * this is a null operation. If this is not possible we break
  112. * the other link in the recursive calling tree which mentions
  113. * this package (this being the first package involved in the
  114. * cycle). It doesn't particularly matter which we pick, but if
  115. * we break the earliest dependency we came across we may be
  116. * able to do something straight away when findbreakcycle returns. */
  117. sofar= thislink;
  118. for (sol = sofar; !(sol != sofar && sol->pkg == dependedon); sol = sol->prev) {
  119. if (!pkg_infodb_has_file(sol->pkg, &sol->pkg->installed, POSTINSTFILE))
  120. break;
  121. }
  122. /* Now we have either a package with no postinst, or the other
  123. * occurrence of the current package in the list. */
  124. sol->possi->cyclebreak = true;
  125. debug(dbg_depcon, "cycle broken at %s -> %s",
  126. pkg_name(sol->possi->up->up, pnaw_nonambig), sol->possi->ed->name);
  127. return true;
  128. }
  129. /**
  130. * Cycle breaking works recursively down the package dependency tree.
  131. *
  132. * ‘sofar’ is the list of packages we've descended down already - if we
  133. * encounter any of its packages again in a dependency we have found a cycle.
  134. */
  135. static bool
  136. findbreakcyclerecursive(struct pkginfo *pkg, struct cyclesofarlink *sofar)
  137. {
  138. struct cyclesofarlink thislink, *sol;
  139. struct dependency *dep;
  140. struct deppossi *possi, *providelink;
  141. struct pkginfo *provider, *pkg_pos;
  142. if (pkg->clientdata->color == black)
  143. return false;
  144. pkg->clientdata->color = gray;
  145. if (debug_has_flag(dbg_depcondetail)) {
  146. struct varbuf str_pkgs = VARBUF_INIT;
  147. for (sol = sofar; sol; sol = sol->prev) {
  148. varbuf_add_str(&str_pkgs, " <- ");
  149. varbuf_add_pkgbin_name(&str_pkgs, sol->pkg, &sol->pkg->installed, pnaw_nonambig);
  150. }
  151. varbuf_end_str(&str_pkgs);
  152. debug(dbg_depcondetail, "findbreakcyclerecursive %s %s",
  153. pkg_name(pkg, pnaw_nonambig), str_pkgs.buf);
  154. varbuf_destroy(&str_pkgs);
  155. }
  156. thislink.pkg= pkg;
  157. thislink.prev = sofar;
  158. thislink.possi = NULL;
  159. for (dep= pkg->installed.depends; dep; dep= dep->next) {
  160. if (dep->type != dep_depends && dep->type != dep_predepends) continue;
  161. for (possi= dep->list; possi; possi= possi->next) {
  162. struct deppossi_pkg_iterator *possi_iter;
  163. /* Don't find the same cycles again. */
  164. if (possi->cyclebreak) continue;
  165. thislink.possi= possi;
  166. possi_iter = deppossi_pkg_iter_new(possi, wpb_installed);
  167. while ((pkg_pos = deppossi_pkg_iter_next(possi_iter)))
  168. if (foundcyclebroken(&thislink, sofar, pkg_pos, possi)) {
  169. deppossi_pkg_iter_free(possi_iter);
  170. return true;
  171. }
  172. deppossi_pkg_iter_free(possi_iter);
  173. /* Right, now we try all the providers ... */
  174. for (providelink = possi->ed->depended.installed;
  175. providelink;
  176. providelink = providelink->rev_next) {
  177. if (providelink->up->type != dep_provides) continue;
  178. provider= providelink->up->up;
  179. if (provider->clientdata->istobe == itb_normal) 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 = 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 = 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 itb_remove: case itb_deconfigure:
  287. return true;
  288. case itb_normal:
  289. /* Only installed packages can be make dependency problems. */
  290. switch (dep->up->status) {
  291. case stat_installed:
  292. case stat_triggerspending:
  293. case stat_triggersawaited:
  294. break;
  295. case stat_notinstalled: case stat_configfiles: case stat_halfinstalled:
  296. case stat_halfconfigured: case stat_unpacked:
  297. return true;
  298. default:
  299. internerr("unknown status depending '%d'", dep->up->status);
  300. }
  301. break;
  302. case itb_installnew: case itb_preinstall:
  303. break;
  304. default:
  305. internerr("unknown istobe depending '%d'", dep->up->clientdata->istobe);
  306. }
  307. /* Describe the dependency, in case we have to moan about it. */
  308. varbuf_reset(whynot);
  309. varbuf_add_char(whynot, ' ');
  310. describedepcon(whynot, dep);
  311. varbuf_add_char(whynot, '\n');
  312. /* TODO: Check dep_enhances as well. */
  313. if (dep->type == dep_depends || dep->type == dep_predepends ||
  314. dep->type == dep_recommends || dep->type == dep_suggests ) {
  315. /* Go through the alternatives. As soon as we find one that
  316. * we like, we return ‘true’ straight away. Otherwise, when we get to
  317. * the end we'll have accumulated all the reasons in whynot and
  318. * can return ‘false’. */
  319. for (possi= dep->list; possi; possi= possi->next) {
  320. struct deppossi_pkg_iterator *possi_iter;
  321. possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
  322. while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
  323. switch (pkg_pos->clientdata->istobe) {
  324. case itb_remove:
  325. sprintf(linebuf, _(" %.250s is to be removed.\n"),
  326. pkg_name(pkg_pos, pnaw_nonambig));
  327. break;
  328. case itb_deconfigure:
  329. sprintf(linebuf, _(" %.250s is to be deconfigured.\n"),
  330. pkg_name(pkg_pos, pnaw_nonambig));
  331. break;
  332. case itb_installnew:
  333. if (versionsatisfied(&pkg_pos->available, possi)) {
  334. deppossi_pkg_iter_free(possi_iter);
  335. return true;
  336. }
  337. sprintf(linebuf, _(" %.250s is to be installed, but is version "
  338. "%.250s.\n"),
  339. pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
  340. versiondescribe(&pkg_pos->available.version, vdew_nonambig));
  341. break;
  342. case itb_normal:
  343. case itb_preinstall:
  344. switch (pkg_pos->status) {
  345. case stat_installed:
  346. case stat_triggerspending:
  347. if (versionsatisfied(&pkg_pos->installed, possi)) {
  348. deppossi_pkg_iter_free(possi_iter);
  349. return true;
  350. }
  351. sprintf(linebuf, _(" %.250s is installed, but is version "
  352. "%.250s.\n"),
  353. pkg_name(pkg_pos, pnaw_nonambig),
  354. versiondescribe(&pkg_pos->installed.version, vdew_nonambig));
  355. break;
  356. case stat_notinstalled:
  357. /* Don't say anything about this yet - it might be a virtual package.
  358. * Later on, if nothing has put anything in linebuf, we know that it
  359. * isn't and issue a diagnostic then. */
  360. *linebuf = '\0';
  361. break;
  362. case stat_triggersawaited:
  363. if (canfixbytrigaw && versionsatisfied(&pkg_pos->installed, possi))
  364. *canfixbytrigaw = pkg_pos;
  365. /* Fall through to have a chance to return OK due to
  366. * allowunconfigd and to fill the explanation */
  367. case stat_unpacked:
  368. case stat_halfconfigured:
  369. if (allowunconfigd) {
  370. if (!informativeversion(&pkg_pos->configversion)) {
  371. sprintf(linebuf, _(" %.250s is unpacked, but has never been "
  372. "configured.\n"),
  373. pkg_name(pkg_pos, pnaw_nonambig));
  374. break;
  375. } else if (!versionsatisfied(&pkg_pos->installed, possi)) {
  376. sprintf(linebuf, _(" %.250s is unpacked, but is version "
  377. "%.250s.\n"),
  378. pkg_name(pkg_pos, pnaw_nonambig),
  379. versiondescribe(&pkg_pos->installed.version,
  380. vdew_nonambig));
  381. break;
  382. } else if (!versionsatisfied3(&pkg_pos->configversion,
  383. &possi->version, possi->verrel)) {
  384. sprintf(linebuf, _(" %.250s latest configured version is "
  385. "%.250s.\n"),
  386. pkg_name(pkg_pos, pnaw_nonambig),
  387. versiondescribe(&pkg_pos->configversion, vdew_nonambig));
  388. break;
  389. } else {
  390. deppossi_pkg_iter_free(possi_iter);
  391. return true;
  392. }
  393. }
  394. /* Fall through. */
  395. default:
  396. sprintf(linebuf, _(" %.250s is %s.\n"),
  397. pkg_name(pkg_pos, pnaw_nonambig),
  398. gettext(statusstrings[pkg_pos->status]));
  399. break;
  400. }
  401. break;
  402. default:
  403. internerr("unknown istobe depended '%d'", pkg_pos->clientdata->istobe);
  404. }
  405. varbuf_add_str(whynot, linebuf);
  406. }
  407. deppossi_pkg_iter_free(possi_iter);
  408. /* If there was no version specified we try looking for Providers. */
  409. if (possi->verrel == dvr_none) {
  410. /* See if the package we're about to install Provides it. */
  411. for (provider = possi->ed->depended.available;
  412. provider;
  413. provider = provider->rev_next) {
  414. if (provider->up->type != dep_provides) continue;
  415. if (provider->up->up->clientdata->istobe == itb_installnew)
  416. return true;
  417. }
  418. /* Now look at the packages already on the system. */
  419. for (provider = possi->ed->depended.installed;
  420. provider;
  421. provider = provider->rev_next) {
  422. if (provider->up->type != dep_provides) continue;
  423. switch (provider->up->up->clientdata->istobe) {
  424. case itb_installnew:
  425. /* Don't pay any attention to the Provides field of the
  426. * currently-installed version of the package we're trying
  427. * to install. We dealt with that by using the available
  428. * information above. */
  429. continue;
  430. case itb_remove:
  431. sprintf(linebuf, _(" %.250s provides %.250s but is to be removed.\n"),
  432. pkg_name(provider->up->up, pnaw_nonambig),
  433. possi->ed->name);
  434. break;
  435. case itb_deconfigure:
  436. sprintf(linebuf, _(" %.250s provides %.250s but is to be deconfigured.\n"),
  437. pkg_name(provider->up->up, pnaw_nonambig),
  438. possi->ed->name);
  439. break;
  440. case itb_normal: case itb_preinstall:
  441. if (provider->up->up->status == stat_installed ||
  442. provider->up->up->status == stat_triggerspending)
  443. return true;
  444. if (provider->up->up->status == stat_triggersawaited)
  445. *canfixbytrigaw = provider->up->up;
  446. sprintf(linebuf, _(" %.250s provides %.250s but is %s.\n"),
  447. pkg_name(provider->up->up, pnaw_nonambig),
  448. possi->ed->name,
  449. gettext(statusstrings[provider->up->up->status]));
  450. break;
  451. default:
  452. internerr("unknown istobe provider '%d'",
  453. provider->up->up->clientdata->istobe);
  454. }
  455. varbuf_add_str(whynot, linebuf);
  456. }
  457. if (!*linebuf) {
  458. /* If the package wasn't installed at all, and we haven't said
  459. * yet why this isn't satisfied, we should say so now. */
  460. sprintf(linebuf, _(" %.250s is not installed.\n"), possi->ed->name);
  461. varbuf_add_str(whynot, linebuf);
  462. }
  463. }
  464. }
  465. return false;
  466. } else {
  467. /* It's conflicts or breaks. There's only one main alternative,
  468. * but we also have to consider Providers. We return ‘false’ as soon
  469. * as we find something that matches the conflict, and only describe
  470. * it then. If we get to the end without finding anything we return
  471. * ‘true’. */
  472. possi= dep->list;
  473. nconflicts= 0;
  474. if (possi->ed != possi->up->up->set) {
  475. struct deppossi_pkg_iterator *possi_iter;
  476. /* If the package conflicts with or breaks itself it must mean
  477. * other packages which provide the same virtual name. We
  478. * therefore don't look at the real package and go on to the
  479. * virtual ones. */
  480. possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
  481. while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
  482. switch (pkg_pos->clientdata->istobe) {
  483. case itb_remove:
  484. break;
  485. case itb_installnew:
  486. if (!versionsatisfied(&pkg_pos->available, possi))
  487. break;
  488. sprintf(linebuf, _(" %.250s (version %.250s) is to be installed.\n"),
  489. pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
  490. versiondescribe(&pkg_pos->available.version, vdew_nonambig));
  491. varbuf_add_str(whynot, linebuf);
  492. if (!canfixbyremove) {
  493. deppossi_pkg_iter_free(possi_iter);
  494. return false;
  495. }
  496. nconflicts++;
  497. *canfixbyremove = pkg_pos;
  498. break;
  499. case itb_deconfigure:
  500. if (dep->type == dep_breaks)
  501. break; /* Already deconfiguring this. */
  502. /* Fall through. */
  503. case itb_normal:
  504. case itb_preinstall:
  505. switch (pkg_pos->status) {
  506. case stat_notinstalled:
  507. case stat_configfiles:
  508. break;
  509. case stat_halfinstalled:
  510. case stat_unpacked:
  511. case stat_halfconfigured:
  512. if (dep->type == dep_breaks)
  513. break; /* No problem. */
  514. case stat_installed:
  515. case stat_triggerspending:
  516. case stat_triggersawaited:
  517. if (!versionsatisfied(&pkg_pos->installed, possi))
  518. break;
  519. sprintf(linebuf, _(" %.250s (version %.250s) is present and %s.\n"),
  520. pkg_name(pkg_pos, pnaw_nonambig),
  521. versiondescribe(&pkg_pos->installed.version, vdew_nonambig),
  522. gettext(statusstrings[pkg_pos->status]));
  523. varbuf_add_str(whynot, linebuf);
  524. if (!canfixbyremove) {
  525. deppossi_pkg_iter_free(possi_iter);
  526. return false;
  527. }
  528. nconflicts++;
  529. *canfixbyremove = pkg_pos;
  530. }
  531. break;
  532. default:
  533. internerr("unknown istobe conflict '%d'", pkg_pos->clientdata->istobe);
  534. }
  535. }
  536. deppossi_pkg_iter_free(possi_iter);
  537. }
  538. /* If there was no version specified we try looking for Providers. */
  539. if (possi->verrel == dvr_none) {
  540. /* See if the package we're about to install Provides it. */
  541. for (provider = possi->ed->depended.available;
  542. provider;
  543. provider = provider->rev_next) {
  544. if (provider->up->type != dep_provides) continue;
  545. if (provider->up->up->clientdata->istobe != itb_installnew) continue;
  546. if (provider->up->up->set == dep->up->set)
  547. continue; /* Conflicts and provides the same. */
  548. sprintf(linebuf, _(" %.250s provides %.250s and is to be installed.\n"),
  549. pkgbin_name(provider->up->up, &provider->up->up->available,
  550. pnaw_nonambig), possi->ed->name);
  551. varbuf_add_str(whynot, linebuf);
  552. /* We can't remove the one we're about to install: */
  553. if (canfixbyremove)
  554. *canfixbyremove = NULL;
  555. return false;
  556. }
  557. /* Now look at the packages already on the system. */
  558. for (provider = possi->ed->depended.installed;
  559. provider;
  560. provider = provider->rev_next) {
  561. if (provider->up->type != dep_provides) continue;
  562. if (provider->up->up->set == dep->up->set)
  563. continue; /* Conflicts and provides the same. */
  564. switch (provider->up->up->clientdata->istobe) {
  565. case itb_installnew:
  566. /* Don't pay any attention to the Provides field of the
  567. * currently-installed version of the package we're trying
  568. * to install. We dealt with that package by using the
  569. * available information above. */
  570. continue;
  571. case itb_remove:
  572. continue;
  573. case itb_deconfigure:
  574. if (dep->type == dep_breaks)
  575. continue; /* Already deconfiguring. */
  576. case itb_normal: case itb_preinstall:
  577. switch (provider->up->up->status) {
  578. case stat_notinstalled: case stat_configfiles:
  579. continue;
  580. case stat_halfinstalled: case stat_unpacked:
  581. case stat_halfconfigured:
  582. if (dep->type == dep_breaks)
  583. break; /* No problem. */
  584. case stat_installed:
  585. case stat_triggerspending:
  586. case stat_triggersawaited:
  587. sprintf(linebuf,
  588. _(" %.250s provides %.250s and is present and %s.\n"),
  589. pkg_name(provider->up->up, pnaw_nonambig), possi->ed->name,
  590. gettext(statusstrings[provider->up->up->status]));
  591. varbuf_add_str(whynot, linebuf);
  592. if (!canfixbyremove)
  593. return false;
  594. nconflicts++;
  595. *canfixbyremove= provider->up->up;
  596. break;
  597. }
  598. break;
  599. default:
  600. internerr("unknown istobe conflict provider '%d'",
  601. provider->up->up->clientdata->istobe);
  602. }
  603. }
  604. }
  605. if (!nconflicts)
  606. return true;
  607. if (nconflicts > 1)
  608. *canfixbyremove = NULL;
  609. return false;
  610. } /* if (dependency) {...} else {...} */
  611. }