From 40f2812a41cb40edff76a497dda89e095f0792f5 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 25 Jul 2011 09:25:09 +0200 Subject: [PATCH] suppress bdb complaints about unknown file format pass DB_TRUNCATE when creating databases. otherwise bdb will complain about the empty file we pass it (we have to create it upfront to implement our locking). --- src/drv_maildir.c | 11 ++++++++++- src/mdconvert.c | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/drv_maildir.c b/src/drv_maildir.c index 24aae2d..6013846 100644 --- a/src/drv_maildir.c +++ b/src/drv_maildir.c @@ -803,6 +803,9 @@ maildir_select( store_t *gctx, int create, { maildir_store_t *ctx = (maildir_store_t *)gctx; int ret; +#ifdef USE_DB + struct stat st; +#endif /* USE_DB */ char uvpath[_POSIX_PATH_MAX]; maildir_cleanup( gctx ); @@ -855,12 +858,18 @@ maildir_select( store_t *gctx, int create, cb( DRV_BOX_BAD, aux ); return; } + if (fstat( ctx->uvfd, &st )) { + sys_error( "Maildir error: cannot stat %s", uvpath ); + cb( DRV_BOX_BAD, aux ); + return; + } if (db_create( &ctx->db, 0, 0 )) { fputs( "Maildir error: db_create() failed\n", stderr ); cb( DRV_BOX_BAD, aux ); return; } - if ((ret = (ctx->db->open)( ctx->db, 0, uvpath, 0, DB_HASH, DB_CREATE, 0 ))) { + if ((ret = (ctx->db->open)( ctx->db, 0, uvpath, 0, DB_HASH, + st.st_size ? 0 : DB_CREATE | DB_TRUNCATE, 0 ))) { ctx->db->err( ctx->db, ret, "Maildir error: db->open(%s)", uvpath ); cb( DRV_BOX_BAD, aux ); return; diff --git a/src/mdconvert.c b/src/mdconvert.c index 48bd759..7dbfb48 100644 --- a/src/mdconvert.c +++ b/src/mdconvert.c @@ -122,7 +122,7 @@ convert( const char *box, int altmap ) fputs( "Error: db_create() failed\n", stderr ); goto tbork; } - if ((ret = (db->open)( db, 0, dbpath, 0, DB_HASH, DB_CREATE, 0 ))) { + if ((ret = (db->open)( db, 0, dbpath, 0, DB_HASH, altmap ? DB_CREATE|DB_TRUNCATE : 0, 0 ))) { db->err( db, ret, "Error: db->open(%s)", dbpath ); dbork: db->close( db, 0 );