changeset 5923:239078f515a8 HEAD

Added maildir_uidlist_sync_remove()
author Timo Sirainen <tss@iki.fi>
date Mon, 09 Jul 2007 00:13:51 +0300
parents 79513299d42c
children ac05ec8c7171
files src/lib-storage/index/maildir/maildir-uidlist.c src/lib-storage/index/maildir/maildir-uidlist.h
diffstat 2 files changed, 37 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Mon Jul 09 00:13:32 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Mon Jul 09 00:13:51 2007 +0300
@@ -76,6 +76,7 @@
 
 	unsigned int partial:1;
 	unsigned int finished:1;
+	unsigned int changed:1;
 	unsigned int failed:1;
 };
 
@@ -732,6 +733,7 @@
 		if (ctx->new_files_count == 0)
 			ctx->first_new_pos = array_count(&uidlist->records);
 		ctx->new_files_count++;
+		ctx->changed = TRUE;
 
 		if (uidlist->record_pool == NULL) {
 			uidlist->record_pool =
@@ -813,6 +815,7 @@
 		else {
 			rec->uid = (uint32_t)-1;
 			ctx->new_files_count++;
+			ctx->changed = TRUE;
 		}
 
 		array_append(&ctx->records, &rec, 1);
@@ -828,6 +831,36 @@
 	return 1;
 }
 
+static int maildir_uid_cmp(const void *p1, const void *p2)
+{
+	const struct maildir_uidlist_rec *const *rec1 = p1, *const *rec2 = p2;
+
+	return (*rec1)->uid < (*rec2)->uid ? -1 :
+		(*rec1)->uid > (*rec2)->uid ? 1 : 0;
+}
+
+void maildir_uidlist_sync_remove(struct maildir_uidlist_sync_ctx *ctx,
+				 const char *filename)
+{
+	struct maildir_uidlist_rec *const *recs, *const *pos, *rec;
+	unsigned int count;
+
+	i_assert(ctx->partial);
+
+	rec = hash_lookup(ctx->uidlist->files, filename);
+	i_assert(rec != NULL);
+
+	hash_remove(ctx->uidlist->files, filename);
+
+	recs = array_get(&ctx->uidlist->records, &count);
+	pos = bsearch(&rec, recs, count, sizeof(*recs), maildir_uid_cmp);
+	i_assert(pos != NULL);
+
+	array_delete(&ctx->uidlist->records, pos - recs, 1);
+
+	ctx->changed = TRUE;
+}
+
 const char *
 maildir_uidlist_sync_get_full_filename(struct maildir_uidlist_sync_ctx *ctx,
 				       const char *filename)
@@ -883,14 +916,6 @@
         ctx->uidlist->last_seen_uid = ctx->uidlist->next_uid-1;
 }
 
-static int maildir_uid_cmp(const void *p1, const void *p2)
-{
-	const struct maildir_uidlist_rec *const *rec1 = p1, *const *rec2 = p2;
-
-	return (*rec1)->uid < (*rec2)->uid ? -1 :
-		(*rec1)->uid > (*rec2)->uid ? 1 : 0;
-}
-
 static void maildir_uidlist_swap(struct maildir_uidlist_sync_ctx *ctx)
 {
 	struct maildir_uidlist *uidlist = ctx->uidlist;
@@ -931,7 +956,7 @@
 		if (!ctx->failed)
 			maildir_uidlist_swap(ctx);
 	} else {
-		if (ctx->new_files_count != 0)
+		if (ctx->changed)
 			maildir_uidlist_assign_uids(ctx, ctx->first_new_pos);
 	}
 
@@ -952,7 +977,7 @@
 	if (ctx->partial)
 		maildir_uidlist_mark_all(ctx->uidlist, FALSE);
 
-	if (ctx->new_files_count != 0 && !ctx->failed) {
+	if (ctx->changed && !ctx->failed) {
 		t_push();
 		ret = maildir_uidlist_recreate(ctx->uidlist);
 		t_pop();
--- a/src/lib-storage/index/maildir/maildir-uidlist.h	Mon Jul 09 00:13:32 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.h	Mon Jul 09 00:13:51 2007 +0300
@@ -55,6 +55,8 @@
 int maildir_uidlist_sync_next(struct maildir_uidlist_sync_ctx *ctx,
 			      const char *filename,
 			      enum maildir_uidlist_rec_flag flags);
+void maildir_uidlist_sync_remove(struct maildir_uidlist_sync_ctx *ctx,
+				 const char *filename);
 const char *
 maildir_uidlist_sync_get_full_filename(struct maildir_uidlist_sync_ctx *ctx,
 				       const char *filename);