Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-6]: src/usr.sbin/makemandb Pull up following revision(s) (request...
details: https://anonhg.NetBSD.org/src/rev/1381a3ace941
branches: netbsd-6
changeset: 773862:1381a3ace941
user: riz <riz%NetBSD.org@localhost>
date: Fri Mar 02 17:02:00 2012 +0000
description:
Pull up following revision(s) (requested by joerg in ticket #70):
usr.sbin/makemandb/makemandb.c: revision 1.6
Expand workaround for .so usage to do the chdir call just before
starting parsing, not during the tree iteration. This gives it a chance
to work.
diffstat:
usr.sbin/makemandb/makemandb.c | 52 ++++++++++++++++++++++++++++-------------
1 files changed, 35 insertions(+), 17 deletions(-)
diffs (161 lines):
diff -r ee240de2aefa -r 1381a3ace941 usr.sbin/makemandb/makemandb.c
--- a/usr.sbin/makemandb/makemandb.c Fri Mar 02 16:50:53 2012 +0000
+++ b/usr.sbin/makemandb/makemandb.c Fri Mar 02 17:02:00 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: makemandb.c,v 1.2.2.1 2012/02/18 18:03:26 riz Exp $ */
+/* $NetBSD: makemandb.c,v 1.2.2.2 2012/03/02 17:02:00 riz Exp $ */
/*
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
* Copyright (c) 2011 Kristaps Dzonsons <kristaps%bsd.lv@localhost>
@@ -17,7 +17,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: makemandb.c,v 1.2.2.1 2012/02/18 18:03:26 riz Exp $");
+__RCSID("$NetBSD: makemandb.c,v 1.2.2.2 2012/03/02 17:02:00 riz Exp $");
#include <sys/stat.h>
#include <sys/types.h>
@@ -115,10 +115,11 @@
static void pman_parse_name(const struct man_node *, mandb_rec *);
static void pman_sh(const struct man_node *, mandb_rec *);
static void pman_block(const struct man_node *, mandb_rec *);
-static void traversedir(const char *, sqlite3 *, struct mparse *);
+static void traversedir(const char *, const char *, sqlite3 *, struct mparse *);
static void mdoc_parse_section(enum mdoc_sec, const char *, mandb_rec *);
static void man_parse_section(enum man_sec, const struct man_node *, mandb_rec *);
-static void build_file_cache(sqlite3 *, const char *, struct stat *);
+static void build_file_cache(sqlite3 *, const char *, const char *,
+ struct stat *);
static void update_db(sqlite3 *, struct mparse *, mandb_rec *);
__dead static void usage(void);
static void optimize(sqlite3 *);
@@ -380,9 +381,9 @@
exit(EXIT_FAILURE);
}
- sqlstr = "CREATE TABLE IF NOT EXISTS metadb.file_cache(device, inode,"
- " mtime, file PRIMARY KEY);"
- "CREATE UNIQUE INDEX IF NOT EXISTS metadb.index_file_cache_dev"
+ sqlstr = "CREATE TABLE metadb.file_cache(device, inode, mtime, parent,"
+ " file PRIMARY KEY);"
+ "CREATE UNIQUE INDEX metadb.index_file_cache_dev"
" ON file_cache (device, inode)";
sqlite3_exec(db, sqlstr, NULL, NULL, &errmsg);
@@ -401,10 +402,11 @@
/* Replace the new line character at the end of string with '\0' */
line[len - 1] = '\0';
parent = estrdup(line);
- chdir(dirname(parent));
+ char *pdir = estrdup(dirname(parent));
free(parent);
/* Traverse the man page directories and parse the pages */
- traversedir(line, db, mp);
+ traversedir(pdir, line, db, mp);
+ free(pdir);
}
free(line);
@@ -440,7 +442,8 @@
* in the way to build_file_cache()
*/
static void
-traversedir(const char *file, sqlite3 *db, struct mparse *mp)
+traversedir(const char *parent, const char *file, sqlite3 *db,
+ struct mparse *mp)
{
struct stat sb;
struct dirent *dirp;
@@ -454,7 +457,7 @@
/* If it is a regular file or a symlink, pass it to build_cache() */
if (S_ISREG(sb.st_mode) || S_ISLNK(sb.st_mode)) {
- build_file_cache(db, file, &sb);
+ build_file_cache(db, parent, file, &sb);
return;
}
@@ -469,7 +472,7 @@
/* Avoid . and .. entries in a directory */
if (strncmp(dirp->d_name, ".", 1)) {
easprintf(&buf, "%s/%s", file, dirp->d_name);
- traversedir(buf, db, mp);
+ traversedir(parent, buf, db, mp);
free(buf);
}
}
@@ -485,7 +488,8 @@
* update_db(), once the database has been updated.
*/
static void
-build_file_cache(sqlite3 *db, const char *file, struct stat *sb)
+build_file_cache(sqlite3 *db, const char *parent, const char *file,
+ struct stat *sb)
{
const char *sqlstr;
sqlite3_stmt *stmt = NULL;
@@ -496,7 +500,7 @@
time_t mtime_cache = sb->st_mtime;
sqlstr = "INSERT INTO metadb.file_cache VALUES (:device, :inode,"
- " :mtime, :file)";
+ " :mtime, :parent, :file)";
rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL);
if (rc != SQLITE_OK) {
warnx("%s", sqlite3_errmsg(db));
@@ -527,6 +531,14 @@
return;
}
+ idx = sqlite3_bind_parameter_index(stmt, ":parent");
+ rc = sqlite3_bind_text(stmt, idx, parent, -1, NULL);
+ if (rc != SQLITE_OK) {
+ warnx("%s", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return;
+ }
+
idx = sqlite3_bind_parameter_index(stmt, ":file");
rc = sqlite3_bind_text(stmt, idx, file, -1, NULL);
if (rc != SQLITE_OK) {
@@ -659,6 +671,7 @@
const char *sqlstr;
sqlite3_stmt *stmt = NULL;
const char *file;
+ const char *parent;
char *errmsg = NULL;
char *md5sum;
void *buf;
@@ -670,8 +683,11 @@
int md5_status;
int rc;
- sqlstr = "SELECT device, inode, mtime, file FROM metadb.file_cache"
- " EXCEPT SELECT device, inode, mtime, file from mandb_meta";
+ sqlstr = "SELECT device, inode, mtime, parent, file"
+ " FROM metadb.file_cache fc"
+ " WHERE NOT EXISTS(SELECT 1 FROM mandb_meta WHERE"
+ " device = fc.device AND inode = fc.inode AND "
+ " mtime = fc.mtime AND file = fc.file)";
rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL);
if (rc != SQLITE_OK) {
@@ -687,7 +703,8 @@
rec->device = sqlite3_column_int64(stmt, 0);
rec->inode = sqlite3_column_int64(stmt, 1);
rec->mtime = sqlite3_column_int64(stmt, 2);
- file = (const char *) sqlite3_column_text(stmt, 3);
+ parent = (const char *) sqlite3_column_text(stmt, 3);
+ file = (const char *) sqlite3_column_text(stmt, 4);
if (read_and_decompress(file, &buf, &buflen)) {
err_count++;
buf = NULL;
@@ -731,6 +748,7 @@
rec->md5_hash = md5sum;
rec->file_path = estrdup(file);
// file_path is freed by insert_into_db itself.
+ chdir(parent);
begin_parse(file, mp, rec, buf, buflen);
if (insert_into_db(db, rec) < 0) {
warnx("Error in indexing %s", file);
Home |
Main Index |
Thread Index |
Old Index