LCOV - code coverage report
Current view: top level - lib/dpkg - pkg-files.c (source / functions) Coverage Total Hit
Test: dpkg 1.22.7-3-g89f48 C code coverage Lines: 62.1 % 29 18
Test Date: 2024-07-17 02:53:43 Functions: 100.0 % 2 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 30.0 % 10 3

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * libdpkg - Debian packaging suite library routines
       3                 :             :  * pkg-files.c - handle list of filesystem files per package
       4                 :             :  *
       5                 :             :  * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
       6                 :             :  * Copyright © 2000,2001 Wichert Akkerman <wakkerma@debian.org>
       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 <dpkg/i18n.h>
      27                 :             : #include <dpkg/dpkg.h>
      28                 :             : #include <dpkg/dpkg-db.h>
      29                 :             : #include <dpkg/pkg-list.h>
      30                 :             : #include <dpkg/pkg-files.h>
      31                 :             : 
      32                 :             : /**
      33                 :             :  * Erase the files saved in pkg.
      34                 :             :  */
      35                 :             : void
      36                 :           1 : pkg_files_blank(struct pkginfo *pkg)
      37                 :             : {
      38                 :             :         struct fsys_namenode_list *current;
      39                 :             : 
      40                 :           1 :         for (current = pkg->files;
      41         [ -  + ]:           1 :              current;
      42                 :           0 :              current = current->next) {
      43                 :           0 :                 struct pkg_list **pkg_prev = &current->namenode->packages;
      44                 :             :                 struct pkg_list *pkg_node;
      45                 :             : 
      46                 :             :                 /* For each file that used to be in the package, go through
      47                 :             :                  * looking for this package's entry in the list of packages
      48                 :             :                  * containing this file, and blank it out. */
      49                 :           0 :                 for (pkg_node = current->namenode->packages;
      50         [ #  # ]:           0 :                      pkg_node;
      51                 :           0 :                      pkg_node = pkg_node->next) {
      52         [ #  # ]:           0 :                         if (pkg_node->pkg == pkg) {
      53                 :           0 :                                 *pkg_prev = pkg_node->next;
      54                 :             : 
      55                 :             :                                 /* The actual filelist links were allocated
      56                 :             :                                  * w/ nfmalloc, so we should not free them. */
      57                 :           0 :                                 break;
      58                 :             :                         }
      59                 :             : 
      60                 :           0 :                         pkg_prev = &pkg_node->next;
      61                 :             :                 }
      62                 :             :         }
      63                 :           1 :         pkg->files = NULL;
      64                 :           1 : }
      65                 :             : 
      66                 :             : struct fsys_namenode_list **
      67                 :           1 : pkg_files_add_file(struct pkginfo *pkg, struct fsys_namenode *namenode,
      68                 :             :                    struct fsys_namenode_list **file_tail)
      69                 :             : {
      70                 :             :         struct fsys_namenode_list *newent;
      71                 :             :         struct pkg_list *pkg_node;
      72                 :             : 
      73         [ -  + ]:           1 :         if (file_tail == NULL)
      74                 :           0 :                 file_tail = &pkg->files;
      75                 :             : 
      76                 :             :         /* Make sure we're at the end. */
      77         [ -  + ]:           1 :         while ((*file_tail) != NULL)
      78                 :           0 :                 file_tail = &((*file_tail)->next);
      79                 :             : 
      80                 :             :         /* Create a new node. */
      81                 :           1 :         newent = nfmalloc(sizeof(*newent));
      82                 :           1 :         newent->namenode = namenode;
      83                 :           1 :         newent->next = NULL;
      84                 :           1 :         *file_tail = newent;
      85                 :           1 :         file_tail = &newent->next;
      86                 :             : 
      87                 :             :         /* Add pkg to newent's package list. */
      88                 :           1 :         pkg_node = nfmalloc(sizeof(*pkg_node));
      89                 :           1 :         pkg_node->pkg = pkg;
      90                 :           1 :         pkg_node->next = newent->namenode->packages;
      91                 :           1 :         newent->namenode->packages = pkg_node;
      92                 :             : 
      93                 :             :         /* Return the position for the next guy. */
      94                 :           1 :         return file_tail;
      95                 :             : }
        

Generated by: LCOV version 2.0-1