From 262e2af383382c02b8a3dda72168f6505ddae15f Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 12 May 2007 20:24:39 +0200 Subject: [PATCH] BDB suck hard. in a GNU env, we will at least have gdbm. Signed-off-by: Pierre Habouzit --- configure.ac | 54 -------------- globals.h | 4 +- init.h | 4 +- lib-mx/hcache.c | 184 ------------------------------------------------ main.c | 5 -- 5 files changed, 4 insertions(+), 247 deletions(-) diff --git a/configure.ac b/configure.ac index 4ffd08d..f050da7 100644 --- a/configure.ac +++ b/configure.ac @@ -379,7 +379,6 @@ AC_ARG_ENABLE(hcache, AC_HELP_STRING([--enable-hcache], [Enable header caching]) [if test x$enableval = xyes; then AC_DEFINE(USE_HCACHE, 1, [Enable header caching]) OLDCPPFLAGS="$CPPFLAGS" - need_md5="yes" ac_prefer_qdbm=yes AC_ARG_WITH(qdbm, AC_HELP_STRING([--without-qdbm], [Don't use qdbm even if it is available]), @@ -411,55 +410,6 @@ AC_ARG_ENABLE(hcache, AC_HELP_STRING([--enable-hcache], [Enable header caching]) fi fi - ac_bdb_prefix=yes - AC_ARG_WITH(bdb, AC_HELP_STRING([--with-bdb[=DIR]], [Use BerkeleyDB4 if gdbm is not available ]), - ac_bdb_prefix=$withval) - if test x$ac_bdb_prefix != xno -a x$ac_cv_gdbmopen != xyes -a x$ac_qdbm_here != xyes; then - test x$ac_bdb_prefix = xyes && ac_bdb_prefix="${prefix} /opt/csw/bdb4 /opt /usr/local /usr" - for d in $ac_bdb_prefix; do - bdbpfx="$bdbpfx $d" - for v in BerkeleyDB.4.3 BerkeleyDB.4.2 BerkeleyDB.4.1; do - bdbpfx="$bdbpfx $d/$v" - done - done - BDB_VERSIONS="db-4 db4 db-4.3 db4.3 db43 db-4.2 db4.2 db42 db-4.1 db4.1 db41 db ''" - AC_MSG_CHECKING([for BerkeleyDB > 4.0]) - for d in $bdbpfx; do - BDB_INCLUDE_DIR="" - BDB_LIB_DIR="" - for v in / $BDB_VERSIONS; do - if test -r "$d/include/$v/db.h"; then - BDB_INCLUDE_DIR="$d/include/$v" - if test -d "$d/lib/$v"; then - BDB_LIB_DIR="$d/lib/$v" - for l in `echo $BDB_VERSIONS`; do - CPPFLAGS="-I$BDB_INCLUDE_DIR $OLDCPPFLAGS" - LIBS="$MUTTLIBS -L$BDB_LIB_DIR -l$l" - AC_TRY_LINK([ - #include - #include - ],[ - DB *db = NULL; - db->open(db,NULL,NULL,NULL,0,0,0); - ],[ - ac_cv_dbcreate=yes - BDB_LIB="$l" - break - ]) - done - test x$ac_cv_dbcreate = xyes && break - fi - fi - done - test x$BDB_LIB != x && break - done - if test x$ac_cv_dbcreate = xyes; then - AC_MSG_RESULT(yes) - else - AC_MSG_RESULT(no) - fi - fi - if test x$ac_qdbm_here = xyes; then CPPFLAGS="$OLDCPPFLAGS $QDBM_CFLAGS" MUTTLIBS="$MUTTLIBS -lqdbm" @@ -468,10 +418,6 @@ AC_ARG_ENABLE(hcache, AC_HELP_STRING([--enable-hcache], [Enable header caching]) CPPFLAGS="$OLDCPPFLAGS $GDBM_INC" MUTTLIBS="$MUTTLIBS $GDBM_LIB -lgdbm"; AC_DEFINE(HAVE_GDBM, 1, [GDBM Support]) - elif test x$ac_cv_dbcreate = xyes; then - CPPFLAGS="-I$BDB_INCLUDE_DIR $OLDCPPFLAGS" - MUTTLIBS="$MUTTLIBS -L$BDB_LIB_DIR -l$BDB_LIB" - AC_DEFINE(HAVE_DB4, 1, [Sleepycat DB4 Support]) else AC_MSG_ERROR([You need one of: QDBM, GDBM or Sleepycat DB4 for --enable-hcache]) fi diff --git a/globals.h b/globals.h index 97f792c..c70cb29 100644 --- a/globals.h +++ b/globals.h @@ -49,9 +49,9 @@ WHERE char *Maildir; #ifdef USE_HCACHE WHERE char *HeaderCache; -#if defined(HAVE_GDBM) || defined(HAVE_DB4) +#if defined(HAVE_GDBM) WHERE char *HeaderCachePageSize; -#endif /* HAVE_GDBM || HAVE_DB4 */ +#endif /* HAVE_GDBM */ #endif /* USE_HCACHE */ WHERE char *MhFlagged; WHERE char *MhReplied; diff --git a/init.h b/init.h index db43a4d..37a0b0e 100644 --- a/init.h +++ b/init.h @@ -1076,7 +1076,7 @@ struct option_t MuttVars[] = { ** files when the header cache is in use. This incurs one \fTstat(2)\fP per ** message every time the folder is opened. */ -#if defined(HAVE_GDBM) || defined(HAVE_DB4) +#if defined(HAVE_GDBM) {"header_cache_pagesize", DT_STR, R_NONE, UL &HeaderCachePageSize, "16384"}, /* ** .pp @@ -1091,7 +1091,7 @@ struct option_t MuttVars[] = { ** less the best you can get. For details google for mutt header ** cache (first hit). */ -#endif /* HAVE_GDBM || HAVE_DB 4 */ +#endif /* HAVE_GDBM */ #ifdef HAVE_QDBM { "header_cache_compress", DT_BOOL, R_NONE, OPTHCACHECOMPRESS, "no" }, /* diff --git a/lib-mx/hcache.c b/lib-mx/hcache.c index 4f4504c..846a6cf 100644 --- a/lib-mx/hcache.c +++ b/lib-mx/hcache.c @@ -21,8 +21,6 @@ #include #elif defined(HAVE_GDBM) #include -#elif defined(HAVE_DB4) -#include #endif #include @@ -41,12 +39,6 @@ struct header_cache { GDBM_FILE db; char *folder; unsigned int crc; -#elif defined(HAVE_DB4) - DB_ENV *env; - DB *db; - unsigned int crc; - int fd; - char lockfile[_POSIX_PATH_MAX]; #endif }; @@ -746,182 +738,6 @@ mutt_hcache_delete (void *db, const char *filename, return gdbm_delete (h->db, key); } -#elif defined(HAVE_DB4) - -static void mutt_hcache_dbt_init (DBT * dbt, void *data, ssize_t len) -{ - dbt->data = data; - dbt->size = dbt->ulen = len; - dbt->dlen = dbt->doff = 0; - dbt->flags = DB_DBT_USERMEM; -} - -static void mutt_hcache_dbt_empty_init (DBT * dbt) -{ - dbt->data = NULL; - dbt->size = dbt->ulen = dbt->dlen = dbt->doff = 0; - dbt->flags = 0; -} - -void *mutt_hcache_open (const char *path, const char *folder) -{ - struct stat sb; - u_int32_t createflags = DB_CREATE; - int ret; - struct header_cache *h = p_new(struct header_cache, 1); - int pagesize = atoi (HeaderCachePageSize); - - - h->crc = generate_crc32 (); - - if (!path || path[0] == '\0') { - p_delete(&h); - return NULL; - } - - path = mutt_hcache_per_folder (path, folder); - - snprintf (h->lockfile, _POSIX_PATH_MAX, "%s-lock-hack", path); - - h->fd = open (h->lockfile, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); - if (h->fd < 0) { - p_delete(&h); - return NULL; - } - - if (mx_lock_file (h->lockfile, h->fd, 1, 0, 5)) { - close (h->fd); - p_delete(&h); - return NULL; - } - - ret = db_env_create (&h->env, 0); - if (ret) { - mx_unlock_file (h->lockfile, h->fd, 0); - close (h->fd); - p_delete(&h); - return NULL; - } - - ret = - (h->env->open)(h->env, NULL, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0600); - if (!ret) { - ret = db_create (&h->db, h->env, 0); - if (ret) { - h->env->close (h->env, 0); - mx_unlock_file (h->lockfile, h->fd, 0); - close (h->fd); - p_delete(&h); - return NULL; - } - } - - if (stat (path, &sb) != 0 && errno == ENOENT) { - createflags |= DB_EXCL; - h->db->set_pagesize (h->db, pagesize); - } - - ret = (h->db->open)(h->db, NULL, path, folder, DB_BTREE, createflags, 0600); - if (ret) { - h->db->close (h->db, 0); - h->env->close (h->env, 0); - mx_unlock_file (h->lockfile, h->fd, 0); - close (h->fd); - p_delete(&h); - return NULL; - } - - return h; -} - -void mutt_hcache_close (void *db) -{ - struct header_cache *h = db; - - if (!h) { - return; - } - - h->db->close (h->db, 0); - h->env->close (h->env, 0); - mx_unlock_file (h->lockfile, h->fd, 0); - close (h->fd); - p_delete(&h); -} - -void *mutt_hcache_fetch (void *db, const char *filename, - ssize_t (*keylen) (const char *fn)) -{ - DBT key; - DBT data; - struct header_cache *h = db; - - if (!h) { - return NULL; - } - - filename++; /* skip '/' */ - - mutt_hcache_dbt_init (&key, (void *) filename, keylen (filename)); - mutt_hcache_dbt_empty_init (&data); - data.flags = DB_DBT_MALLOC; - - h->db->get (h->db, NULL, &key, &data, 0); - - if (!crc32_matches (data.data, h->crc)) { - p_delete(&data.data); - return NULL; - } - - return data.data; -} - -int -mutt_hcache_store (void *db, const char *filename, HEADER * header, - unsigned long uid_validity, ssize_t (*keylen) (const char *fn)) -{ - DBT key; - DBT data; - int ret; - struct header_cache *h = db; - - if (!h) { - return -1; - } - - filename++; /* skip '/' */ - - mutt_hcache_dbt_init (&key, (void *) filename, keylen (filename)); - - mutt_hcache_dbt_empty_init (&data); - data.flags = DB_DBT_USERMEM; - data.data = - mutt_hcache_dump (db, header, (signed int *) &data.size, uid_validity); - data.ulen = data.size; - - ret = h->db->put (h->db, NULL, &key, &data, 0); - - p_delete(&data.data); - - return ret; -} - -int -mutt_hcache_delete (void *db, const char *filename, - ssize_t (*keylen) (const char *fn)) -{ - DBT key; - struct header_cache *h = db; - - if (!h) { - return -1; - } - - filename++; /* skip '/' */ - - mutt_hcache_dbt_init (&key, (void *) filename, keylen (filename)); - return h->db->del (h->db, NULL, &key, 0); -} #endif #endif /* USE_HCACHE */ diff --git a/main.c b/main.c index f953750..3002fb7 100644 --- a/main.c +++ b/main.c @@ -57,8 +57,6 @@ extern int optind; #include #elif defined(HAVE_GDBM) #include -#elif defined(HAVE_DB4) -#include #endif #endif @@ -176,9 +174,6 @@ static void show_version (void) printf (" qdbm %s\n", dpversion); #elif defined(HAVE_GDBM) printf (" gdbm %s\n", gdbm_version); -#elif defined(HAVE_DB4) - printf (" DB4 %d.%d.%d\n", DB_VERSION_MAJOR, DB_VERSION_MINOR, - DB_VERSION_PATCH); #endif #endif -- 2.20.1