summaryrefslogtreecommitdiffstats
path: root/mandocdb.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-04-18 21:55:38 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-04-18 21:55:38 +0000
commit3c3163f61e1d08e084c2481ef1a6b7da8362fe30 (patch)
treea594b3186c406a5f2ef799a717d77c45e7e22d2c /mandocdb.c
parentdafb4fbd722f1a0f28cb0d3e1f8734f7efebd635 (diff)
downloadmandoc-3c3163f61e1d08e084c2481ef1a6b7da8362fe30.tar.gz
In update mode, when opening the database fails, probably because it is
missing or corrupt, just rebuild it from scratch. This also helps when installing the very first port on a freshly installed machine and is similar to what espie@'s classical makewhatis(8) did. Issue reported by naddy@ via kili@.
Diffstat (limited to 'mandocdb.c')
-rw-r--r--mandocdb.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/mandocdb.c b/mandocdb.c
index ebcfd181..206c7781 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -442,15 +442,25 @@ main(int argc, char *argv[])
*/
if (0 == set_basedir(path_arg))
goto out;
- for (i = 0; i < argc; i++)
- filescan(argv[i]);
- if (0 == dbopen(1))
- goto out;
- if (OP_TEST != op)
- dbprune();
+ if (dbopen(1)) {
+ for (i = 0; i < argc; i++)
+ filescan(argv[i]);
+ if (OP_TEST != op)
+ dbprune();
+ } else {
+ /*
+ * Database missing or corrupt.
+ * Recreate from scratch.
+ */
+ op = OP_DEFAULT;
+ if (0 == treescan())
+ goto out;
+ if (0 == dbopen(0))
+ goto out;
+ }
if (OP_DELETE != op)
mpages_merge(mc, mp);
- dbclose(1);
+ dbclose(OP_DEFAULT == op ? 0 : 1);
} else {
/*
* If we have arguments, use them as our manpaths.