depcon.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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 (!versionsatisfied3(&pkg_pos->configversion,
  382. &possi->version, possi->verrel)) {
  383. sprintf(linebuf, _(" %.250s latest configured version is "
  384. "%.250s.\n"),
  385. pkg_name(pkg_pos, pnaw_nonambig),
  386. versiondescribe(&pkg_pos->configversion, vdew_nonambig));
  387. break;
  388. } else {
  389. deppossi_pkg_iter_free(possi_iter);
  390. return true;
  391. }
  392. }
  393. /* Fall through. */
  394. default:
  395. sprintf(linebuf, _(" %.250s is %s.\n"),
  396. pkg_name(pkg_pos, pnaw_nonambig),
  397. gettext(statusstrings[pkg_pos->status]));
  398. break;
  399. }
  400. break;
  401. default:
  402. internerr("unknown istobe depended '%d'", pkg_pos->clientdata->istobe);
  403. }
  404. varbuf_add_str(whynot, linebuf);
  405. }
  406. deppossi_pkg_iter_free(possi_iter);
  407. /* If there was no version specified we try looking for Providers. */
  408. if (possi->verrel == dvr_none) {
  409. /* See if the package we're about to install Provides it. */
  410. for (provider = possi->ed->depended.available;
  411. provider;
  412. provider = provider->rev_next) {
  413. if (provider->up->type != dep_provides) continue;
  414. if (provider->up->up->clientdata->istobe == itb_installnew)
  415. return true;
  416. }
  417. /* Now look at the packages already on the system. */
  418. for (provider = possi->ed->depended.installed;
  419. provider;
  420. provider = provider->rev_next) {
  421. if (provider->up->type != dep_provides) continue;
  422. switch (provider->up->up->clientdata->istobe) {
  423. case itb_installnew:
  424. /* Don't pay any attention to the Provides field of the
  425. * currently-installed version of the package we're trying
  426. * to install. We dealt with that by using the available
  427. * information above. */
  428. continue;
  429. case itb_remove:
  430. sprintf(linebuf, _(" %.250s provides %.250s but is to be removed.\n"),
  431. pkg_name(provider->up->up, pnaw_nonambig),
  432. possi->ed->name);
  433. break;
  434. case itb_deconfigure:
  435. sprintf(linebuf, _(" %.250s provides %.250s but is to be deconfigured.\n"),
  436. pkg_name(provider->up->up, pnaw_nonambig),
  437. possi->ed->name);
  438. break;
  439. case itb_normal: case itb_preinstall:
  440. if (provider->up->up->status == stat_installed ||
  441. provider->up->up->status == stat_triggerspending)
  442. return true;
  443. if (provider->up->up->status == stat_triggersawaited)
  444. *canfixbytrigaw = provider->up->up;
  445. sprintf(linebuf, _(" %.250s provides %.250s but is %s.\n"),
  446. pkg_name(provider->up->up, pnaw_nonambig),
  447. possi->ed->name,
  448. gettext(statusstrings[provider->up->up->status]));
  449. break;
  450. default:
  451. internerr("unknown istobe provider '%d'",
  452. provider->up->up->clientdata->istobe);
  453. }
  454. varbuf_add_str(whynot, linebuf);
  455. }
  456. if (!*linebuf) {
  457. /* If the package wasn't installed at all, and we haven't said
  458. * yet why this isn't satisfied, we should say so now. */
  459. sprintf(linebuf, _(" %.250s is not installed.\n"), possi->ed->name);
  460. varbuf_add_str(whynot, linebuf);
  461. }
  462. }
  463. }
  464. return false;
  465. } else {
  466. /* It's conflicts or breaks. There's only one main alternative,
  467. * but we also have to consider Providers. We return ‘false’ as soon
  468. * as we find something that matches the conflict, and only describe
  469. * it then. If we get to the end without finding anything we return
  470. * ‘true’. */
  471. possi= dep->list;
  472. nconflicts= 0;
  473. if (possi->ed != possi->up->up->set) {
  474. struct deppossi_pkg_iterator *possi_iter;
  475. /* If the package conflicts with or breaks itself it must mean
  476. * other packages which provide the same virtual name. We
  477. * therefore don't look at the real package and go on to the
  478. * virtual ones. */
  479. possi_iter = deppossi_pkg_iter_new(possi, wpb_by_istobe);
  480. while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) {
  481. switch (pkg_pos->clientdata->istobe) {
  482. case itb_remove:
  483. break;
  484. case itb_installnew:
  485. if (!versionsatisfied(&pkg_pos->available, possi))
  486. break;
  487. sprintf(linebuf, _(" %.250s (version %.250s) is to be installed.\n"),
  488. pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig),
  489. versiondescribe(&pkg_pos->available.version, vdew_nonambig));
  490. varbuf_add_str(whynot, linebuf);
  491. if (!canfixbyremove) {
  492. deppossi_pkg_iter_free(possi_iter);
  493. return false;
  494. }
  495. nconflicts++;
  496. *canfixbyremove = pkg_pos;
  497. break;
  498. case itb_deconfigure:
  499. if (dep->type == dep_breaks)
  500. break; /* Already deconfiguring this. */
  501. /* Fall through. */
  502. case itb_normal:
  503. case itb_preinstall:
  504. switch (pkg_pos->status) {
  505. case stat_notinstalled:
  506. case stat_configfiles:
  507. break;
  508. case stat_halfinstalled:
  509. case stat_unpacked:
  510. case stat_halfconfigured:
  511. if (dep->type == dep_breaks)
  512. break; /* No problem. */
  513. case stat_installed:
  514. case stat_triggerspending:
  515. case stat_triggersawaited:
  516. if (!versionsatisfied(&pkg_pos->installed, possi))
  517. break;
  518. sprintf(linebuf, _(" %.250s (version %.250s) is present and %s.\n"),
  519. pkg_name(pkg_pos, pnaw_nonambig),
  520. versiondescribe(&pkg_pos->installed.version, vdew_nonambig),
  521. gettext(statusstrings[pkg_pos->status]));
  522. varbuf_add_str(whynot, linebuf);
  523. if (!canfixbyremove) {
  524. deppossi_pkg_iter_free(possi_iter);
  525. return false;
  526. }
  527. nconflicts++;
  528. *canfixbyremove = pkg_pos;
  529. }
  530. break;
  531. default:
  532. internerr("unknown istobe conflict '%d'", pkg_pos->clientdata->istobe);
  533. }
  534. }
  535. deppossi_pkg_iter_free(possi_iter);
  536. }
  537. /* If there was no version specified we try looking for Providers. */
  538. if (possi->verrel == dvr_none) {
  539. /* See if the package we're about to install Provides it. */
  540. for (provider = possi->ed->depended.available;
  541. provider;
  542. provider = provider->rev_next) {
  543. if (provider->up->type != dep_provides) continue;
  544. if (provider->up->up->clientdata->istobe != itb_installnew) continue;
  545. if (provider->up->up->set == dep->up->set)
  546. continue; /* Conflicts and provides the same. */
  547. sprintf(linebuf, _(" %.250s provides %.250s and is to be installed.\n"),
  548. pkgbin_name(provider->up->up, &provider->up->up->available,
  549. pnaw_nonambig), possi->ed->name);
  550. varbuf_add_str(whynot, linebuf);
  551. /* We can't remove the one we're about to install: */
  552. if (canfixbyremove)
  553. *canfixbyremove = NULL;
  554. return false;
  555. }
  556. /* Now look at the packages already on the system. */
  557. for (provider = possi->ed->depended.installed;
  558. provider;
  559. provider = provider->rev_next) {
  560. if (provider->up->type != dep_provides) continue;
  561. if (provider->up->up->set == dep->up->set)
  562. continue; /* Conflicts and provides the same. */
  563. switch (provider->up->up->clientdata->istobe) {
  564. case itb_installnew:
  565. /* Don't pay any attention to the Provides field of the
  566. * currently-installed version of the package we're trying
  567. * to install. We dealt with that package by using the
  568. * available information above. */
  569. continue;
  570. case itb_remove:
  571. continue;
  572. case itb_deconfigure:
  573. if (dep->type == dep_breaks)
  574. continue; /* Already deconfiguring. */
  575. case itb_normal: case itb_preinstall:
  576. switch (provider->up->up->status) {
  577. case stat_notinstalled: case stat_configfiles:
  578. continue;
  579. case stat_halfinstalled: case stat_unpacked:
  580. case stat_halfconfigured:
  581. if (dep->type == dep_breaks)
  582. break; /* No problem. */
  583. case stat_installed:
  584. case stat_triggerspending:
  585. case stat_triggersawaited:
  586. sprintf(linebuf,
  587. _(" %.250s provides %.250s and is present and %s.\n"),
  588. pkg_name(provider->up->up, pnaw_nonambig), possi->ed->name,
  589. gettext(statusstrings[provider->up->up->status]));
  590. varbuf_add_str(whynot, linebuf);
  591. if (!canfixbyremove)
  592. return false;
  593. nconflicts++;
  594. *canfixbyremove= provider->up->up;
  595. break;
  596. }
  597. break;
  598. default:
  599. internerr("unknown istobe conflict provider '%d'",
  600. provider->up->up->clientdata->istobe);
  601. }
  602. }
  603. }
  604. if (!nconflicts)
  605. return true;
  606. if (nconflicts > 1)
  607. *canfixbyremove = NULL;
  608. return false;
  609. } /* if (dependency) {...} else {...} */
  610. }