LCOV - code coverage report
Current view: top level - lib/dpkg - pkg.c (source / functions) Hit Total Coverage
Test: dpkg 1.21.11 C code coverage Lines: 100 101 99.0 %
Date: 2022-12-03 00:40:01 Functions: 12 12 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 24 38 63.2 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * libdpkg - Debian packaging suite library routines
       3                 :            :  * pkg.c - primitives for pkg handling
       4                 :            :  *
       5                 :            :  * Copyright © 1995, 1996 Ian Jackson <ijackson@chiark.greenend.org.uk>
       6                 :            :  * Copyright © 2009-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 <string.h>
      26                 :            : 
      27                 :            : #include <dpkg/ehandle.h>
      28                 :            : #include <dpkg/string.h>
      29                 :            : #include <dpkg/dpkg-db.h>
      30                 :            : #include <dpkg/pkg.h>
      31                 :            : 
      32                 :            : /**
      33                 :            :  * Set the package installation status.
      34                 :            :  */
      35                 :            : void
      36                 :         23 : pkg_set_status(struct pkginfo *pkg, enum pkgstatus status)
      37                 :            : {
      38         [ +  + ]:         23 :         if (pkg->status == status)
      39                 :          3 :                 return;
      40         [ +  + ]:         20 :         else if (pkg->status == PKG_STAT_NOTINSTALLED)
      41                 :          9 :                 pkg->set->installed_instances++;
      42         [ +  + ]:         11 :         else if (status == PKG_STAT_NOTINSTALLED)
      43                 :          5 :                 pkg->set->installed_instances--;
      44                 :            : 
      45         [ -  + ]:         20 :         if (pkg->set->installed_instances < 0)
      46                 :          0 :                 internerr("pkgset %s went into negative installed instances %d",
      47                 :            :                           pkg->set->name, pkg->set->installed_instances);
      48                 :            : 
      49                 :         20 :         pkg->status = status;
      50                 :         20 :         pkg->status_dirty = true;
      51                 :            : }
      52                 :            : 
      53                 :            : /**
      54                 :            :  * Set the specified flags to 1 in the package error flags.
      55                 :            :  */
      56                 :            : void
      57                 :          2 : pkg_set_eflags(struct pkginfo *pkg, enum pkgeflag eflag)
      58                 :            : {
      59                 :          2 :         pkg->eflag |= eflag;
      60                 :          2 : }
      61                 :            : 
      62                 :            : /**
      63                 :            :  * Clear the specified flags to 0 in the package error flags.
      64                 :            :  */
      65                 :            : void
      66                 :          1 : pkg_clear_eflags(struct pkginfo *pkg, enum pkgeflag eflag)
      67                 :            : {
      68                 :          1 :         pkg->eflag &= ~eflag;
      69                 :          1 : }
      70                 :            : 
      71                 :            : /**
      72                 :            :  * Reset the package error flags to 0.
      73                 :            :  */
      74                 :            : void
      75                 :          1 : pkg_reset_eflags(struct pkginfo *pkg)
      76                 :            : {
      77                 :          1 :         pkg->eflag = PKG_EFLAG_OK;
      78                 :          1 : }
      79                 :            : 
      80                 :            : /**
      81                 :            :  * Copy the package error flags to another package.
      82                 :            :  */
      83                 :            : void
      84                 :          1 : pkg_copy_eflags(struct pkginfo *pkg_dst, struct pkginfo *pkg_src)
      85                 :            : {
      86                 :          1 :         pkg_dst->eflag = pkg_src->eflag;
      87                 :          1 : }
      88                 :            : 
      89                 :            : /**
      90                 :            :  * Set the package selection status.
      91                 :            :  */
      92                 :            : void
      93                 :          2 : pkg_set_want(struct pkginfo *pkg, enum pkgwant want)
      94                 :            : {
      95                 :          2 :         pkg->want = want;
      96                 :          2 : }
      97                 :            : 
      98                 :            : void
      99                 :        208 : pkgbin_blank(struct pkgbin *pkgbin)
     100                 :            : {
     101                 :        208 :         pkgbin->essential = false;
     102                 :        208 :         pkgbin->is_protected = false;
     103                 :        208 :         pkgbin->depends = NULL;
     104                 :        208 :         pkgbin->pkgname_archqual = NULL;
     105                 :        208 :         pkgbin->description = NULL;
     106                 :        208 :         pkgbin->maintainer = NULL;
     107                 :        208 :         pkgbin->source = NULL;
     108                 :        208 :         pkgbin->installedsize = NULL;
     109                 :        208 :         pkgbin->bugs = NULL;
     110                 :        208 :         pkgbin->origin = NULL;
     111                 :        208 :         dpkg_version_blank(&pkgbin->version);
     112                 :        208 :         pkgbin->conffiles = NULL;
     113                 :        208 :         pkgbin->arbs = NULL;
     114                 :        208 : }
     115                 :            : 
     116                 :            : void
     117                 :        104 : pkg_blank(struct pkginfo *pkg)
     118                 :            : {
     119                 :        104 :         pkg->status = PKG_STAT_NOTINSTALLED;
     120                 :        104 :         pkg->status_dirty = false;
     121                 :        104 :         pkg->eflag = PKG_EFLAG_OK;
     122                 :        104 :         pkg->want = PKG_WANT_UNKNOWN;
     123                 :        104 :         pkg->priority = PKG_PRIO_UNKNOWN;
     124                 :        104 :         pkg->otherpriority = NULL;
     125                 :        104 :         pkg->section = NULL;
     126                 :        104 :         dpkg_version_blank(&pkg->configversion);
     127                 :        104 :         pkg->files_list_valid = false;
     128                 :        104 :         pkg->files_list_phys_offs = 0;
     129                 :        104 :         pkg->files = NULL;
     130                 :        104 :         pkg->archives = NULL;
     131                 :        104 :         pkg->clientdata = NULL;
     132                 :        104 :         pkg->trigaw.head = NULL;
     133                 :        104 :         pkg->trigaw.tail = NULL;
     134                 :        104 :         pkg->othertrigaw_head = NULL;
     135                 :        104 :         pkg->trigpend_head = NULL;
     136                 :        104 :         pkgbin_blank(&pkg->installed);
     137                 :        104 :         pkgbin_blank(&pkg->available);
     138                 :            : 
     139                 :            :         /* The architectures are reset here (instead of in pkgbin_blank),
     140                 :            :          * because they are part of the package specification, and needed
     141                 :            :          * for selections. */
     142                 :        104 :         pkg->installed.arch = dpkg_arch_get(DPKG_ARCH_NONE);
     143                 :        104 :         pkg->installed.multiarch = PKG_MULTIARCH_NO;
     144                 :        104 :         pkg->available.arch = dpkg_arch_get(DPKG_ARCH_NONE);
     145                 :        104 :         pkg->available.multiarch = PKG_MULTIARCH_NO;
     146                 :        104 : }
     147                 :            : 
     148                 :            : void
     149                 :         94 : pkgset_blank(struct pkgset *set)
     150                 :            : {
     151                 :         94 :         set->name = NULL;
     152                 :         94 :         set->depended.available = NULL;
     153                 :         94 :         set->depended.installed = NULL;
     154                 :         94 :         pkg_blank(&set->pkg);
     155                 :         94 :         set->installed_instances = 0;
     156                 :         94 :         set->pkg.set = set;
     157                 :         94 :         set->pkg.arch_next = NULL;
     158                 :         94 : }
     159                 :            : 
     160                 :            : /**
     161                 :            :  * Link a pkginfo instance into a package set.
     162                 :            :  *
     163                 :            :  * @param set The package set to use.
     164                 :            :  * @param pkg The package to link into the set.
     165                 :            :  */
     166                 :            : void
     167                 :          5 : pkgset_link_pkg(struct pkgset *set, struct pkginfo *pkg)
     168                 :            : {
     169                 :          5 :         pkg->set = set;
     170                 :          5 :         pkg->arch_next = set->pkg.arch_next;
     171                 :          5 :         set->pkg.arch_next = pkg;
     172                 :          5 : }
     173                 :            : 
     174                 :            : /**
     175                 :            :  * Get the number of installed package instances in a package set.
     176                 :            :  *
     177                 :            :  * @param set The package set to use.
     178                 :            :  *
     179                 :            :  * @return The count of installed packages.
     180                 :            :  */
     181                 :            : int
     182                 :         94 : pkgset_installed_instances(struct pkgset *set)
     183                 :            : {
     184                 :         94 :         return set->installed_instances;
     185                 :            : }
     186                 :            : 
     187                 :            : /**
     188                 :            :  * Check if a pkg is informative.
     189                 :            :  *
     190                 :            :  * Used by dselect and dpkg query options as an aid to decide whether to
     191                 :            :  * display things, and by dump to decide whether to write them out.
     192                 :            :  */
     193                 :            : bool
     194                 :          3 : pkg_is_informative(struct pkginfo *pkg, struct pkgbin *pkgbin)
     195                 :            : {
     196                 :            :         /* We ignore Section and Priority, as these tend to hang around. */
     197         [ +  - ]:          3 :         if (pkgbin == &pkg->installed &&
     198         [ +  + ]:          3 :             (pkg->want != PKG_WANT_UNKNOWN ||
     199         [ +  - ]:          2 :              pkg->eflag != PKG_EFLAG_OK ||
     200   [ +  -  -  + ]:          4 :              pkg->status != PKG_STAT_NOTINSTALLED ||
     201                 :          2 :              dpkg_version_is_informative(&pkg->configversion)))
     202                 :          1 :                 return true;
     203                 :            : 
     204   [ +  -  +  + ]:          4 :         if (pkgbin->depends ||
     205         [ +  - ]:          3 :             str_is_set(pkgbin->description) ||
     206         [ +  - ]:          2 :             str_is_set(pkgbin->maintainer) ||
     207         [ +  - ]:          2 :             str_is_set(pkgbin->origin) ||
     208         [ +  - ]:          2 :             str_is_set(pkgbin->bugs) ||
     209         [ +  - ]:          2 :             str_is_set(pkgbin->installedsize) ||
     210         [ +  - ]:          2 :             str_is_set(pkgbin->source) ||
     211                 :          1 :             dpkg_version_is_informative(&pkgbin->version) ||
     212         [ +  - ]:          1 :             pkgbin->conffiles ||
     213         [ -  + ]:          1 :             pkgbin->arbs)
     214                 :          1 :                 return true;
     215                 :            : 
     216                 :          1 :         return false;
     217                 :            : }

Generated by: LCOV version 1.16