Branch data Line data Source code
1 : : /*
2 : : * libdpkg - Debian packaging suite library routines
3 : : * db-fsys-divert.c - management of filesystem diverted files database
4 : : *
5 : : * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 : : * Copyright © 2000, 2001 Wichert Akkerman <wakkerma@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 : :
27 : : #include <errno.h>
28 : : #include <string.h>
29 : : #include <pwd.h>
30 : : #include <grp.h>
31 : : #include <fcntl.h>
32 : : #include <unistd.h>
33 : : #include <stdlib.h>
34 : :
35 : : #include <dpkg/i18n.h>
36 : : #include <dpkg/dpkg.h>
37 : : #include <dpkg/dpkg-db.h>
38 : : #include <dpkg/debug.h>
39 : : #include <dpkg/db-fsys.h>
40 : :
41 : : static struct fsys_diversion *diversions = NULL;
42 : :
43 : : void
44 : 74 : ensure_diversions(void)
45 : : {
46 : : static struct dpkg_db db = {
47 : : .name = DIVERSIONSFILE,
48 : : };
49 : : enum dpkg_db_error rc;
50 : : char linebuf[MAXDIVERTFILENAME];
51 : : struct fsys_diversion *ov, *oicontest, *oialtname;
52 : :
53 : 74 : rc = dpkg_db_reopen(&db);
54 [ - + ]: 73 : if (rc == DPKG_DB_SAME)
55 : 1 : return;
56 : :
57 [ - + ]: 73 : for (ov = diversions; ov; ov = ov->next) {
58 : 0 : ov->useinstead->divert->camefrom->divert = NULL;
59 : 0 : ov->useinstead->divert = NULL;
60 : : }
61 : 73 : diversions = NULL;
62 : :
63 [ + + ]: 73 : if (rc == DPKG_DB_NONE)
64 : 1 : return;
65 : :
66 : 72 : onerr_abort++;
67 : :
68 [ + + ]: 158 : while (fgets_checked(linebuf, sizeof(linebuf), db.file, db.pathname) >= 0) {
69 : 88 : oicontest = nfmalloc(sizeof(*oicontest));
70 : 88 : oialtname = nfmalloc(sizeof(*oialtname));
71 : :
72 : 88 : oialtname->camefrom = fsys_hash_find_node(linebuf, FHFF_NONE);
73 : 88 : oialtname->useinstead = NULL;
74 : :
75 : 88 : fgets_must(linebuf, sizeof(linebuf), db.file, db.pathname);
76 : 87 : oicontest->useinstead = fsys_hash_find_node(linebuf, FHFF_NONE);
77 : 87 : oicontest->camefrom = NULL;
78 : :
79 : 87 : fgets_must(linebuf, sizeof(linebuf), db.file, db.pathname);
80 : 172 : oicontest->pkgset = strcmp(linebuf, ":") ?
81 [ + + ]: 86 : pkg_hash_find_set(linebuf) : NULL;
82 : 86 : oialtname->pkgset = oicontest->pkgset;
83 : :
84 [ + - ]: 86 : if (oialtname->camefrom->divert ||
85 [ - + ]: 86 : oicontest->useinstead->divert)
86 : 0 : ohshit(_("conflicting diversions involving '%.250s' or '%.250s'"),
87 : 0 : oialtname->camefrom->name, oicontest->useinstead->name);
88 : :
89 : 86 : oialtname->camefrom->divert = oicontest;
90 : 86 : oicontest->useinstead->divert = oialtname;
91 : :
92 : 86 : oicontest->next = diversions;
93 : 86 : diversions = oicontest;
94 : : }
95 : :
96 : 70 : onerr_abort--;
97 : : }
|