LCOV - code coverage report
Current view: top level - src/main - select.c (source / functions) Coverage Total Hit
Test: dpkg 1.22.7-3-g89f48 C code coverage Lines: 0.0 % 118 0
Test Date: 2024-07-17 02:53:43 Functions: 0.0 % 4 0
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0.0 % 88 0

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * dpkg - main program for package management
       3                 :             :  * select.c - by-hand (rather than dselect-based) package selection
       4                 :             :  *
       5                 :             :  * Copyright © 1995,1996 Ian Jackson <ijackson@chiark.greenend.org.uk>
       6                 :             :  * Copyright © 2006, 2008-2015 Guillem Jover <guillem@debian.org>
       7                 :             :  * Copyright © 2011 Linaro Limited
       8                 :             :  * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
       9                 :             :  *
      10                 :             :  * This is free software; you can redistribute it and/or modify
      11                 :             :  * it under the terms of the GNU General Public License as published by
      12                 :             :  * the Free Software Foundation; either version 2 of the License, or
      13                 :             :  * (at your option) any later version.
      14                 :             :  *
      15                 :             :  * This is distributed in the hope that it will be useful,
      16                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      17                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18                 :             :  * GNU General Public License for more details.
      19                 :             :  *
      20                 :             :  * You should have received a copy of the GNU General Public License
      21                 :             :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      22                 :             :  */
      23                 :             : 
      24                 :             : #include <config.h>
      25                 :             : #include <compat.h>
      26                 :             : 
      27                 :             : #include <fnmatch.h>
      28                 :             : #include <string.h>
      29                 :             : #include <stdlib.h>
      30                 :             : #include <stdio.h>
      31                 :             : 
      32                 :             : #include <dpkg/i18n.h>
      33                 :             : #include <dpkg/c-ctype.h>
      34                 :             : #include <dpkg/dpkg.h>
      35                 :             : #include <dpkg/dpkg-db.h>
      36                 :             : #include <dpkg/pkg-array.h>
      37                 :             : #include <dpkg/pkg-show.h>
      38                 :             : #include <dpkg/pkg-spec.h>
      39                 :             : #include <dpkg/options.h>
      40                 :             : #include <dpkg/db-ctrl.h>
      41                 :             : #include <dpkg/db-fsys.h>
      42                 :             : 
      43                 :             : #include "main.h"
      44                 :             : 
      45                 :           0 : static void getsel1package(struct pkginfo *pkg) {
      46                 :             :   const char *pkgname;
      47                 :             :   int l;
      48                 :             : 
      49         [ #  # ]:           0 :   if (pkg->want == PKG_WANT_UNKNOWN)
      50                 :           0 :     return;
      51                 :           0 :   pkgname = pkg_name(pkg, pnaw_nonambig);
      52                 :           0 :   l = strlen(pkgname);
      53                 :           0 :   l >>= 3;
      54                 :           0 :   l = 6 - l;
      55         [ #  # ]:           0 :   if (l < 1)
      56                 :           0 :     l = 1;
      57                 :           0 :   printf("%s%.*s%s\n", pkgname, l, "\t\t\t\t\t\t", pkg_want_name(pkg));
      58                 :             : }
      59                 :             : 
      60                 :             : int
      61                 :           0 : getselections(const char *const *argv)
      62                 :             : {
      63                 :             :   struct pkg_array array;
      64                 :             :   struct pkginfo *pkg;
      65                 :             :   int i;
      66                 :             : 
      67                 :           0 :   modstatdb_open(msdbrw_readonly);
      68                 :             : 
      69                 :           0 :   pkg_array_init_from_hash(&array);
      70                 :           0 :   pkg_array_sort(&array, pkg_sorter_by_nonambig_name_arch);
      71                 :             : 
      72         [ #  # ]:           0 :   if (!*argv) {
      73         [ #  # ]:           0 :     for (i = 0; i < array.n_pkgs; i++) {
      74                 :           0 :       pkg = array.pkgs[i];
      75         [ #  # ]:           0 :       if (pkg->status == PKG_STAT_NOTINSTALLED)
      76                 :           0 :         continue;
      77                 :           0 :       getsel1package(pkg);
      78                 :             :     }
      79                 :             :   } else {
      80                 :             :     const char *thisarg;
      81                 :             : 
      82         [ #  # ]:           0 :     while ((thisarg= *argv++)) {
      83                 :             :       struct pkg_spec pkgspec;
      84                 :             :       int found;
      85                 :             : 
      86                 :           0 :       found= 0;
      87                 :           0 :       pkg_spec_init(&pkgspec, PKG_SPEC_PATTERNS | PKG_SPEC_ARCH_WILDCARD);
      88                 :           0 :       pkg_spec_parse(&pkgspec, thisarg);
      89                 :             : 
      90         [ #  # ]:           0 :       for (i = 0; i < array.n_pkgs; i++) {
      91                 :           0 :         pkg = array.pkgs[i];
      92         [ #  # ]:           0 :         if (!pkg_spec_match_pkg(&pkgspec, pkg, &pkg->installed))
      93                 :           0 :           continue;
      94                 :           0 :         getsel1package(pkg); found++;
      95                 :             :       }
      96         [ #  # ]:           0 :       if (!found)
      97                 :           0 :         notice(_("no packages found matching %s"), thisarg);
      98                 :             : 
      99                 :           0 :       pkg_spec_destroy(&pkgspec);
     100                 :             :     }
     101                 :             :   }
     102                 :             : 
     103                 :           0 :   m_output(stdout, _("<standard output>"));
     104                 :           0 :   m_output(stderr, _("<standard error>"));
     105                 :             : 
     106                 :           0 :   pkg_array_destroy(&array);
     107                 :             : 
     108                 :           0 :   modstatdb_shutdown();
     109                 :             : 
     110                 :           0 :   return 0;
     111                 :             : }
     112                 :             : 
     113                 :             : int
     114                 :           0 : setselections(const char *const *argv)
     115                 :             : {
     116                 :             :   enum modstatdb_rw msdbflags;
     117                 :             :   const struct namevalue *nv;
     118                 :             :   struct pkginfo *pkg;
     119                 :             :   int c, lno;
     120                 :           0 :   struct varbuf namevb = VARBUF_INIT;
     121                 :           0 :   struct varbuf selvb = VARBUF_INIT;
     122                 :           0 :   bool db_possibly_outdated = false;
     123                 :             : 
     124         [ #  # ]:           0 :   if (*argv)
     125                 :           0 :     badusage(_("--%s takes no arguments"), cipaction->olong);
     126                 :             : 
     127                 :           0 :   msdbflags = msdbrw_available_readonly;
     128         [ #  # ]:           0 :   if (f_noact)
     129                 :           0 :     msdbflags |= msdbrw_readonly;
     130                 :             :   else
     131                 :           0 :     msdbflags |= msdbrw_write;
     132                 :             : 
     133                 :           0 :   modstatdb_open(msdbflags);
     134                 :           0 :   pkg_infodb_upgrade();
     135                 :             : 
     136                 :           0 :   lno= 1;
     137                 :           0 :   for (;;) {
     138                 :             :     struct dpkg_error err;
     139                 :             : 
     140                 :             :     do {
     141                 :           0 :       c = getchar();
     142         [ #  # ]:           0 :       if (c == '\n')
     143                 :           0 :         lno++;
     144   [ #  #  #  # ]:           0 :     } while (c != EOF && c_isspace(c));
     145         [ #  # ]:           0 :     if (c == EOF) break;
     146         [ #  # ]:           0 :     if (c == '#') {
     147   [ #  #  #  #  :           0 :       do { c= getchar(); if (c == '\n') lno++; } while (c != EOF && c != '\n');
                   #  # ]
     148                 :           0 :       continue;
     149                 :             :     }
     150                 :             : 
     151                 :           0 :     varbuf_reset(&namevb);
     152         [ #  # ]:           0 :     while (!c_isspace(c)) {
     153                 :           0 :       varbuf_add_char(&namevb, c);
     154                 :           0 :       c= getchar();
     155         [ #  # ]:           0 :       if (c == EOF)
     156                 :           0 :         ohshit(_("unexpected end of file in package name at line %d"), lno);
     157         [ #  # ]:           0 :       if (c == '\n') ohshit(_("unexpected end of line in package name at line %d"),lno);
     158                 :             :     }
     159                 :             : 
     160   [ #  #  #  # ]:           0 :     while (c != EOF && c_isspace(c)) {
     161                 :           0 :       c= getchar();
     162         [ #  # ]:           0 :       if (c == EOF)
     163                 :           0 :         ohshit(_("unexpected end of file after package name at line %d"), lno);
     164         [ #  # ]:           0 :       if (c == '\n') ohshit(_("unexpected end of line after package name at line %d"),lno);
     165                 :             :     }
     166                 :             : 
     167                 :           0 :     varbuf_reset(&selvb);
     168   [ #  #  #  # ]:           0 :     while (c != EOF && !c_isspace(c)) {
     169                 :           0 :       varbuf_add_char(&selvb, c);
     170                 :           0 :       c= getchar();
     171                 :             :     }
     172                 :             : 
     173   [ #  #  #  # ]:           0 :     while (c != EOF && c != '\n') {
     174                 :           0 :       c= getchar();
     175         [ #  # ]:           0 :       if (!c_isspace(c))
     176                 :           0 :         ohshit(_("unexpected data after package and selection at line %d"),lno);
     177                 :             :     }
     178                 :           0 :     pkg = pkg_spec_parse_pkg(varbuf_str(&namevb), &err);
     179         [ #  # ]:           0 :     if (pkg == NULL)
     180                 :           0 :       ohshit(_("illegal package name at line %d: %.250s"), lno, err.str);
     181                 :             : 
     182         [ #  # ]:           0 :     if (!pkg_is_informative(pkg, &pkg->installed) &&
     183         [ #  # ]:           0 :         !pkg_is_informative(pkg, &pkg->available)) {
     184                 :           0 :       db_possibly_outdated = true;
     185                 :           0 :       warning(_("package not in status nor available database at line %d: %.250s"),
     186                 :             :               lno, varbuf_str(&namevb));
     187                 :           0 :       lno++;
     188                 :           0 :       continue;
     189                 :             :     }
     190                 :             : 
     191                 :           0 :     nv = namevalue_find_by_name(wantinfos, varbuf_str(&selvb));
     192         [ #  # ]:           0 :     if (nv == NULL)
     193                 :           0 :       ohshit(_("unknown wanted status at line %d: %.250s"),
     194                 :             :              lno, varbuf_str(&selvb));
     195                 :             : 
     196                 :           0 :     pkg_set_want(pkg, nv->value);
     197         [ #  # ]:           0 :     if (c == EOF) break;
     198                 :           0 :     lno++;
     199                 :             :   }
     200         [ #  # ]:           0 :   if (ferror(stdin)) ohshite(_("read error on standard input"));
     201                 :           0 :   modstatdb_shutdown();
     202                 :           0 :   varbuf_destroy(&namevb);
     203                 :           0 :   varbuf_destroy(&selvb);
     204                 :             : 
     205         [ #  # ]:           0 :   if (db_possibly_outdated)
     206                 :           0 :     warning(_("found unknown packages; this might mean the available database\n"
     207                 :             :               "is outdated, and needs to be updated through a frontend method;\n"
     208                 :             :               "please see the FAQ <https://wiki.debian.org/Teams/Dpkg/FAQ#set-selections>"));
     209                 :             : 
     210                 :           0 :   return 0;
     211                 :             : }
     212                 :             : 
     213                 :             : int
     214                 :           0 : clearselections(const char *const *argv)
     215                 :             : {
     216                 :             :   enum modstatdb_rw msdbflags;
     217                 :             :   struct pkg_hash_iter *iter;
     218                 :             :   struct pkginfo *pkg;
     219                 :             : 
     220         [ #  # ]:           0 :   if (*argv)
     221                 :           0 :     badusage(_("--%s takes no arguments"), cipaction->olong);
     222                 :             : 
     223         [ #  # ]:           0 :   if (f_noact)
     224                 :           0 :     msdbflags = msdbrw_readonly;
     225                 :             :   else
     226                 :           0 :     msdbflags = msdbrw_write;
     227                 :             : 
     228                 :           0 :   modstatdb_open(msdbflags);
     229                 :           0 :   pkg_infodb_upgrade();
     230                 :             : 
     231                 :           0 :   iter = pkg_hash_iter_new();
     232         [ #  # ]:           0 :   while ((pkg = pkg_hash_iter_next_pkg(iter))) {
     233         [ #  # ]:           0 :     if (!pkg->installed.essential &&
     234         [ #  # ]:           0 :         !pkg->installed.is_protected &&
     235         [ #  # ]:           0 :         pkg->want != PKG_WANT_UNKNOWN)
     236                 :           0 :       pkg_set_want(pkg, PKG_WANT_DEINSTALL);
     237                 :             :   }
     238                 :           0 :   pkg_hash_iter_free(iter);
     239                 :             : 
     240                 :           0 :   modstatdb_shutdown();
     241                 :             : 
     242                 :           0 :   return 0;
     243                 :             : }
     244                 :             : 
        

Generated by: LCOV version 2.0-1