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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * dpkg - main program for package management
       3                 :            :  * update.c - options which update the ‘available’ database
       4                 :            :  *
       5                 :            :  * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
       6                 :            :  *
       7                 :            :  * This is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License as published by
       9                 :            :  * the Free Software Foundation; either version 2 of the License, or
      10                 :            :  * (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      19                 :            :  */
      20                 :            : 
      21                 :            : #include <config.h>
      22                 :            : #include <compat.h>
      23                 :            : 
      24                 :            : #include <errno.h>
      25                 :            : #include <string.h>
      26                 :            : #include <unistd.h>
      27                 :            : #include <stdlib.h>
      28                 :            : #include <stdio.h>
      29                 :            : 
      30                 :            : #include <dpkg/i18n.h>
      31                 :            : #include <dpkg/dpkg.h>
      32                 :            : #include <dpkg/dpkg-db.h>
      33                 :            : #include <dpkg/options.h>
      34                 :            : 
      35                 :            : #include "main.h"
      36                 :            : 
      37                 :            : int
      38                 :          0 : updateavailable(const char *const *argv)
      39                 :            : {
      40                 :          0 :   const char *sourcefile= argv[0];
      41                 :            :   char *availfile;
      42                 :          0 :   int count= 0;
      43                 :            : 
      44                 :          0 :   modstatdb_init();
      45                 :            : 
      46      [ #  #  # ]:          0 :   switch (cipaction->arg_int) {
      47                 :          0 :   case act_avclear:
      48         [ #  # ]:          0 :     if (sourcefile) badusage(_("--%s takes no arguments"),cipaction->olong);
      49                 :          0 :     break;
      50                 :          0 :   case act_avreplace: case act_avmerge:
      51         [ #  # ]:          0 :     if (sourcefile == NULL)
      52                 :          0 :       sourcefile = "-";
      53         [ #  # ]:          0 :     else if (argv[1])
      54                 :          0 :       badusage(_("--%s takes at most one Packages-file argument"),
      55                 :          0 :                cipaction->olong);
      56                 :          0 :     break;
      57                 :          0 :   default:
      58                 :          0 :     internerr("unknown action '%d'", cipaction->arg_int);
      59                 :            :   }
      60                 :            : 
      61         [ #  # ]:          0 :   if (!f_noact) {
      62                 :          0 :     const char *dbdir = dpkg_db_get_dir();
      63                 :            : 
      64         [ #  # ]:          0 :     if (access(dbdir, W_OK)) {
      65         [ #  # ]:          0 :       if (errno != EACCES)
      66                 :          0 :         ohshite(_("unable to access dpkg database directory '%s' for bulk available update"),
      67                 :            :                 dbdir);
      68                 :            :       else
      69                 :          0 :         ohshit(_("required write access to dpkg database directory '%s' for bulk available update"),
      70                 :            :                dbdir);
      71                 :            :     }
      72                 :          0 :     modstatdb_lock();
      73                 :            :   }
      74                 :            : 
      75   [ #  #  #  # ]:          0 :   switch (cipaction->arg_int) {
      76                 :          0 :   case act_avreplace:
      77                 :          0 :     printf(_("Replacing available packages info, using %s.\n"),sourcefile);
      78                 :          0 :     break;
      79                 :          0 :   case act_avmerge:
      80                 :          0 :     printf(_("Updating available packages info, using %s.\n"),sourcefile);
      81                 :          0 :     break;
      82                 :          0 :   case act_avclear:
      83                 :          0 :     break;
      84                 :          0 :   default:
      85                 :          0 :     internerr("unknown action '%d'", cipaction->arg_int);
      86                 :            :   }
      87                 :            : 
      88                 :          0 :   availfile = dpkg_db_get_path(AVAILFILE);
      89                 :            : 
      90         [ #  # ]:          0 :   if (cipaction->arg_int == act_avmerge)
      91                 :          0 :     parsedb(availfile, pdb_parse_available, NULL);
      92                 :            : 
      93         [ #  # ]:          0 :   if (cipaction->arg_int != act_avclear)
      94                 :          0 :     count += parsedb(sourcefile,
      95                 :            :                      pdb_parse_available | pdb_ignoreolder | pdb_dash_is_stdin,
      96                 :            :                      NULL);
      97                 :            : 
      98         [ #  # ]:          0 :   if (!f_noact) {
      99                 :          0 :     writedb(availfile, wdb_dump_available);
     100                 :          0 :     modstatdb_unlock();
     101                 :            :   }
     102                 :            : 
     103                 :          0 :   free(availfile);
     104                 :            : 
     105         [ #  # ]:          0 :   if (cipaction->arg_int != act_avclear)
     106                 :          0 :     printf(P_("Information about %d package was updated.\n",
     107                 :            :               "Information about %d packages was updated.\n", count), count);
     108                 :            : 
     109                 :          0 :   modstatdb_done();
     110                 :            : 
     111                 :          0 :   return 0;
     112                 :            : }
     113                 :            : 
     114                 :            : int
     115                 :          0 : forgetold(const char *const *argv)
     116                 :            : {
     117         [ #  # ]:          0 :   if (*argv)
     118                 :          0 :     badusage(_("--%s takes no arguments"), cipaction->olong);
     119                 :            : 
     120                 :          0 :   warning(_("obsolete '--%s' option; unavailable packages are automatically cleaned up"),
     121                 :          0 :           cipaction->olong);
     122                 :            : 
     123                 :          0 :   return 0;
     124                 :            : }

Generated by: LCOV version 1.16