Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/makemandb Add -Q flag:
details: https://anonhg.NetBSD.org/src/rev/b436a05b40c1
branches: trunk
changeset: 781264:b436a05b40c1
user: wiz <wiz%NetBSD.org@localhost>
date: Wed Aug 29 20:33:01 2012 +0000
description:
Add -Q flag:
Print only fatal error messages (i.e., when the database is left in
an inconsistent state and needs manual intervention).
>From Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>.
diffstat:
usr.sbin/makemandb/makemandb.8 | 14 +++--
usr.sbin/makemandb/makemandb.c | 96 ++++++++++++++++++++++++++++--------------
2 files changed, 73 insertions(+), 37 deletions(-)
diffs (truncated from 374 to 300 lines):
diff -r 9efcc29d4f0d -r b436a05b40c1 usr.sbin/makemandb/makemandb.8
--- a/usr.sbin/makemandb/makemandb.8 Wed Aug 29 19:10:15 2012 +0000
+++ b/usr.sbin/makemandb/makemandb.8 Wed Aug 29 20:33:01 2012 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: makemandb.8,v 1.4 2012/08/25 12:37:00 wiz Exp $
+.\" $NetBSD: makemandb.8,v 1.5 2012/08/29 20:33:01 wiz Exp $
.\"
.\" Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
.\" All rights reserved.
@@ -29,7 +29,7 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 21, 2012
+.Dd August 29, 2012
.Dt MAKEMANDB 8
.Os
.Sh NAME
@@ -37,7 +37,7 @@
.Nd parse the manual pages and build a search index over them
.Sh SYNOPSIS
.Nm
-.Op Fl floqv
+.Op Fl floQqv
.Op Fl C Ar path
.Sh DESCRIPTION
The
@@ -71,11 +71,15 @@
Use this option to optimize the index for speed and also
to significantly reduce disk space usage.
This is a somewhat expensive operation.
+.It Fl Q
+Print only fatal error messages (i.e., when the database is left in
+an inconsistent state and needs manual intervention).
.It Fl q
-Print only error messages and no status updates.
+Print only warnings and error messages but no status updates.
.It Fl v
Enable verbose output.
-This prints the name of every file being parsed.
+This prints the name of every file being parsed
+and a summary at the end of the index update.
.El
.Pp
As the database file is stored under
diff -r 9efcc29d4f0d -r b436a05b40c1 usr.sbin/makemandb/makemandb.c
--- a/usr.sbin/makemandb/makemandb.c Wed Aug 29 19:10:15 2012 +0000
+++ b/usr.sbin/makemandb/makemandb.c Wed Aug 29 20:33:01 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: makemandb.c,v 1.12 2012/08/25 12:37:12 wiz Exp $ */
+/* $NetBSD: makemandb.c,v 1.13 2012/08/29 20:33:01 wiz 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.12 2012/08/25 12:37:12 wiz Exp $");
+__RCSID("$NetBSD: makemandb.c,v 1.13 2012/08/29 20:33:01 wiz Exp $");
#include <sys/stat.h>
#include <sys/types.h>
@@ -304,7 +304,7 @@
size_t linesize;
struct mandb_rec rec;
- while ((ch = getopt(argc, argv, "C:floqv")) != -1) {
+ while ((ch = getopt(argc, argv, "C:floQqv")) != -1) {
switch (ch) {
case 'C':
manconf = optarg;
@@ -319,8 +319,11 @@
case 'o':
mflags.optimize = 1;
break;
+ case 'Q':
+ mflags.verbosity = 0;
+ break;
case 'q':
- mflags.verbosity = 0;
+ mflags.verbosity = 1;
break;
case 'v':
mflags.verbosity = 2;
@@ -417,6 +420,8 @@
err(EXIT_FAILURE, "pclose error");
}
+ if (mflags.verbosity)
+ printf("Performing index update\n");
update_db(db, mp, &rec);
mparse_free(mp);
free_secbuffs(&rec);
@@ -451,7 +456,8 @@
char *buf;
if (stat(file, &sb) < 0) {
- warn("stat failed: %s", file);
+ if (mflags.verbosity)
+ warn("stat failed: %s", file);
return;
}
@@ -464,7 +470,8 @@
/* If it is a directory, traverse it recursively */
if (S_ISDIR(sb.st_mode)) {
if ((dp = opendir(file)) == NULL) {
- warn("opendir error: %s", file);
+ if (mflags.verbosity)
+ warn("opendir error: %s", file);
return;
}
@@ -503,14 +510,16 @@
" :mtime, :parent, :file)";
rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL);
if (rc != SQLITE_OK) {
- warnx("%s", sqlite3_errmsg(db));
+ if (mflags.verbosity)
+ warnx("%s", sqlite3_errmsg(db));
return;
}
idx = sqlite3_bind_parameter_index(stmt, ":device");
rc = sqlite3_bind_int64(stmt, idx, device_cache);
if (rc != SQLITE_OK) {
- warnx("%s", sqlite3_errmsg(db));
+ if (mflags.verbosity)
+ warnx("%s", sqlite3_errmsg(db));
sqlite3_finalize(stmt);
return;
}
@@ -518,7 +527,8 @@
idx = sqlite3_bind_parameter_index(stmt, ":inode");
rc = sqlite3_bind_int64(stmt, idx, inode_cache);
if (rc != SQLITE_OK) {
- warnx("%s", sqlite3_errmsg(db));
+ if (mflags.verbosity)
+ warnx("%s", sqlite3_errmsg(db));
sqlite3_finalize(stmt);
return;
}
@@ -526,7 +536,8 @@
idx = sqlite3_bind_parameter_index(stmt, ":mtime");
rc = sqlite3_bind_int64(stmt, idx, mtime_cache);
if (rc != SQLITE_OK) {
- warnx("%s", sqlite3_errmsg(db));
+ if (mflags.verbosity)
+ warnx("%s", sqlite3_errmsg(db));
sqlite3_finalize(stmt);
return;
}
@@ -534,7 +545,8 @@
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));
+ if (mflags.verbosity)
+ warnx("%s", sqlite3_errmsg(db));
sqlite3_finalize(stmt);
return;
}
@@ -542,7 +554,8 @@
idx = sqlite3_bind_parameter_index(stmt, ":file");
rc = sqlite3_bind_text(stmt, idx, file, -1, NULL);
if (rc != SQLITE_OK) {
- warnx("%s", sqlite3_errmsg(db));
+ if (mflags.verbosity)
+ warnx("%s", sqlite3_errmsg(db));
sqlite3_finalize(stmt);
return;
}
@@ -567,7 +580,8 @@
" :inode2 OR mtime <> :mtime2)";
rc = sqlite3_prepare_v2(db, inner_sqlstr, -1, &inner_stmt, NULL);
if (rc != SQLITE_OK) {
- warnx("%s", sqlite3_errmsg(db));
+ if (mflags.verbosity)
+ warnx("%s", sqlite3_errmsg(db));
return;
}
idx = sqlite3_bind_parameter_index(inner_stmt, ":device");
@@ -591,7 +605,7 @@
if (rc == SQLITE_DONE) {
/* Check if an update has been performed. */
if (update_count != sqlite3_total_changes(db)) {
- if (mflags.verbosity)
+ if (mflags.verbosity == 2)
printf("Updated %s\n", file);
(*new_count)++;
} else {
@@ -599,7 +613,8 @@
(*link_count)++;
}
} else {
- warnx("Could not update the meta data for %s", file);
+ if (mflags.verbosity == 2)
+ warnx("Could not update the meta data for %s", file);
(*err_count)++;
}
sqlite3_finalize(inner_stmt);
@@ -643,7 +658,8 @@
if (off == *len) {
*len *= 2;
if (*len < off) {
- warnx("File too large: %s", file);
+ if (mflags.verbosity)
+ warnx("File too large: %s", file);
free(*buf);
archive_read_close(a);
return -1;
@@ -691,6 +707,7 @@
rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL);
if (rc != SQLITE_OK) {
+ if (mflags.verbosity)
warnx("%s", sqlite3_errmsg(db));
close_db(db);
errx(EXIT_FAILURE, "Could not query file cache");
@@ -713,7 +730,8 @@
md5_status = check_md5(file, db, "mandb_meta", &md5sum, buf, buflen);
assert(md5sum != NULL);
if (md5_status == -1) {
- warnx("An error occurred in checking md5 value"
+ if (mflags.verbosity)
+ warnx("An error occurred in checking md5 value"
" for file %s", file);
err_count++;
continue;
@@ -743,7 +761,7 @@
* This means is either a new file or an updated file.
* We should go ahead with parsing.
*/
- if (mflags.verbosity > 1)
+ if (mflags.verbosity == 2)
printf("Parsing: %s\n", file);
rec->md5_hash = md5sum;
rec->file_path = estrdup(file);
@@ -751,7 +769,8 @@
chdir(parent);
begin_parse(file, mp, rec, buf, buflen);
if (insert_into_db(db, rec) < 0) {
- warnx("Error in indexing %s", file);
+ if (mflags.verbosity)
+ warnx("Error in indexing %s", file);
err_count++;
} else {
new_count++;
@@ -762,7 +781,7 @@
sqlite3_finalize(stmt);
- if (mflags.verbosity) {
+ if (mflags.verbosity == 2) {
printf("Total Number of new or updated pages encountered = %d\n"
"Total number of (hard or symbolic) links found = %d\n"
"Total number of pages that were successfully"
@@ -775,7 +794,7 @@
if (mflags.recreate)
return;
- if (mflags.verbosity)
+ if (mflags.verbosity == 2)
printf("Deleting stale index entries\n");
sqlstr = "DELETE FROM mandb_meta WHERE file NOT IN"
@@ -810,13 +829,19 @@
rec->xr_found = 0;
if (mparse_readmem(mp, buf, len, file) >= MANDOCLEVEL_FATAL) {
- warnx("%s: Parse failure", file);
+ /* Printing this warning at verbosity level 2
+ * because some packages from pkgsrc might trigger several
+ * of such warnings.
+ */
+ if (mflags.verbosity == 2)
+ warnx("%s: Parse failure", file);
return;
}
mparse_result(mp, &mdoc, &man);
if (mdoc == NULL && man == NULL) {
- warnx("Not a man(7) or mdoc(7) page");
+ if (mflags.verbosity == 2)
+ warnx("Not a man(7) or mdoc(7) page");
return;
}
@@ -1670,7 +1695,8 @@
sqlite3_exec(db, sql, NULL, NULL, &errmsg);
sqlite3_free(sql);
if (errmsg != NULL) {
- warnx("%s", errmsg);
+ if (mflags.verbosity)
+ warnx("%s", errmsg);
free(errmsg);
}
sqlstr = "UPDATE mandb_meta SET device = :device,"
@@ -1678,7 +1704,8 @@
Home |
Main Index |
Thread Index |
Old Index