Ver Fonte

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).
Oswald Buddenhagen há 14 anos atrás
pai
commit
40f2812a41
2 ficheiros alterados com 11 adições e 2 exclusões
  1. 10 1
      src/drv_maildir.c
  2. 1 1
      src/mdconvert.c

+ 10 - 1
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;

+ 1 - 1
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 );