depcon.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * depcon.c - dependency and conflict checking
  4. *
  5. * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
  6. * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
  7. * Copyright © 2009 Canonical Ltd.
  8. *
  9. * This is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. #include <config.h>
  23. #include <compat.h>
  24. #include <dpkg/dpkg.h>
  25. #include <dpkg/dpkg-db.h>
  26. #include <dpkg/arch.h>
  27. bool
  28. versionsatisfied(struct pkgbin *it, struct deppossi *against)
  29. {
  30. return dpkg_version_relate(&it->version,
  31. against->verrel,
  32. &against->version);
  33. }
  34. /**
  35. * Check if the architecture qualifier in the dependency is satisfied.
  36. *
  37. * The rules are supposed to be:
  38. * - unqualified Depends/Pre-Depends/Recommends/Suggests are only
  39. * satisfied by a package of a different architecture if the target
  40. * package is Multi-Arch: foreign.
  41. * - Depends/Pre-Depends/Recommends/Suggests on pkg:any are satisfied by
  42. * a package of a different architecture if the target package is
  43. * Multi-Arch: allowed.
  44. * - all other Depends/Pre-Depends/Recommends/Suggests are only
  45. * satisfied by packages of the same architecture.
  46. * - Architecture: all packages are treated the same as packages of the
  47. * native architecture.
  48. * - Conflicts/Replaces/Breaks are assumed to apply to packages of any arch.
  49. */
  50. bool
  51. deparchsatisfied(struct pkgbin *it, const struct dpkg_arch *it_arch,
  52. struct deppossi *against)
  53. {
  54. const struct dpkg_arch *dep_arch, *pkg_arch;
  55. if (against->arch_is_implicit &&
  56. it->multiarch == PKG_MULTIARCH_FOREIGN)
  57. return true;
  58. dep_arch = against->arch;
  59. if (dep_arch->type == DPKG_ARCH_WILDCARD &&
  60. (it->multiarch == PKG_MULTIARCH_ALLOWED ||
  61. against->up->type == dep_conflicts ||
  62. against->up->type == dep_replaces ||
  63. against->up->type == dep_breaks))
  64. return true;
  65. pkg_arch = it_arch;
  66. if (dep_arch->type == DPKG_ARCH_NONE || dep_arch->type == DPKG_ARCH_ALL)
  67. dep_arch = dpkg_arch_get(DPKG_ARCH_NATIVE);
  68. if (pkg_arch->type == DPKG_ARCH_NONE || pkg_arch->type == DPKG_ARCH_ALL)
  69. pkg_arch = dpkg_arch_get(DPKG_ARCH_NATIVE);
  70. return (dep_arch == pkg_arch);
  71. }
  72. bool
  73. archsatisfied(struct pkgbin *it, struct deppossi *against)
  74. {
  75. return deparchsatisfied(it, it->arch, against);
  76. }
  77. /**
  78. * Check if the dependency is satisfied by a virtual package.
  79. *
  80. * For versioned depends, we only check providers with #DPKG_RELATION_EQ. It
  81. * does not make sense to check ones without a version since we have nothing
  82. * to verify against. Also, it is way too complex to allow anything but an
  83. * equal in a provided version. A few examples below to deter you from trying:
  84. *
  85. * - pkg1 depends on virt (>= 0.6), pkg2 provides virt (<= 1.0).
  86. * Should pass (easy enough).
  87. *
  88. * - pkg1 depends on virt (>= 0.7) and (<= 1.1), pkg2 provides virt (>= 1.2).
  89. * Should fail (little harder).
  90. *
  91. * - pkg1 depends on virt (>= 0.4), pkg2 provides virt (<= 1.0) and (>= 0.5),
  92. * IOW, inclusive of only those versions. This would require backchecking
  93. * the other provided versions in the possi, which would make things sickly
  94. * complex and overly time consuming. Should fail (very hard to implement).
  95. *
  96. * This could be handled by switching to a SAT solver, but that would imply
  97. * lots of work for very little gain. Packages can easily get around most of
  98. * these by providing multiple #DPKG_RELATION_EQ versions.
  99. */
  100. bool
  101. pkg_virtual_deppossi_satisfied(struct deppossi *dependee,
  102. struct deppossi *provider)
  103. {
  104. if (provider->verrel != DPKG_RELATION_NONE &&
  105. provider->verrel != DPKG_RELATION_EQ)
  106. return false;
  107. if (provider->verrel == DPKG_RELATION_NONE &&
  108. dependee->verrel != DPKG_RELATION_NONE)
  109. return false;
  110. return dpkg_version_relate(&provider->version,
  111. dependee->verrel,
  112. &dependee->version);
  113. }