LCOV - code coverage report
Current view: top level - lib/dpkg - db-ctrl-access.c (source / functions) Coverage Total Hit
Test: dpkg 1.22.7-3-g89f48 C code coverage Lines: 0.0 % 39 0
Test Date: 2024-07-17 02:53:43 Functions: 0.0 % 2 0
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0.0 % 20 0

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * libdpkg - Debian packaging suite library routines
       3                 :             :  * db-ctrl-access.c - package control information database
       4                 :             :  *
       5                 :             :  * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
       6                 :             :  * Copyright © 2011-2014 Guillem Jover <guillem@debian.org>
       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 <https://www.gnu.org/licenses/>.
      20                 :             :  */
      21                 :             : 
      22                 :             : #include <config.h>
      23                 :             : #include <compat.h>
      24                 :             : 
      25                 :             : #include <sys/types.h>
      26                 :             : #include <sys/stat.h>
      27                 :             : 
      28                 :             : #include <errno.h>
      29                 :             : #include <dirent.h>
      30                 :             : #include <unistd.h>
      31                 :             : 
      32                 :             : #include <dpkg/i18n.h>
      33                 :             : #include <dpkg/dpkg.h>
      34                 :             : #include <dpkg/dpkg-db.h>
      35                 :             : #include <dpkg/fsys.h>
      36                 :             : #include <dpkg/db-ctrl.h>
      37                 :             : #include <dpkg/debug.h>
      38                 :             : 
      39                 :             : bool
      40                 :           0 : pkg_infodb_has_file(struct pkginfo *pkg, struct pkgbin *pkgbin,
      41                 :             :                     const char *name)
      42                 :             : {
      43                 :             :         const char *filename;
      44                 :             :         struct stat stab;
      45                 :             : 
      46                 :           0 :         filename = pkg_infodb_get_file(pkg, pkgbin, name);
      47         [ #  # ]:           0 :         if (lstat(filename, &stab) == 0)
      48                 :           0 :                 return true;
      49         [ #  # ]:           0 :         else if (errno == ENOENT)
      50                 :           0 :                 return false;
      51                 :             :         else
      52                 :           0 :                 ohshite(_("unable to check existence of '%.250s'"), filename);
      53                 :             : }
      54                 :             : 
      55                 :             : void
      56                 :           0 : pkg_infodb_foreach(struct pkginfo *pkg, struct pkgbin *pkgbin,
      57                 :             :                    pkg_infodb_file_func *func)
      58                 :             : {
      59                 :             :         DIR *db_dir;
      60                 :             :         struct dirent *db_de;
      61                 :             :         struct varbuf_state db_path_state;
      62                 :           0 :         struct varbuf db_path = VARBUF_INIT;
      63                 :             :         const char *pkgname;
      64                 :             :         enum pkg_infodb_format db_format;
      65                 :             : 
      66                 :             :         /* Make sure to always read and verify the format version. */
      67                 :           0 :         db_format = pkg_infodb_get_format();
      68                 :             : 
      69   [ #  #  #  # ]:           0 :         if (pkgbin->multiarch == PKG_MULTIARCH_SAME &&
      70                 :             :             db_format == PKG_INFODB_FORMAT_MULTIARCH)
      71                 :           0 :                 pkgname = pkgbin_name(pkg, pkgbin, pnaw_always);
      72                 :             :         else
      73                 :           0 :                 pkgname = pkgbin_name(pkg, pkgbin, pnaw_never);
      74                 :             : 
      75                 :           0 :         varbuf_add_dir(&db_path, pkg_infodb_get_dir());
      76                 :           0 :         varbuf_snapshot(&db_path, &db_path_state);
      77                 :             : 
      78                 :           0 :         db_dir = opendir(db_path.buf);
      79         [ #  # ]:           0 :         if (!db_dir)
      80                 :           0 :                 ohshite(_("cannot read info directory"));
      81                 :             : 
      82                 :           0 :         push_cleanup(cu_closedir, ~0, 1, (void *)db_dir);
      83         [ #  # ]:           0 :         while ((db_de = readdir(db_dir)) != NULL) {
      84                 :             :                 const char *filename, *filetype, *dot;
      85                 :             : 
      86                 :           0 :                 debug(dbg_veryverbose, "infodb foreach info file '%s'",
      87                 :           0 :                       db_de->d_name);
      88                 :             : 
      89                 :             :                 /* Ignore dotfiles, including ‘.’ and ‘..’. */
      90         [ #  # ]:           0 :                 if (db_de->d_name[0] == '.')
      91                 :           0 :                         continue;
      92                 :             : 
      93                 :             :                 /* Ignore anything odd. */
      94                 :           0 :                 dot = strrchr(db_de->d_name, '.');
      95         [ #  # ]:           0 :                 if (dot == NULL)
      96                 :           0 :                         continue;
      97                 :             : 
      98                 :             :                 /* Ignore files from other packages. */
      99         [ #  # ]:           0 :                 if (strlen(pkgname) != (size_t)(dot - db_de->d_name) ||
     100         [ #  # ]:           0 :                     strncmp(db_de->d_name, pkgname, dot - db_de->d_name))
     101                 :           0 :                         continue;
     102                 :             : 
     103                 :           0 :                 debug(dbg_stupidlyverbose, "infodb foreach file this pkg");
     104                 :             : 
     105                 :             :                 /* Skip past the full stop. */
     106                 :           0 :                 filetype = dot + 1;
     107                 :             : 
     108                 :           0 :                 varbuf_rollback(&db_path_state);
     109                 :           0 :                 varbuf_add_str(&db_path, db_de->d_name);
     110                 :           0 :                 filename = db_path.buf;
     111                 :             : 
     112                 :           0 :                 func(filename, filetype);
     113                 :             :         }
     114                 :           0 :         pop_cleanup(ehflag_normaltidy); /* closedir */
     115                 :             : 
     116                 :           0 :         varbuf_destroy(&db_path);
     117                 :           0 : }
        

Generated by: LCOV version 2.0-1