dovecot: Added maildir_uidlist_sync_remove()
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jul 9 05:44:44 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/239078f515a8
changeset: 5923:239078f515a8
user: Timo Sirainen <tss at iki.fi>
date: Mon Jul 09 00:13:51 2007 +0300
description:
Added maildir_uidlist_sync_remove()
diffstat:
2 files changed, 37 insertions(+), 10 deletions(-)
src/lib-storage/index/maildir/maildir-uidlist.c | 45 +++++++++++++++++------
src/lib-storage/index/maildir/maildir-uidlist.h | 2 +
diffs (109 lines):
diff -r 79513299d42c -r 239078f515a8 src/lib-storage/index/maildir/maildir-uidlist.c
--- 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 @@ struct maildir_uidlist_sync_ctx {
unsigned int partial:1;
unsigned int finished:1;
+ unsigned int changed:1;
unsigned int failed:1;
};
@@ -732,6 +733,7 @@ maildir_uidlist_sync_next_partial(struct
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 @@ int maildir_uidlist_sync_next(struct mai
else {
rec->uid = (uint32_t)-1;
ctx->new_files_count++;
+ ctx->changed = TRUE;
}
array_append(&ctx->records, &rec, 1);
@@ -826,6 +829,36 @@ int maildir_uidlist_sync_next(struct mai
rec->filename = p_strdup(ctx->record_pool, filename);
hash_insert(ctx->files, rec->filename, rec);
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 *
@@ -883,14 +916,6 @@ static void maildir_uidlist_assign_uids(
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 @@ void maildir_uidlist_sync_finish(struct
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 @@ int maildir_uidlist_sync_deinit(struct m
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();
diff -r 79513299d42c -r 239078f515a8 src/lib-storage/index/maildir/maildir-uidlist.h
--- 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 mai
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);
More information about the dovecot-cvs
mailing list