Skip to content

Commit

Permalink
Merge pull request #1653 from jeffali/fix/lmdb_recreate_test
Browse files Browse the repository at this point in the history
Make lmdb recreate a file if it has an invalid format
  • Loading branch information
kacf committed Apr 23, 2014
2 parents 7bb5fb4 + 5a752e9 commit 6558a51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions libpromises/dbm_lmdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ DBPriv *DBPrivOpenDB(const char *dbpath, dbid id)
mdb_env_close(db->env);
}
free(db);
if (rc == MDB_INVALID)
{
return DB_PRIV_DATABASE_BROKEN;
}
return NULL;
}

Expand Down
8 changes: 7 additions & 1 deletion tests/unit/db_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void test_iter_delete_entry(void)
CloseDB(db);
}

#if defined(HAVE_LIBTOKYOCABINET) || defined(HAVE_LIBQDBM)
#if defined(HAVE_LIBTOKYOCABINET) || defined(HAVE_LIBQDBM) || defined(HAVE_LIBLMDB)
static void CreateGarbage(const char *filename)
{
FILE *fh = fopen(filename, "w");
Expand All @@ -106,6 +106,12 @@ void test_recreate(void)
snprintf(qdbm_db, CF_BUFSIZE, "%s/cf_classes.qdbm", CFWORKDIR);
CreateGarbage(qdbm_db);
#endif
#ifdef HAVE_LIBLMDB
char lmdb_db[CF_BUFSIZE];
snprintf(lmdb_db, CF_BUFSIZE, "%s/cf_classes.lmdb", CFWORKDIR);
CreateGarbage(lmdb_db);
#endif

CF_DB *db;
assert_int_equal(OpenDB(&db, dbid_classes), true);
CloseDB(db);
Expand Down

0 comments on commit 6558a51

Please sign in to comment.