[dovecot-cvs] dovecot/src/lib-index mail-cache.c, 1.26, 1.27 mail-cache.h, 1.7, 1.8 mail-index-sync-private.h, 1.2, 1.3 mail-index-sync-update.c, 1.9, 1.10 mail-index-sync.c, 1.7, 1.8 mail-index.h, 1.103, 1.104

cras at procontrol.fi cras at procontrol.fi
Sun May 2 22:24:37 EEST 2004


Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv2744/lib-index

Modified Files:
	mail-cache.c mail-cache.h mail-index-sync-private.h 
	mail-index-sync-update.c mail-index-sync.c mail-index.h 
Log Message:
Added support for setting dirty flags for messages (TODO: undirty..)

s/mail_index_record_flag/mail_cache_record_flag/



Index: mail-cache.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- mail-cache.c	27 Apr 2004 20:25:53 -0000	1.26
+++ mail-cache.c	2 May 2004 19:24:35 -0000	1.27
@@ -13,7 +13,7 @@
 #include <sys/stat.h>
 
 unsigned int mail_cache_field_sizes[32] = {
-	sizeof(enum mail_index_record_flag),
+	sizeof(enum mail_cache_record_flag),
 	sizeof(uoff_t),
 	16,
 	sizeof(struct mail_sent_date),
@@ -640,14 +640,14 @@
 			     enum mail_cache_field fields) {}
 
 /* Return index flags. */
-enum mail_index_record_flag
-mail_cache_get_index_flags(struct mail_cache_view *view, uint32_t seq)
+enum mail_cache_record_flag
+mail_cache_get_record_flags(struct mail_cache_view *view, uint32_t seq)
 {return 0;}
 
 /* Update index flags. The cache file must be locked and the flags must be
    already inserted to the record. */
