2 * libdpkg - Debian packaging suite library routines
3 * pkg-files.c - handle list of filesystem files per package
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2000,2001 Wichert Akkerman <wakkerma@debian.org>
7 * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
9 * This is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 #include <dpkg/i18n.h>
27 #include <dpkg/dpkg.h>
28 #include <dpkg/dpkg-db.h>
29 #include <dpkg/pkg-list.h>
30 #include <dpkg/pkg-files.h>
33 * Erase the files saved in pkg.
36 pkg_files_blank(struct pkginfo
*pkg
)
38 struct fsys_namenode_list
*current
;
40 for (current
= pkg
->files
;
42 current
= current
->next
) {
43 struct pkg_list
**pkg_prev
= ¤t
->namenode
->packages
;
44 struct pkg_list
*pkg_node
;
46 /* For each file that used to be in the package, go through
47 * looking for this package's entry in the list of packages
48 * containing this file, and blank it out. */
49 for (pkg_node
= current
->namenode
->packages
;
51 pkg_node
= pkg_node
->next
) {
52 if (pkg_node
->pkg
== pkg
) {
53 *pkg_prev
= pkg_node
->next
;
55 /* The actual filelist links were allocated
56 * w/ nfmalloc, so we should not free them. */
60 pkg_prev
= &pkg_node
->next
;
66 struct fsys_namenode_list
**
67 pkg_files_add_file(struct pkginfo
*pkg
, struct fsys_namenode
*namenode
,
68 struct fsys_namenode_list
**file_tail
)
70 struct fsys_namenode_list
*newent
;
71 struct pkg_list
*pkg_node
;
73 if (file_tail
== NULL
)
74 file_tail
= &pkg
->files
;
76 /* Make sure we're at the end. */
77 while ((*file_tail
) != NULL
)
78 file_tail
= &((*file_tail
)->next
);
80 /* Create a new node. */
81 newent
= nfmalloc(sizeof(*newent
));
82 newent
->namenode
= namenode
;
85 file_tail
= &newent
->next
;
87 /* Add pkg to newent's package list. */
88 pkg_node
= nfmalloc(sizeof(*pkg_node
));
90 pkg_node
->next
= newent
->namenode
->packages
;
91 newent
->namenode
->packages
= pkg_node
;
93 /* Return the position for the next guy. */