chiark / gitweb /
lib/dpkg/tarfn.c: Kludge `tar_header_decode' to handle spurious `errno'.
[dpkg] / src / update.c
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 updateavailable(const char *const *argv)
39 {
40   const char *sourcefile= argv[0];
41   char *availfile;
42   int count= 0;
43
44   modstatdb_init();
45
46   switch (cipaction->arg_int) {
47   case act_avclear:
48     if (sourcefile) badusage(_("--%s takes no arguments"),cipaction->olong);
49     break;
50   case act_avreplace: case act_avmerge:
51     if (sourcefile == NULL)
52       sourcefile = "-";
53     else if (sourcefile && argv[1])
54       badusage(_("--%s takes at most one Packages-file argument"),
55                cipaction->olong);
56     break;
57   default:
58     internerr("unknown action '%d'", cipaction->arg_int);
59   }
60
61   if (!f_noact) {
62     if (access(dpkg_db_get_dir(), W_OK)) {
63       if (errno != EACCES)
64         ohshite(_("unable to access dpkg status area for bulk available update"));
65       else
66         ohshit(_("bulk available update requires write access to dpkg status area"));
67     }
68     modstatdb_lock();
69   }
70
71   switch (cipaction->arg_int) {
72   case act_avreplace:
73     printf(_("Replacing available packages info, using %s.\n"),sourcefile);
74     break;
75   case act_avmerge:
76     printf(_("Updating available packages info, using %s.\n"),sourcefile);
77     break;
78   case act_avclear:
79     break;
80   default:
81     internerr("unknown action '%d'", cipaction->arg_int);
82   }
83
84   availfile = dpkg_db_get_path(AVAILFILE);
85
86   if (cipaction->arg_int == act_avmerge)
87     parsedb(availfile, pdb_parse_available, NULL);
88
89   if (cipaction->arg_int != act_avclear)
90     count += parsedb(sourcefile,
91                      pdb_parse_available | pdb_ignoreolder | pdb_dash_is_stdin,
92                      NULL);
93
94   if (!f_noact) {
95     writedb(availfile, wdb_dump_available);
96     modstatdb_unlock();
97   }
98
99   free(availfile);
100
101   if (cipaction->arg_int != act_avclear)
102     printf(P_("Information about %d package was updated.\n",
103               "Information about %d packages was updated.\n", count), count);
104
105   modstatdb_done();
106
107   return 0;
108 }
109
110 int
111 forgetold(const char *const *argv)
112 {
113   if (*argv)
114     badusage(_("--%s takes no arguments"), cipaction->olong);
115
116   warning(_("obsolete '--%s' option; unavailable packages are automatically cleaned up"),
117           cipaction->olong);
118
119   return 0;
120 }