2 * libdpkg - Debian packaging suite library routines
3 * db-fsys-load.c - (re)loading of database of files installed on system
5 * Copyright © 2008-2024 Guillem Jover <guillem@debian.org>
6 * Copyright © 2022 Simon Richter <sjr@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>
30 #include <dpkg/dpkg.h>
31 #include <dpkg/dpkg-db.h>
32 #include <dpkg/db-fsys.h>
33 #include <dpkg/i18n.h>
34 #include <dpkg/debug.h>
37 dpkg_db_reopen(struct dpkg_db
*db
)
42 if (db
->pathname
== NULL
)
43 db
->pathname
= dpkg_db_get_path(db
->name
);
47 file_next
= fopen(db
->pathname
, "r");
50 ohshite(_("cannot open %s file"), db
->pathname
);
52 setcloexec(fileno(file_next
), db
->pathname
);
54 if (fstat(fileno(file_next
), &st_next
))
55 ohshite(_("cannot get %s file metadata"), db
->pathname
);
58 * We need to keep the database file open so that the
59 * filesystem cannot reuse the inode number (f.ex. during
60 * multiple dpkg-divert invocations in a maintainer script),
61 * otherwise the following check might turn true, and we
62 * would skip reloading a modified database.
65 db
->st
.st_dev
== st_next
.st_dev
&&
66 db
->st
.st_ino
== st_next
.st_ino
) {
70 debug(dbg_general
, "%s: unchanged %s, skipping",
71 __func__
, db
->pathname
);
83 debug(dbg_general
, "%s: new %s, (re)loading",
84 __func__
, db
->pathname
);
87 debug(dbg_general
, "%s: missing %s, resetting",
88 __func__
, db
->pathname
);