[dovecot-cvs] dovecot/src/lib-index
mail-index-transaction-private.h, 1.7,
1.8 mail-index-transaction-view.c, 1.2,
1.3 mail-index-transaction.c, 1.15, 1.16 mail-index.h, 1.121, 1.122
cras at procontrol.fi
cras at procontrol.fi
Sat Jul 3 13:57:55 EEST 2004
Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv20742/lib-index
Modified Files:
mail-index-transaction-private.h mail-index-transaction-view.c
mail-index-transaction.c mail-index.h
Log Message:
UIDs for appended messages can now be assigned all at once. Maildir now
updates indexes immediately while saving messages.
Index: mail-index-transaction-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-transaction-private.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mail-index-transaction-private.h 24 Jun 2004 11:10:41 -0000 1.7
+++ mail-index-transaction-private.h 3 Jul 2004 10:57:52 -0000 1.8
@@ -4,7 +4,8 @@
#include "mail-transaction-log.h"
struct mail_index_transaction {
- struct mail_index_view *view, *updated_view;
+ int refcount;
+ struct mail_index_view *view;
buffer_t *appends;
uint32_t first_new_seq, last_new_seq;
@@ -30,4 +31,7 @@
struct mail_index_record *
mail_index_transaction_lookup(struct mail_index_transaction *t, uint32_t seq);
+void mail_index_transaction_ref(struct mail_index_transaction *t);
+void mail_index_transaction_unref(struct mail_index_transaction *t);
+
#endif
Index: mail-index-transaction-view.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-transaction-view.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mail-index-transaction-view.c 24 Jun 2004 11:10:41 -0000 1.2
+++ mail-index-transaction-view.c 3 Jul 2004 10:57:52 -0000 1.3
@@ -17,8 +17,7 @@
struct mail_index_view_transaction *tview =
(struct mail_index_view_transaction *)view;
- tview->t->updated_view = NULL;
-
+ mail_index_transaction_unref(tview->t);
return tview->parent->close(view);
}
@@ -147,19 +146,16 @@
};
struct mail_index_view *
-mail_index_transaction_get_updated_view(struct mail_index_transaction *t)
+mail_index_transaction_open_updated_view(struct mail_index_transaction *t)
{
struct mail_index_view_transaction *tview;
- if (t->updated_view == NULL) {
- tview = i_new(struct mail_index_view_transaction, 1);
- mail_index_view_clone(&tview->view, t->view);
- tview->view.methods = view_methods;
- tview->parent = &t->view->methods;
- tview->t = t;
-
- t->updated_view = &tview->view;
- }
+ tview = i_new(struct mail_index_view_transaction, 1);
+ mail_index_view_clone(&tview->view, t->view);
+ tview->view.methods = view_methods;
+ tview->parent = &t->view->methods;
+ tview->t = t;
- return t->updated_view;
+ mail_index_transaction_ref(t);
+ return &tview->view;
}
Index: mail-index-transaction.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-transaction.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- mail-index-transaction.c 24 Jun 2004 11:10:41 -0000 1.15
+++ mail-index-transaction.c 3 Jul 2004 10:57:53 -0000 1.16
@@ -23,6 +23,7 @@
mail_index_view_transaction_ref(view);
t = i_new(struct mail_index_transaction, 1);
+ t->refcount = 1;
t->view = view;
t->hide_transaction = hide;
t->first_new_seq = mail_index_view_get_message_count(t->view)+1;
@@ -48,11 +49,20 @@
buffer_free(t->updates);
if (t->cache_updates != NULL)
buffer_free(t->cache_updates);
- if (t->updated_view != NULL)
- mail_index_view_close(t->updated_view);
i_free(t);
}
+void mail_index_transaction_ref(struct mail_index_transaction *t)
+{
+ t->refcount++;
+}
+
+void mail_index_transaction_unref(struct mail_index_transaction *t)
+{
+ if (--t->refcount == 0)
+ mail_index_transaction_free(t);
+}
+
static void
mail_index_buffer_convert_to_uids(struct mail_index_view *view,
buffer_t *buf, size_t record_size, int range)
@@ -114,7 +124,7 @@
int ret;
if (mail_index_view_is_inconsistent(t->view)) {
- mail_index_transaction_free(t);
+ mail_index_transaction_unref(t);
return -1;
}
@@ -128,13 +138,13 @@
log_file_offset_r);
}
- mail_index_transaction_free(t);
+ mail_index_transaction_unref(t);
return ret;
}
void mail_index_transaction_rollback(struct mail_index_transaction *t)
{
- mail_index_transaction_free(t);
+ mail_index_transaction_unref(t);
}
static void
@@ -208,6 +218,34 @@
rec->uid = uid;
}
+void mail_index_append_assign_uids(struct mail_index_transaction *t,
+ uint32_t first_uid, uint32_t *next_uid_r)
+{
+ struct mail_index_record *rec, *end;
+ size_t size;
+
+ if (t->appends == NULL)
+ return;
+
+ rec = buffer_get_modifyable_data(t->appends, &size);
+ end = PTR_OFFSET(rec, size);
+
+ /* find the first mail with uid = 0 */
+ while (rec != end) {
+ if (rec->uid == 0)
+ break;
+ rec = PTR_OFFSET(rec, t->append_record_size);
+ }
+
+ while (rec != end) {
+ i_assert(rec->uid == 0);
+ rec->uid = first_uid++;
+ rec = PTR_OFFSET(rec, t->append_record_size);
+ }
+
+ *next_uid_r = first_uid;
+}
+
void mail_index_expunge(struct mail_index_transaction *t, uint32_t seq)
{
struct mail_transaction_expunge exp, *data;
Index: mail-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- mail-index.h 28 Jun 2004 17:35:27 -0000 1.121
+++ mail-index.h 3 Jul 2004 10:57:53 -0000 1.122
@@ -179,10 +179,10 @@
void mail_index_transaction_rollback(struct mail_index_transaction *t);
/* Returns a view to transaction. Currently this differs from normal view only
- in that it contains newly appended messages in transaction. The view is
- destroyed when the transaction is destroyed. */
+ in that it contains newly appended messages in transaction. The view can
+ still be used after transaction has been committed. */
struct mail_index_view *
-mail_index_transaction_get_updated_view(struct mail_index_transaction *t);
+mail_index_transaction_open_updated_view(struct mail_index_transaction *t);
/* Begin synchronizing mailbox with index file. This call locks the index
exclusively against other modifications. Returns 1 if ok, -1 if error.
@@ -270,6 +270,10 @@
/* Append a new record to index. */
void mail_index_append(struct mail_index_transaction *t, uint32_t uid,
uint32_t *seq_r);
+/* Assigns UIDs for appended mails all at once. UID must have been given as 0
+ for mail_index_append(). Returns the next unused UID. */
+void mail_index_append_assign_uids(struct mail_index_transaction *t,
+ uint32_t first_uid, uint32_t *next_uid_r);
/* Expunge record from index. Note that this doesn't affect sequence numbers
until transaction is committed and mailbox is synced. */
void mail_index_expunge(struct mail_index_transaction *t, uint32_t seq);
More information about the dovecot-cvs
mailing list