diff options
author | Colin Watson <cjwatson@debian.org> | 2009-08-22 15:36:11 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2009-08-22 15:36:11 +0100 |
commit | dec775fc93131970035d5c2ecfe86bea4974032f (patch) | |
tree | b047c17db2d38a4c73ae58fd492f53c1a982f5ab /src/check_mandirs.c | |
parent | be4324693660b678af2979d9503474fa09caf366 (diff) |
Cope with some more cases of database corruption (Debian bug
#187750).
* libdb/db_store.c (dbstore): Always replace existing keys once
we've decided we ought to. If the key already exists in the
database, then that probably indicates some kind of database
corruption, but our new key is almost certainly better.
* src/check_mandirs.c (sanity_check_db): New function, checking
dbver_rd and ensuring that all keys have non-NULL content.
(update_db): Use sanity_check_db to decide whether an existing
database is OK.
* src/accessdb.c (main): If we encounter a key with no content,
print a debugging message and continue as far as we can before
exiting non-zero, rather than just silently exiting non-zero
immediately.
Diffstat (limited to 'src/check_mandirs.c')
-rw-r--r-- | src/check_mandirs.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/check_mandirs.c b/src/check_mandirs.c index fd13e938..c21c744c 100644 --- a/src/check_mandirs.c +++ b/src/check_mandirs.c @@ -511,12 +511,40 @@ int create_db (const char *manpath, const char *catpath) return amount; } +/* Make sure an existing database is essentially sane. */ +int sanity_check_db (void) +{ + datum key; + + if (dbver_rd (dbf)) + return 0; + + key = MYDBM_FIRSTKEY (dbf); + while (MYDBM_DPTR (key) != NULL) { + datum content, nextkey; + + content = MYDBM_FETCH (dbf, key); + if (!MYDBM_DPTR (content)) { + debug ("warning: %s has a key with no content (%s); " + "rebuilding\n", database, MYDBM_DPTR (key)); + MYDBM_FREE (MYDBM_DPTR (key)); + return 0; + } + MYDBM_FREE (MYDBM_DPTR (content)); + nextkey = MYDBM_NEXTKEY (dbf, key); + MYDBM_FREE (MYDBM_DPTR (key)); + key = nextkey; + } + + return 1; +} + /* routine to update the db, ensure that it is consistent with the filesystem */ int update_db (const char *manpath, const char *catpath) { dbf = MYDBM_RDOPEN (database); - if (dbf && dbver_rd (dbf)) { + if (dbf && !sanity_check_db ()) { MYDBM_CLOSE (dbf); dbf = NULL; } |