[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-list.c, 1.27, 1.28 maildir-mail.c, 1.2, 1.3 maildir-storage.c, 1.70, 1.71 maildir-storage.h, 1.21, 1.22 maildir-sync.c, 1.11, 1.12 maildir-uidlist.c, 1.12, 1.13 maildir-uidlist.h, 1.3, 1.4

cras at procontrol.fi cras at procontrol.fi
Thu May 6 04:22:27 EEST 2004


Update of /home/cvs/dovecot/src/lib-storage/index/maildir
In directory talvi:/tmp/cvs-serv13512/src/lib-storage/index/maildir

Modified Files:
	maildir-list.c maildir-mail.c maildir-storage.c 
	maildir-storage.h maildir-sync.c maildir-uidlist.c 
	maildir-uidlist.h 
Log Message:
mbox code compiles again, but syncing is only partially implemented so
accessing mboxes fails..

Also some cleanups to index-storage and maildir code.



Index: maildir-list.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-list.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- maildir-list.c	2 May 2004 00:14:12 -0000	1.27
+++ maildir-list.c	6 May 2004 01:22:25 -0000	1.28
@@ -19,7 +19,6 @@
 	struct mailbox_list_context mailbox_ctx;
 	pool_t pool;
 
-	struct mail_storage *storage;
 	const char *dir, *prefix;
         enum mailbox_list_flags flags;
 
@@ -63,7 +62,7 @@
 	dirp = opendir(ctx->dir);
 	if (dirp == NULL) {
 		if (errno != ENOENT) {
-			mail_storage_set_critical(ctx->storage,
+			mail_storage_set_critical(ctx->mailbox_ctx.storage,
 				"opendir(%s) failed: %m", ctx->dir);
 			return FALSE;
 		}
@@ -171,7 +170,7 @@
 	}
 
 	if (closedir(dirp) < 0) {
-		mail_storage_set_critical(ctx->storage,
+		mail_storage_set_critical(ctx->mailbox_ctx.storage,
 					  "readdir(%s) failed: %m", ctx->dir);
 		return FALSE;
 	}
@@ -184,7 +183,8 @@
 static int maildir_fill_subscribed(struct maildir_list_context *ctx,
 				   struct imap_match_glob *glob)
 {
-	struct index_storage *istorage = (struct index_storage *)ctx->storage;
+	struct index_storage *istorage =
+		(struct index_storage *)ctx->mailbox_ctx.storage;
 	struct subsfile_list_context *subsfile_ctx;
 	const char *path, *name, *p;
 	struct mailbox_node *node;
@@ -193,7 +193,7 @@
 	path = t_strconcat(istorage->control_dir != NULL ?
 			   istorage->control_dir : istorage->dir,
 			   "/" SUBSCRIPTION_FILE_NAME, NULL);
-	subsfile_ctx = subsfile_list_init(ctx->storage, path);
+	subsfile_ctx = subsfile_list_init(ctx->mailbox_ctx.storage, path);
 	if (subsfile_ctx == NULL)
 		return FALSE;
 
@@ -245,8 +245,8 @@
 
 	pool = pool_alloconly_create("maildir_list", 1024);
 	ctx = p_new(pool, struct maildir_list_context, 1);
+	ctx->mailbox_ctx.storage = storage;
 	ctx->pool = pool;
-	ctx->storage = storage;
 	ctx->flags = flags;
 	ctx->tree_ctx = mailbox_tree_init(MAILDIR_FS_SEP);
 
@@ -352,7 +352,7 @@
 
 		str_truncate(ctx->node_path, 0);
 		node = find_next(&ctx->root, ctx->node_path,
-				 ctx->storage->hierarchy_sep);
+				 ctx->mailbox_ctx.storage->hierarchy_sep);
                 ctx->parent_pos = str_len(ctx->node_path);
 
 		if (node == NULL)
@@ -364,8 +364,10 @@
 	node->flags &= ~MAILBOX_FLAG_MATCHED;
 
 	str_truncate(ctx->node_path, ctx->parent_pos);
-	if (ctx->parent_pos != 0)
-		str_append_c(ctx->node_path, ctx->storage->hierarchy_sep);
+	if (ctx->parent_pos != 0) {
+		str_append_c(ctx->node_path,
+			     ctx->mailbox_ctx.storage->hierarchy_sep);
+	}
 	str_append(ctx->node_path, node->name);
 
 	ctx->list.name = str_c(ctx->node_path);

Index: maildir-mail.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-mail.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- maildir-mail.c	1 May 2004 18:30:53 -0000	1.2
+++ maildir-mail.c	6 May 2004 01:22:25 -0000	1.3
@@ -68,9 +68,8 @@
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
 	struct index_mail_data *data = &mail->data;
-        const struct mail_full_flags *flags;
 
-	flags = index_mail_get_flags(_mail);
+	(void)index_mail_get_flags(_mail);
 
 	if (maildir_uidlist_is_recent(mail->ibox->uidlist, _mail->uid))
 		data->flags.flags |= MAIL_RECENT;
@@ -84,15 +83,10 @@
 	struct stat st;
 	int fd;
 
+	(void)index_mail_get_received_date(_mail);
 	if (data->received_date != (time_t)-1)
 		return data->received_date;
 
-	if ((mail->wanted_fields & MAIL_FETCH_RECEIVED_DATE) == 0) {
-		data->received_date = index_mail_get_cached_received_date(mail);
-		if (data->received_date != (time_t)-1)
-			return data->received_date;
-	}
-
 	if (data->stream != NULL) {
 		fd = i_stream_get_fd(data->stream);
 		i_assert(fd != -1);

Index: maildir-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- maildir-storage.c	3 May 2004 19:15:51 -0000	1.70
+++ maildir-storage.c	6 May 2004 01:22:25 -0000	1.71
@@ -108,9 +108,6 @@
 
 	index_storage_deinit(storage);
 
-	i_free(storage->storage.namespace);
-	i_free(storage->storage.error);
-
 	i_free(storage->dir);
 	i_free(storage->inbox_path);
 	i_free(storage->index_dir);

Index: maildir-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- maildir-storage.h	2 May 2004 20:32:16 -0000	1.21
+++ maildir-storage.h	6 May 2004 01:22:25 -0000	1.22
@@ -57,9 +57,6 @@
 int maildir_copy_commit(struct maildir_copy_context *ctx);
 void maildir_copy_rollback(struct maildir_copy_context *ctx);
 
-int maildir_storage_expunge(struct mail *mail,
-			    struct mailbox_transaction_context *t);
-
 const char *maildir_fix_mailbox_name(struct index_storage *storage,
 				     const char *name, int remove_namespace);
 const char *maildir_get_path(struct index_storage *storage, const char *name);

Index: maildir-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-sync.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- maildir-sync.c	3 May 2004 19:28:47 -0000	1.11
+++ maildir-sync.c	6 May 2004 01:22:25 -0000	1.12
@@ -390,6 +390,13 @@
 		if (dp->d_name[0] == '.')
 			continue;
 
+		ret = maildir_uidlist_sync_next_pre(ctx->uidlist_sync_ctx,
+						    dp->d_name);
+		if (ret == 0)
+			continue;
+		if (ret < 0)
+			break;
+
 		flags = 0;
 		if (move_new) {
 			str_truncate(src, 0);

Index: maildir-uidlist.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-uidlist.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- maildir-uidlist.c	3 May 2004 22:15:08 -0000	1.12
+++ maildir-uidlist.c	6 May 2004 01:22:25 -0000	1.13
@@ -58,6 +58,7 @@
 
 	unsigned int partial:1;
 	unsigned int synced:1;
+	unsigned int locked:1;
 	unsigned int failed:1;
 };
 
@@ -559,8 +560,10 @@
 	/* lock and update uidlist to see if it's just been added */
 	ret = maildir_uidlist_try_lock(ctx->uidlist);
 	if (ret <= 0) {
-		if (ret == 0)
-			return 1; // FIXME: does it work right?
+		if (ret == 0) {
+			ctx->locked = TRUE;
+			return -1;
+		}
 		ctx->failed = TRUE;
 		return -1;
 	}
@@ -580,21 +583,10 @@
 {
 	struct maildir_uidlist *uidlist = ctx->uidlist;
 	struct maildir_uidlist_rec *rec;
-	int ret;
 
 	/* we'll update uidlist directly */
 	rec = hash_lookup(uidlist->files, filename);
-	if (rec == NULL && !ctx->synced) {
-		ret = maildir_uidlist_sync_uidlist(ctx);
-		if (ret < 0)
-			return -1;
-		if (ret == 0) {
-			return maildir_uidlist_sync_next_partial(ctx, filename,
-								 flags);
-		}
-
-		rec = hash_lookup(uidlist->files, filename);
-	}
+	i_assert(rec != NULL || ctx->synced);
 
 	if (rec == NULL) {
 		if (ctx->new_files_count == 0) {
@@ -616,13 +608,33 @@
 	return 1;
 }
 
+int maildir_uidlist_sync_next_pre(struct maildir_uidlist_sync_ctx *ctx,
+				  const char *filename)
+{
+	int ret;
+
+	if (!ctx->synced &&
+	    hash_lookup(ctx->uidlist->files, filename) == NULL &&
+	    (ctx->partial || hash_lookup(ctx->files, filename) == NULL)) {
+		if (ctx->locked)
+			return 0;
+
+		ret = maildir_uidlist_sync_uidlist(ctx);
+		if (ret < 0)
+			return ctx->locked ? 0 : -1;
+		if (ret == 0)
+			return maildir_uidlist_sync_next_pre(ctx, filename);
+	}
+
+	return 1;
+}
+
 int maildir_uidlist_sync_next(struct maildir_uidlist_sync_ctx *ctx,
 			      const char *filename,
 			      enum maildir_uidlist_rec_flag flags)
 {
 	struct maildir_uidlist *uidlist = ctx->uidlist;
 	struct maildir_uidlist_rec *rec, *old_rec;
-	int ret;
 
 	if (ctx->failed)
 		return -1;
@@ -642,16 +654,7 @@
 				MAILDIR_UIDLIST_REC_FLAG_MOVED);
 	} else {
 		old_rec = hash_lookup(uidlist->files, filename);
-		if (old_rec == NULL && !ctx->synced) {
-			ret = maildir_uidlist_sync_uidlist(ctx);
-			if (ret < 0)
-				return -1;
-			if (ret == 0) {
-				return maildir_uidlist_sync_next(ctx, filename,
-								 flags);
-			}
-			old_rec = hash_lookup(uidlist->files, filename);
-		}
+		i_assert(old_rec != NULL || ctx->synced);
 
 		rec = p_new(ctx->record_pool, struct maildir_uidlist_rec, 1);
 
@@ -762,10 +765,10 @@
 {
 	int ret = ctx->failed ? -1 : 0;
 
-	// FIXME: we most likely don't handle ctx->failed well enough
-	if (!ctx->partial)
-		maildir_uidlist_swap(ctx);
-	else {
+	if (!ctx->partial) {
+		if (!ctx->failed && !ctx->locked)
+			maildir_uidlist_swap(ctx);
+	} else {
 		if (ctx->new_files_count != 0) {
 			maildir_uidlist_assign_uids(ctx->uidlist,
 						    ctx->first_new_pos);
@@ -773,7 +776,7 @@
 		maildir_uidlist_mark_all(ctx->uidlist, FALSE);
 	}
 
-	if (ctx->new_files_count != 0 && ret == 0)
+	if (ctx->new_files_count != 0 && !ctx->failed && !ctx->locked)
 		ret = maildir_uidlist_rewrite(ctx->uidlist);
 
 	if (UIDLIST_IS_LOCKED(ctx->uidlist))

Index: maildir-uidlist.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-uidlist.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- maildir-uidlist.h	2 May 2004 18:07:25 -0000	1.3
+++ maildir-uidlist.h	6 May 2004 01:22:25 -0000	1.4
@@ -31,6 +31,9 @@
 /* Sync uidlist with what's actually on maildir. */
 struct maildir_uidlist_sync_ctx *
 maildir_uidlist_sync_init(struct maildir_uidlist *uidlist, int partial);
+/* Returns 1 = ok, -1 = error, 0 = new file and dovecot-uidlist is locked */
+int maildir_uidlist_sync_next_pre(struct maildir_uidlist_sync_ctx *ctx,
+				  const char *filename);
 int maildir_uidlist_sync_next(struct maildir_uidlist_sync_ctx *ctx,
 			      const char *filename,
 			      enum maildir_uidlist_rec_flag flags);



More information about the dovecot-cvs mailing list