trignote.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * trignote.c - trigger note handling
  4. *
  5. * Copyright © 2007 Canonical Ltd
  6. * Written by Ian Jackson <ian@chiark.greenend.org.uk>
  7. * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
  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 <string.h>
  25. #include <dpkg/dpkg.h>
  26. #include <dpkg/dpkg-db.h>
  27. #include <dpkg/pkg.h>
  28. #include <dpkg/pkg-list.h>
  29. #include <dpkg/dlist.h>
  30. #include <dpkg/triglib.h>
  31. /*
  32. * Note: This is also called from fields.c where *pend is a temporary!
  33. *
  34. * trig is not copied!
  35. */
  36. bool
  37. trig_note_pend_core(struct pkginfo *pend, const char *trig)
  38. {
  39. struct trigpend *tp;
  40. for (tp = pend->trigpend_head; tp; tp = tp->next)
  41. if (strcmp(tp->name, trig) == 0)
  42. return false;
  43. tp = nfmalloc(sizeof(*tp));
  44. tp->name = trig;
  45. tp->next = pend->trigpend_head;
  46. pend->trigpend_head = tp;
  47. return true;
  48. }
  49. /*
  50. * trig is not copied!
  51. *
  52. * @retval true For done.
  53. * @retval false For already noted.
  54. */
  55. bool
  56. trig_note_pend(struct pkginfo *pend, const char *trig)
  57. {
  58. if (!trig_note_pend_core(pend, trig))
  59. return false;
  60. if (pend->trigaw.head)
  61. pkg_set_status(pend, PKG_STAT_TRIGGERSAWAITED);
  62. else
  63. pkg_set_status(pend, PKG_STAT_TRIGGERSPENDING);
  64. return true;
  65. }
  66. /*
  67. * Note: This is called also from fields.c where *aw is a temporary
  68. * but pend is from pkg_db_find()!
  69. *
  70. * @retval true For done.
  71. * @retval false For already noted.
  72. */
  73. bool
  74. trig_note_aw(struct pkginfo *pend, struct pkginfo *aw)
  75. {
  76. struct trigaw *ta;
  77. /* We search through aw's list because that's probably shorter. */
  78. for (ta = aw->trigaw.head; ta; ta = ta->sameaw.next)
  79. if (ta->pend == pend)
  80. return false;
  81. ta = nfmalloc(sizeof(*ta));
  82. ta->aw = aw;
  83. ta->pend = pend;
  84. ta->samepend_next = pend->othertrigaw_head;
  85. pend->othertrigaw_head = ta;
  86. LIST_LINK_TAIL_PART(aw->trigaw, ta, sameaw.);
  87. return true;
  88. }
  89. static struct pkg_list *trig_awaited_pend_head;
  90. void
  91. trig_awaited_pend_enqueue(struct pkginfo *pend)
  92. {
  93. struct pkg_list *tp;
  94. for (tp = trig_awaited_pend_head; tp; tp = tp->next)
  95. if (tp->pkg == pend)
  96. return;
  97. pkg_list_prepend(&trig_awaited_pend_head, pend);
  98. }
  99. void
  100. trig_awaited_pend_foreach(trig_awaited_pend_foreach_func *func)
  101. {
  102. struct pkg_list *tp;
  103. for (tp = trig_awaited_pend_head; tp; tp = tp->next)
  104. if (!tp->pkg->trigpend_head)
  105. func(tp->pkg);
  106. }
  107. void
  108. trig_awaited_pend_free(void)
  109. {
  110. pkg_list_free(trig_awaited_pend_head);
  111. trig_awaited_pend_head = NULL;
  112. }