NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/46419: Inconsistent information in man.db for man page aliases after updation

>Number:         46419
>Category:       bin
>Synopsis:       Inconsistent information in man.db for man page aliases after 
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun May 06 19:00:00 +0000 2012
>Originator:     Abhinav Upadhyay
>Release:        NetBSD 6.0_BETA
NetBSD  6.0_BETA NetBSD 6.0_BETA (GENERIC) i386
makemandb(8) maintains an index of all the different aliases of the man pages. 
This information is maintained in the mandb_links table in the database. But 
there is a small bug in there. When old man pages are removed, the 
corresponding entry for the aliases of those man pages are not removed from the 
mandb_links table. 

Similarly, in case a man page is updated to add new aliases or if one or more 
of its aliases are removed, the mandb_links table won't get updated to reflect 
this change properly, leading to inconsistent information. 

Note that, the mandb_links table is not being used right now for any purpose 
but it might be of use in future. Attached patch should fix this problem.

Edit a man page, for example /usr/share/man/man1/ls.1 to add a new alias:

.Nm ls, ls2

Run makemandb to update the index

Run: sqlite3 /var/db/man.db "SELECT * FROM mandb_links WHERE target='ls';"

See the entry for the new alias in the output.

Now, edit again the man page and remove that alias.
Re-run makemandb to update index.
Re-run the SQL query and see the alias entry still present.

RCS file: /cvsroot/src/usr.sbin/makemandb/DBSCHEMA,v
retrieving revision 1.1
diff -u -p -r1.1 DBSCHEMA
--- DBSCHEMA    7 Feb 2012 19:13:32 -0000       1.1
+++ DBSCHEMA    6 May 2012 18:13:10 -0000
@@ -50,3 +50,4 @@ There are three tables in the database a
   3. section        The section number  
   4. machine        The machine architecture (if any) for which 
                     the page is relevant
+  5. md5_hash       MD5 Hash of the target man page.
Index: apropos-utils.c
RCS file: /cvsroot/src/usr.sbin/makemandb/apropos-utils.c,v
retrieving revision 1.4
diff -u -p -r1.4 apropos-utils.c
--- apropos-utils.c     15 Apr 2012 15:56:52 -0000      1.4
+++ apropos-utils.c     6 May 2012 18:13:10 -0000
@@ -172,7 +172,7 @@ create_db(sqlite3 *db)
                            "file UNIQUE, md5_hash UNIQUE, id  INTEGER PRIMARY 
KEY); "
                        "CREATE TABLE IF NOT EXISTS mandb_links(link, target, 
section, "
-                           "machine); ";       //mandb_links
+                           "machine, md5_hash); ";     //mandb_links
        sqlite3_exec(db, sqlstr, NULL, NULL, &errmsg);
        if (errmsg != NULL)
@@ -181,7 +181,9 @@ create_db(sqlite3 *db)
        sqlstr = "CREATE INDEX IF NOT EXISTS index_mandb_links ON mandb_links "
                        "(link); "
                        "CREATE INDEX IF NOT EXISTS index_mandb_meta_dev ON 
mandb_meta "
-                       "(device, inode)";
+                       "(device, inode); "
+                       "CREATE INDEX IF NOT EXISTS index_mandb_links_md5 ON 
mandb_links "
+                       "(md5_hash);";
        sqlite3_exec(db, sqlstr, NULL, NULL, &errmsg);
        if (errmsg != NULL)
                goto out;
Index: makemandb.c
RCS file: /cvsroot/src/usr.sbin/makemandb/makemandb.c,v
retrieving revision 1.8
diff -u -p -r1.8 makemandb.c
--- makemandb.c 4 May 2012 23:50:26 -0000       1.8
+++ makemandb.c 6 May 2012 18:13:11 -0000
@@ -780,6 +780,8 @@ update_db(sqlite3 *db, struct mparse *mp
        sqlstr = "DELETE FROM mandb_meta WHERE file NOT IN"
                 " (SELECT file FROM metadb.file_cache);"
+                "DELETE FROM mandb_links WHERE md5_hash NOT IN"
+                " (SELECT md5_hash from mandb_meta);"
                 "DROP TABLE metadb.file_cache;"
                 "DELETE FROM mandb WHERE rowid NOT IN"
                 " (SELECT id FROM mandb_meta);";
@@ -1726,9 +1728,9 @@ insert_into_db(sqlite3 *db, mandb_rec *r
                                ln[strlen(ln) - 1] = 0;
                        str = sqlite3_mprintf("INSERT INTO mandb_links"
-                                             " VALUES (%Q, %Q, %Q, %Q)",
+                                             " VALUES (%Q, %Q, %Q, %Q, %Q)",
                                              ln, rec->name, rec->section,
-                                             rec->machine);
+                                             rec->machine, rec->md5_hash);
                        sqlite3_exec(db, str, NULL, NULL, &errmsg);
                        if (errmsg != NULL) {

Home | Main Index | Thread Index | Old Index