depcon.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * depcon.c - dependency and conflict checking
  4. *
  5. * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2009 Canonical Ltd.
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <dpkg/dpkg.h>
  24. #include <dpkg/dpkg-db.h>
  25. #include <dpkg/arch.h>
  26. bool
  27. versionsatisfied(struct pkgbin *it, struct deppossi *against)
  28. {
  29. return dpkg_version_relate(&it->version,
  30. against->verrel,
  31. &against->version);
  32. }
  33. /**
  34. * Check if the architecture qualifier in the dependency is satisfied.
  35. *
  36. * The rules are supposed to be:
  37. * - unqualified Depends/Pre-Depends/Recommends/Suggests are only
  38. * satisfied by a package of a different architecture if the target
  39. * package is Multi-Arch: foreign.
  40. * - Depends/Pre-Depends/Recommends/Suggests on pkg:any are satisfied by
  41. * a package of a different architecture if the target package is
  42. * Multi-Arch: allowed.
  43. * - all other Depends/Pre-Depends/Recommends/Suggests are only
  44. * satisfied by packages of the same architecture.
  45. * - Architecture: all packages are treated the same as packages of the
  46. * native architecture.
  47. * - Conflicts/Replaces/Breaks are assumed to apply to packages of any arch.
  48. */
  49. bool
  50. deparchsatisfied(struct pkgbin *it, const struct dpkg_arch *it_arch,
  51. struct deppossi *against)
  52. {
  53. const struct dpkg_arch *dep_arch, *pkg_arch;
  54. if (against->arch_is_implicit &&
  55. it->multiarch == multiarch_foreign)
  56. return true;
  57. dep_arch = against->arch;
  58. if (dep_arch->type == arch_wildcard &&
  59. (it->multiarch == multiarch_allowed ||
  60. against->up->type == dep_conflicts ||
  61. against->up->type == dep_replaces ||
  62. against->up->type == dep_breaks))
  63. return true;
  64. pkg_arch = it_arch;
  65. if (dep_arch->type == arch_none || dep_arch->type == arch_all)
  66. dep_arch = dpkg_arch_get(arch_native);
  67. if (pkg_arch->type == arch_none || pkg_arch->type == arch_all)
  68. pkg_arch = dpkg_arch_get(arch_native);
  69. return (dep_arch == pkg_arch);
  70. }
  71. bool
  72. archsatisfied(struct pkgbin *it, struct deppossi *against)
  73. {
  74. return deparchsatisfied(it, it->arch, against);
  75. }