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("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 == black)
  142. return false;
  143. pkg->clientdata->color = 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 == itb_normal) continue;
  179. /* We don't break things at ‘provides’ links, so ‘possi’ is
  180. * still the one we use. */
  181. if (foundcyclebroken(&thislink, sofar, provider, possi))
  182. return true;
  183. }
  184. }
  185. }
  186. /* Nope, we didn't find a cycle to break. */
  187. pkg->clientdata->color = black;
  188. return false;
  189. }
  190. bool
  191. findbreakcycle(struct pkginfo *pkg)
  192. {
  193. struct pkgiterator *iter;
  194. struct pkginfo *tpkg;
  195. /* Clear the visited flag of all packages before we traverse them. */
  196. iter = pkg_db_iter_new();
  197. while ((tpkg = pkg_db_iter_next_pkg(iter))) {
  198. ensure_package_clientdata(tpkg);
  199. tpkg->clientdata->color = white;
  200. }
  201. pkg_db_iter_free(iter);
  202. return findbreakcyclerecursive(pkg, NULL);
  203. }
  204. void describedepcon(struct varbuf *addto, struct dependency *dep) {
  205. const char *fmt;
  206. struct varbuf depstr = VARBUF_INIT;
  207. switch (dep->type) {
  208. case dep_depends:
  209. fmt = _("%s depends on %s");
  210. break;
  211. case dep_predepends:
  212. fmt = _("%s pre-depends on %s");
  213. break;
  214. case dep_recommends:
  215. fmt = _("%s recommends %s");
  216. break;
  217. case dep_suggests:
  218. fmt = _("%s suggests %s");
  219. break;
  220. case dep_breaks:
  221. fmt = _("%s breaks %s");
  222. break;
  223. case dep_conflicts:
  224. fmt = _("%s conflicts with %s");
  225. break;
  226. case dep_enhances:
  227. fmt = _("%s enhances %s");
  228. break;
  229. default:
  230. internerr("unknown deptype '%d'", dep->type);
  231. }
  232. varbufdependency(&depstr, dep);
  233. varbuf_end_str(&depstr);
  234. varbuf_printf(addto, fmt, pkg_name(dep->up, pnaw_nonambig), depstr.buf);
  235. varbuf_destroy(&depstr);
  236. }
  237. /*
  238. * *whynot must already have been initialized; it need not be
  239. * empty though - it will be reset before use.
  240. *
  241. * If depisok returns false for ‘not OK’ it will contain a description,
  242. * newline-terminated BUT NOT NUL-TERMINATED, of the reason.
  243. *
  244. * If depisok returns true it will contain garbage.
  245. * allowunconfigd should be non-zero during the ‘Pre-Depends’ checking
  246. * before a package is unpacked, when it is sufficient for the package
  247. * to be unpacked provided that both the unpacked and previously-configured
  248. * versions are acceptable.
  249. *
  250. * On false return (‘not OK’), *canfixbyremove refers to a package which
  251. * if removed (dep_conflicts) or deconfigured (dep_breaks) will fix
  252. * the problem. Caller may pass NULL for canfixbyremove and need not
  253. * initialize *canfixbyremove.
  254. *
  255. * On false return (‘not OK’), *canfixbytrigaw refers to a package which
  256. * can fix the problem if all the packages listed in Triggers-Awaited have
  257. * their triggers processed. Caller may pass NULL for canfixbytrigaw and
  258. * need not initialize *canfixbytrigaw.
  259. */
  260. bool
  261. depisok(struct dependency *dep, struct varbuf *whynot,
  262. struct pkginfo **canfixbyremove, struct pkginfo **canfixbytrigaw,
  263. bool allowunconfigd)
  264. {
  265. struct deppossi *possi;
  266. struct deppossi *provider;
  267. struct pkginfo *pkg_pos;
  268. int nconflicts;
  269. /* Use this buffer so that when internationalisation comes along we
  270. * don't have to rewrite the code completely, only redo the sprintf strings
  271. * (assuming we have the fancy argument-number-specifiers).
  272. * Allow 250x3 for package names, versions, &c, + 250 for ourselves. */
  273. char linebuf[1024];
  274. assert(dep->type == dep_depends || dep->type == dep_predepends ||
  275. dep->type == dep_breaks || dep->type == dep_conflicts ||
  276. dep->type == dep_recommends || dep->type == dep_suggests ||
  277. dep->type == dep_enhances);
  278. if (canfixbyremove)
  279. *canfixbyremove = NULL;
  280. if (canfixbytrigaw)
  281. *canfixbytrigaw = NULL;
  282. /* The dependency is always OK if we're trying to remove the depend*ing*
  283. * package. */
  284. switch (dep->up->clientdata->istobe) {
  285. case itb_remove: case itb_deconfigure:
  286. return true;
  287. case itb_normal:
  288. /* Only installed packages can be make dependency problems. */
  289. switch (dep->up->status) {
  290. case stat_installed:
  291. case stat_triggerspending:
  292. case stat_triggersawaited:
  293. break;
  294. case stat_notinstalled: case stat_configfiles: case stat_halfinstalled:
  295. case stat_halfconfigured: case stat_unpacked:
  296. return true;
  297. default:
  298. internerr("unknown status depending '%d'", dep->up->status);
  299. }
  300. break;
  301. case itb_installnew: case itb_preinstall:
  302. break;
  303. default:
  304. internerr("unknown istobe depending '%d'", dep->up->clientdata->istobe);
  305. }
  306. /* Describe the dependency, in case we have to moan about it. */
  307. varbuf_reset(whynot);
  308. varbuf_add_char(whynot, ' ');
  309. describedepcon(whynot, dep);
  310. varbuf_add_char(whynot, '\n');
  311. /* TODO: Check dep_enhances as well. */
  312. if (dep->type == dep_depends || dep->type == dep_predepends ||
  313. dep->type == dep_recommends || dep->type == dep_suggests ) {
  314. /* Go through the alternatives. As soon as we find one that
  315. * we like, we return ‘true’ straight away. Otherwise, when we get to
  316. * the end we'll have accumulated all the reasons in whynot and
  317. * can return ‘false’. */
  318. for (possi= dep->list; possi; possi= possi->next) {
  319. struct deppossi_pkg_iterator *possi_iter;
  320. possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
  321. while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
  322. switch (pkg_pos->clientdata->istobe) {
  323. case itb_remove:
  324. sprintf(linebuf, _(" %.250s is to be removed.\n"),
  325. pkg_name(pkg_pos, pnaw_nonambig));
  326. break;
  327. case itb_deconfigure:
  328. sprintf(linebuf, _(" %.250s is to be deconfigured.\n"),
  329. pkg_name(pkg_pos, pnaw_nonambig));
  330. break;
  331. case itb_installnew:
  332. if (versionsatisfied(&pkg_pos->available, possi)) {
  333. deppossi_pkg_iter_free(possi_iter);
  334. return true;
  335. }
  336. sprintf(linebuf, _(" %.250s is to be installed, but is version "
  337. "%.250s.\n"),
  338. pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
  339. versiondescribe(&pkg_pos->available.version, vdew_nonambig));
  340. break;
  341. case itb_normal:
  342. case itb_preinstall:
  343. switch (pkg_pos->status) {
  344. case stat_installed:
  345. case stat_triggerspending:
  346. if (versionsatisfied(&pkg_pos->installed, possi)) {
  347. deppossi_pkg_iter_free(possi_iter);
  348. return true;
  349. }
  350. sprintf(linebuf, _(" %.250s is installed, but is version "
  351. "%.250s.\n"),
  352. pkg_name(pkg_pos, pnaw_nonambig),
  353. versiondescribe(&pkg_pos->installed.version, vdew_nonambig));
  354. break;
  355. case stat_notinstalled:
  356. /* Don't say anything about this yet - it might be a virtual package.
  357. * Later on, if nothing has put anything in linebuf, we know that it
  358. * isn't and issue a diagnostic then. */
  359. *linebuf = '\0';
  360. break;
  361. case stat_triggersawaited:
  362. if (canfixbytrigaw && versionsatisfied(&pkg_pos->installed, possi))
  363. *canfixbytrigaw = pkg_pos;
  364. /* Fall through to have a chance to return OK due to
  365. * allowunconfigd and to fill the explanation */
  366. case stat_unpacked:
  367. case stat_halfconfigured:
  368. if (allowunconfigd) {
  369. if (!dpkg_version_is_informative(&pkg_pos->configversion)) {
  370. sprintf(linebuf, _(" %.250s is unpacked, but has never been "
  371. "configured.\n"),
  372. pkg_name(pkg_pos, pnaw_nonambig));
  373. break;
  374. } else if (!versionsatisfied(&pkg_pos->installed, possi)) {
  375. sprintf(linebuf, _(" %.250s is unpacked, but is version "
  376. "%.250s.\n"),
  377. pkg_name(pkg_pos, pnaw_nonambig),
  378. versiondescribe(&pkg_pos->installed.version,
  379. vdew_nonambig));
  380. break;
  381. } else if (!dpkg_version_relate(&pkg_pos->configversion,
  382. possi->verrel,
  383. &possi->version)) {
  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 == dpkg_relation_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 == dpkg_relation_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. }