aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mandocdb.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-05-17 22:27:12 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-05-17 22:27:12 +0000
commit5952108d968b7307c891a28c4e3755977a1d25f8 (patch)
treeec448e5ddec89d456f73c638e61c1545e401c676 /mandocdb.c
parent70e375bc0ac2abc353ce19a4a88627775797de77 (diff)
downloadmandoc-5952108d968b7307c891a28c4e3755977a1d25f8.tar.gz
mandoc-5952108d968b7307c891a28c4e3755977a1d25f8.tar.zst
mandoc-5952108d968b7307c891a28c4e3755977a1d25f8.zip
Never create empty databases.
When pkg_add(1)ing packages installing manual pages into some directory, the database in that directory automatically gets created or updated, no change so far. This patch causes the database file to be automatically unlinked when pkg_delete(1)ing the last package having manual pages in that directory, to leave less cruft behind. Suggested by ajacoutot@.
Diffstat (limited to 'mandocdb.c')
-rw-r--r--mandocdb.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/mandocdb.c b/mandocdb.c
index c81106b9..b9e4fb1c 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.249 2017/05/05 15:17:32 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.250 2017/05/17 22:27:12 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -2122,6 +2122,23 @@ dbwrite(struct dba *dba)
int status;
pid_t child;
+ /*
+ * Do not write empty databases, and delete existing ones
+ * when makewhatis -u causes them to become empty.
+ */
+
+ dba_array_start(dba->pages);
+ if (dba_array_next(dba->pages) == NULL) {
+ if (unlink(MANDOC_DB) == -1)
+ say(MANDOC_DB, "&unlink");
+ return;
+ }
+
+ /*
+ * Build the database in a temporary file,
+ * then atomically move it into place.
+ */
+
if (dba_write(MANDOC_DB "~", dba) != -1) {
if (rename(MANDOC_DB "~", MANDOC_DB) == -1) {
exitcode = (int)MANDOCLEVEL_SYSERR;
@@ -2131,6 +2148,11 @@ dbwrite(struct dba *dba)
return;
}
+ /*
+ * We lack write permission and cannot replace the database
+ * file, but let's at least check whether the data changed.
+ */
+
(void)strlcpy(tfn, "/tmp/mandocdb.XXXXXXXX", sizeof(tfn));
if (mkdtemp(tfn) == NULL) {
exitcode = (int)MANDOCLEVEL_SYSERR;