LCOV - code coverage report
Current view: top level - lib/dpkg - trignote.c (source / functions) Hit Total Coverage
Test: dpkg 1.21.11 C code coverage Lines: 0 41 0.0 %
Date: 2022-12-03 00:40:01 Functions: 0 6 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 22 0.0 %

           Branch data     Line data    Source code
       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 <ijackson@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                 :            : 
      23                 :            : #include <config.h>
      24                 :            : #include <compat.h>
      25                 :            : 
      26                 :            : #include <string.h>
      27                 :            : 
      28                 :            : #include <dpkg/dpkg.h>
      29                 :            : #include <dpkg/dpkg-db.h>
      30                 :            : #include <dpkg/pkg.h>
      31                 :            : #include <dpkg/pkg-list.h>
      32                 :            : #include <dpkg/dlist.h>
      33                 :            : #include <dpkg/triglib.h>
      34                 :            : 
      35                 :            : /*
      36                 :            :  * Note: This is also called from fields.c where *pend is a temporary!
      37                 :            :  *
      38                 :            :  * trig is not copied!
      39                 :            :  */
      40                 :            : bool
      41                 :          0 : trig_note_pend_core(struct pkginfo *pend, const char *trig)
      42                 :            : {
      43                 :            :         struct trigpend *tp;
      44                 :            : 
      45         [ #  # ]:          0 :         for (tp = pend->trigpend_head; tp; tp = tp->next)
      46         [ #  # ]:          0 :                 if (strcmp(tp->name, trig) == 0)
      47                 :          0 :                         return false;
      48                 :            : 
      49                 :          0 :         tp = nfmalloc(sizeof(*tp));
      50                 :          0 :         tp->name = trig;
      51                 :          0 :         tp->next = pend->trigpend_head;
      52                 :          0 :         pend->trigpend_head = tp;
      53                 :            : 
      54                 :          0 :         return true;
      55                 :            : }
      56                 :            : 
      57                 :            : /*
      58                 :            :  * trig is not copied!
      59                 :            :  *
      60                 :            :  * @retval true  For done.
      61                 :            :  * @retval false For already noted.
      62                 :            :  */
      63                 :            : bool
      64                 :          0 : trig_note_pend(struct pkginfo *pend, const char *trig)
      65                 :            : {
      66         [ #  # ]:          0 :         if (!trig_note_pend_core(pend, trig))
      67                 :          0 :                 return false;
      68                 :            : 
      69         [ #  # ]:          0 :         if (pend->trigaw.head)
      70                 :          0 :                 pkg_set_status(pend, PKG_STAT_TRIGGERSAWAITED);
      71                 :            :         else
      72                 :          0 :                 pkg_set_status(pend, PKG_STAT_TRIGGERSPENDING);
      73                 :            : 
      74                 :          0 :         return true;
      75                 :            : }
      76                 :            : 
      77                 :            : /*
      78                 :            :  * Note: This is called also from fields.c where *aw is a temporary
      79                 :            :  * but pend is from pkg_hash_find()!
      80                 :            :  *
      81                 :            :  * @retval true  For done.
      82                 :            :  * @retval false For already noted.
      83                 :            :  */
      84                 :            : bool
      85                 :          0 : trig_note_aw(struct pkginfo *pend, struct pkginfo *aw)
      86                 :            : {
      87                 :            :         struct trigaw *ta;
      88                 :            : 
      89                 :            :         /* We search through aw's list because that's probably shorter. */
      90         [ #  # ]:          0 :         for (ta = aw->trigaw.head; ta; ta = ta->sameaw.next)
      91         [ #  # ]:          0 :                 if (ta->pend == pend)
      92                 :          0 :                         return false;
      93                 :            : 
      94                 :          0 :         ta = nfmalloc(sizeof(*ta));
      95                 :          0 :         ta->aw = aw;
      96                 :          0 :         ta->pend = pend;
      97                 :          0 :         ta->samepend_next = pend->othertrigaw_head;
      98                 :          0 :         pend->othertrigaw_head = ta;
      99         [ #  # ]:          0 :         LIST_LINK_TAIL_PART(aw->trigaw, ta, sameaw);
     100                 :            : 
     101                 :          0 :         return true;
     102                 :            : }
     103                 :            : 
     104                 :            : static struct pkg_list *trig_awaited_pend_head;
     105                 :            : 
     106                 :            : void
     107                 :          0 : trig_awaited_pend_enqueue(struct pkginfo *pend)
     108                 :            : {
     109                 :            :         struct pkg_list *tp;
     110                 :            : 
     111         [ #  # ]:          0 :         for (tp = trig_awaited_pend_head; tp; tp = tp->next)
     112         [ #  # ]:          0 :                 if (tp->pkg == pend)
     113                 :          0 :                         return;
     114                 :            : 
     115                 :          0 :         pkg_list_prepend(&trig_awaited_pend_head, pend);
     116                 :            : }
     117                 :            : 
     118                 :            : void
     119                 :          0 : trig_awaited_pend_foreach(trig_awaited_pend_foreach_func *func)
     120                 :            : {
     121                 :            :         struct pkg_list *tp;
     122                 :            : 
     123         [ #  # ]:          0 :         for (tp = trig_awaited_pend_head; tp; tp = tp->next)
     124         [ #  # ]:          0 :                 if (!tp->pkg->trigpend_head)
     125                 :          0 :                         func(tp->pkg);
     126                 :          0 : }
     127                 :            : 
     128                 :            : void
     129                 :          0 : trig_awaited_pend_free(void)
     130                 :            : {
     131                 :          0 :         pkg_list_free(trig_awaited_pend_head);
     132                 :          0 :         trig_awaited_pend_head = NULL;
     133                 :          0 : }

Generated by: LCOV version 1.16