depcon.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 © 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. }