-int mail_cache_update_index_flags(struct mail_cache_view *view, uint32_t seq,
-				  enum mail_index_record_flag flags)
+int mail_cache_update_record_flags(struct mail_cache_view *view, uint32_t seq,
+				   enum mail_cache_record_flag flags)
 {return 0;}
 
 /* Update location offset. External locking is assumed to take care of locking

Index: mail-cache.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mail-cache.h	27 Apr 2004 20:25:53 -0000	1.7
+++ mail-cache.h	2 May 2004 19:24:35 -0000	1.8
@@ -11,6 +11,20 @@
 struct mail_cache_view;
 struct mail_cache_transaction_ctx;
 
+enum mail_cache_record_flag {
+	/* If binary flags are set, it's not checked whether mail is
+	   missing CRs. So this flag may be set as an optimization for
+	   regular non-binary mails as well if it's known that it contains
+	   valid CR+LF line breaks. */
+	MAIL_INDEX_FLAG_BINARY_HEADER		= 0x0001,
+	MAIL_INDEX_FLAG_BINARY_BODY		= 0x0002,
+
+	/* Mail header or body is known to contain NUL characters. */
+	MAIL_INDEX_FLAG_HAS_NULS		= 0x0004,
+	/* Mail header or body is known to not contain NUL characters. */
+	MAIL_INDEX_FLAG_HAS_NO_NULS		= 0x0008
+};
+
 enum mail_cache_field {
 	/* fixed size fields */
 	MAIL_CACHE_INDEX_FLAGS		= 0x00000001,
@@ -144,14 +158,14 @@
 void mail_cache_mark_missing(struct mail_cache_view *view,
 			     enum mail_cache_field fields);
 
-/* Return index flags. */
-enum mail_index_record_flag
-mail_cache_get_index_flags(struct mail_cache_view *view, uint32_t seq);
+/* Return record flags. */
+enum mail_cache_record_flag
+mail_cache_get_record_flags(struct mail_cache_view *view, uint32_t seq);
 
-/* Update index flags. The cache file must be locked and the flags must be
+/* Update record flags. The cache file must be locked and the flags must be
    already inserted to the record. */
-int mail_cache_update_index_flags(struct mail_cache_view *view, uint32_t seq,
-				  enum mail_index_record_flag flags);
+int mail_cache_update_record_flags(struct mail_cache_view *view, uint32_t seq,
+				   enum mail_cache_record_flag flags);
 
 /* Update location offset. External locking is assumed to take care of locking
    readers out to prevent race conditions. */

Index: mail-index-sync-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-sync-private.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mail-index-sync-private.h	2 May 2004 18:07:24 -0000	1.2
+++ mail-index-sync-private.h	2 May 2004 19:24:35 -0000	1.3
@@ -17,9 +17,10 @@
 	size_t expunge_idx, update_idx;
 	uint32_t next_seq;
 
-	unsigned int lock_id;
+	unsigned int lock_id, dirty_lock_id;
 
 	unsigned int sync_appends:1;
+	unsigned int have_dirty:1;
 };
 
 int mail_index_sync_update_index(struct mail_index_sync_ctx *sync_ctx,

Index: mail-index-sync-update.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mail-index-sync-update.c	2 May 2004 18:07:24 -0000	1.9
+++ mail-index-sync-update.c	2 May 2004 19:24:35 -0000	1.10
@@ -175,7 +175,7 @@
 	struct mail_index_sync_rec rec;
 	const struct mail_index_record *appends;
 	unsigned int append_count;
-	uint32_t count, file_seq, src_idx, dest_idx;
+	uint32_t count, file_seq, src_idx, dest_idx, dirty_flag;
 	uoff_t file_offset;
 	unsigned int lock_id;
 	int ret, changed;
@@ -192,6 +192,12 @@
 	ctx.hdr = *index->hdr;
 	ctx.log_view = sync_ctx->view->log_view;
 
+	dirty_flag = sync_ctx->have_dirty ? MAIL_INDEX_HDR_FLAG_HAVE_DIRTY : 0;
+	if ((ctx.hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != dirty_flag) {
+		ctx.hdr.flags ^= MAIL_INDEX_HDR_FLAG_HAVE_DIRTY;
+		changed = TRUE;
+	}
+
 	/* see if we need to update sync headers */
 	if (ctx.hdr.sync_stamp != sync_stamp && sync_stamp != 0) {
 		ctx.hdr.sync_stamp = sync_stamp;

Index: mail-index-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-sync.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mail-index-sync.c	2 May 2004 18:07:24 -0000	1.7
+++ mail-index-sync.c	2 May 2004 19:24:35 -0000	1.8
@@ -397,6 +397,20 @@
 		ctx->sync_appends;
 }
 
+int mail_index_sync_set_dirty(struct mail_index_sync_ctx *ctx, uint32_t seq)
+{
+	if (ctx->dirty_lock_id == 0) {
+		if (mail_index_lock_exclusive(ctx->index,
+					      &ctx->dirty_lock_id) < 0)
+			return -1;
+	}
+
+	i_assert(seq <= ctx->view->map->records_count);
+	ctx->view->map->records[seq-1].flags |= MAIL_INDEX_MAIL_FLAG_DIRTY;
+	ctx->have_dirty = TRUE;
+	return 0;
+}
+
 int mail_index_sync_end(struct mail_index_sync_ctx *ctx,
 			uint32_t sync_stamp, uint64_t sync_size)
 {
@@ -421,11 +435,15 @@
 
 	if (ret == 0) {
 		mail_index_sync_read_and_sort(ctx, TRUE);
+
 		if (mail_index_sync_update_index(ctx, sync_stamp,
 						 sync_size) < 0)
 			ret = -1;
 	}
 
+	if (ctx->dirty_lock_id == 0) 
+		mail_index_unlock(ctx->index, ctx->dirty_lock_id);
+
 	mail_index_unlock(ctx->index, ctx->lock_id);
 	mail_transaction_log_sync_unlock(ctx->index->log);
 	mail_index_view_close(ctx->view);

Index: mail-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- mail-index.h	2 May 2004 18:07:24 -0000	1.103
+++ mail-index.h	2 May 2004 19:24:35 -0000	1.104
@@ -34,21 +34,12 @@
 
 enum mail_index_header_flag {
 	/* Index file is corrupted, reopen or recreate it. */
-	MAIL_INDEX_HDR_FLAG_CORRUPTED		= 0x0001
+	MAIL_INDEX_HDR_FLAG_CORRUPTED		= 0x0001,
+	MAIL_INDEX_HDR_FLAG_HAVE_DIRTY		= 0x0002
 };
 
-enum mail_index_record_flag {
-	/* If binary flags are set, it's not checked whether mail is
-	   missing CRs. So this flag may be set as an optimization for
-	   regular non-binary mails as well if it's known that it contains
-	   valid CR+LF line breaks. */
-	MAIL_INDEX_FLAG_BINARY_HEADER		= 0x0001,
-	MAIL_INDEX_FLAG_BINARY_BODY		= 0x0002,
-
-	/* Mail header or body is known to contain NUL characters. */
-	MAIL_INDEX_FLAG_HAS_NULS		= 0x0004,
-	/* Mail header or body is known to not contain NUL characters. */
-	MAIL_INDEX_FLAG_HAS_NO_NULS		= 0x0008
+enum mail_index_mail_flags {
+	MAIL_INDEX_MAIL_FLAG_DIRTY = 0x80
 };
 
 enum mail_index_error {
@@ -204,6 +195,10 @@
 			 struct mail_index_sync_rec *sync_rec);
 /* Returns 1 if there's more to sync, 0 if not. */
 int mail_index_sync_have_more(struct mail_index_sync_ctx *ctx);
+/* Mark given message to be dirty, ie. we couldn't temporarily change the
+   message flags in storage. Dirty messages are tried to be synced again in
+   next sync. */
+int mail_index_sync_set_dirty(struct mail_index_sync_ctx *ctx, uint32_t seq);
 /* End synchronization by unlocking the index and closing the view.
    sync_stamp/sync_size in header is updated to given values. */
 int mail_index_sync_end(struct mail_index_sync_ctx *ctx,



More information about the dovecot-cvs mailing list