summaryrefslogtreecommitdiffstats
path: root/mandocdb.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-01-06 15:32:47 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-01-06 15:32:47 +0000
commit64929c4dd7ee9b3c9e2f16421b938ea9ffc8696c (patch)
tree2af9b558dfd582fc8adb945c7522d1dd4425638b /mandocdb.c
parentafc3ef1963eab2ca62a7689ca50f8f8f34febc3d (diff)
downloadmandoc-64929c4dd7ee9b3c9e2f16421b938ea9ffc8696c.tar.gz
Fix mandocdb(8) -d and -u.
It was broken by recent optimizations.
Diffstat (limited to 'mandocdb.c')
-rw-r--r--mandocdb.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/mandocdb.c b/mandocdb.c
index ef445ea1..c5c7e5b6 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -700,11 +700,19 @@ filescan(const char *file)
exitcode = (int)MANDOCLEVEL_BADARG;
say(file, NULL);
return;
- } else if (OP_TEST != op && strstr(buf, basedir) != buf) {
+ }
+
+ if (strstr(buf, basedir) == buf)
+ start = buf + strlen(basedir) + 1;
+ else if (OP_TEST == op)
+ start = buf;
+ else {
exitcode = (int)MANDOCLEVEL_BADARG;
say("", "%s: outside base directory", buf);
return;
- } else if (-1 == stat(buf, &st)) {
+ }
+
+ if (-1 == stat(buf, &st)) {
exitcode = (int)MANDOCLEVEL_BADARG;
say(file, NULL);
return;
@@ -713,7 +721,7 @@ filescan(const char *file)
say(file, "Not a regular file");
return;
}
- start = buf + strlen(basedir);
+
mlink = mandoc_calloc(1, sizeof(struct mlink));
strlcpy(mlink->file, start, sizeof(mlink->file));
@@ -1791,20 +1799,31 @@ dbprune(void)
size_t i;
unsigned int slot;
- if (nodb)
- return;
+ if (0 == nodb)
+ SQL_EXEC("BEGIN TRANSACTION");
- mpage = ohash_first(&mpages, &slot);
- while (NULL != mpage) {
+ for (mpage = ohash_first(&mpages, &slot); NULL != mpage;
+ mpage = ohash_next(&mpages, &slot)) {
mlink = mpage->mlinks;
- i = 1;
- SQL_BIND_TEXT(stmts[STMT_DELETE_PAGE], i, mlink->file);
- SQL_STEP(stmts[STMT_DELETE_PAGE]);
- sqlite3_reset(stmts[STMT_DELETE_PAGE]);
if (verb)
- say(mlink->file, "Deleted from database");
- mpage = ohash_next(&mpages, &slot);
+ say(mlink->file, "Deleting from database");
+ if (nodb)
+ continue;
+ for ( ; NULL != mlink; mlink = mlink->next) {
+ i = 1;
+ SQL_BIND_TEXT(stmts[STMT_DELETE_PAGE],
+ i, mlink->dsec);
+ SQL_BIND_TEXT(stmts[STMT_DELETE_PAGE],
+ i, mlink->arch);
+ SQL_BIND_TEXT(stmts[STMT_DELETE_PAGE],
+ i, mlink->name);
+ SQL_STEP(stmts[STMT_DELETE_PAGE]);
+ sqlite3_reset(stmts[STMT_DELETE_PAGE]);
+ }
}
+
+ if (0 == nodb)
+ SQL_EXEC("END TRANSACTION");
}
/*
@@ -1915,7 +1934,9 @@ dbopen(int real)
prepare_statements:
SQL_EXEC("PRAGMA foreign_keys = ON");
- sql = "DELETE FROM mpages where file=?";
+ sql = "DELETE FROM mpages WHERE id IN "
+ "(SELECT pageid FROM mlinks WHERE "
+ "sec=? AND arch=? AND name=?)";
sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_DELETE_PAGE], NULL);
sql = "INSERT INTO mpages "
"(form) VALUES (?)";