2 * libdpkg - Debian packaging suite library routines
3 * db-fsys-divert.c - management of filesystem diverted files database
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2000, 2001 Wichert Akkerman <wakkerma@debian.org>
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.
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.
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/>.
25 #include <sys/types.h>
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>
41 static struct fsys_diversion
*diversions
= NULL
;
44 ensure_diversions(void)
46 static struct dpkg_db db
= {
47 .name
= DIVERSIONSFILE
,
49 enum dpkg_db_error rc
;
50 char linebuf
[MAXDIVERTFILENAME
];
51 struct fsys_diversion
*ov
, *oicontest
, *oialtname
;
53 rc
= dpkg_db_reopen(&db
);
54 if (rc
== DPKG_DB_SAME
)
57 for (ov
= diversions
; ov
; ov
= ov
->next
) {
58 ov
->useinstead
->divert
->camefrom
->divert
= NULL
;
59 ov
->useinstead
->divert
= NULL
;
63 if (rc
== DPKG_DB_NONE
)
68 while (fgets_checked(linebuf
, sizeof(linebuf
), db
.file
, db
.pathname
) >= 0) {
69 oicontest
= nfmalloc(sizeof(*oicontest
));
70 oialtname
= nfmalloc(sizeof(*oialtname
));
72 oialtname
->camefrom
= fsys_hash_find_node(linebuf
, FHFF_NONE
);
73 oialtname
->useinstead
= NULL
;
75 fgets_must(linebuf
, sizeof(linebuf
), db
.file
, db
.pathname
);
76 oicontest
->useinstead
= fsys_hash_find_node(linebuf
, FHFF_NONE
);
77 oicontest
->camefrom
= NULL
;
79 fgets_must(linebuf
, sizeof(linebuf
), db
.file
, db
.pathname
);
80 oicontest
->pkgset
= strcmp(linebuf
, ":") ?
81 pkg_hash_find_set(linebuf
) : NULL
;
82 oialtname
->pkgset
= oicontest
->pkgset
;
84 if (oialtname
->camefrom
->divert
||
85 oicontest
->useinstead
->divert
)
86 ohshit(_("conflicting diversions involving '%.250s' or '%.250s'"),
87 oialtname
->camefrom
->name
, oicontest
->useinstead
->name
);
89 oialtname
->camefrom
->divert
= oicontest
;
90 oicontest
->useinstead
->divert
= oialtname
;
92 oicontest
->next
= diversions
;
93 diversions
= oicontest
;