# HG changeset patch # User Timo Sirainen # Date 1313357685 -10800 # Node ID e2379af31de1e34d2000e7254e89186ba9a3b3d8 # Parent 68c7faa869f84100a18ffefe3bdb2e1faf770feb mbox: Generate mailbox GUID without syncing the mbox, locking it is enough. diff -r 68c7faa869f8 -r e2379af31de1 src/lib-storage/index/mbox/mbox-storage.c --- a/src/lib-storage/index/mbox/mbox-storage.c Mon Aug 15 00:30:18 2011 +0300 +++ b/src/lib-storage/index/mbox/mbox-storage.c Mon Aug 15 00:34:45 2011 +0300 @@ -597,7 +597,7 @@ return -1; } if (mail_guid_128_is_empty(mbox->mbox_hdr.mailbox_guid)) { - if (mailbox_sync(&mbox->box, 0) < 0) + if (mbox_sync_get_guid(mbox) < 0) return -1; } memcpy(guid, mbox->mbox_hdr.mailbox_guid, MAIL_GUID_128_SIZE); diff -r 68c7faa869f8 -r e2379af31de1 src/lib-storage/index/mbox/mbox-sync-private.h --- a/src/lib-storage/index/mbox/mbox-sync-private.h Mon Aug 15 00:30:18 2011 +0300 +++ b/src/lib-storage/index/mbox/mbox-sync-private.h Mon Aug 15 00:34:45 2011 +0300 @@ -179,5 +179,6 @@ size_t pos, size_t need, size_t have); void mbox_sync_headers_add_space(struct mbox_sync_mail_context *ctx, size_t size); +int mbox_sync_get_guid(struct mbox_mailbox *mbox); #endif diff -r 68c7faa869f8 -r e2379af31de1 src/lib-storage/index/mbox/mbox-sync.c --- a/src/lib-storage/index/mbox/mbox-sync.c Mon Aug 15 00:30:18 2011 +0300 +++ b/src/lib-storage/index/mbox/mbox-sync.c Mon Aug 15 00:34:45 2011 +0300 @@ -1376,10 +1376,10 @@ } static void -mbox_sync_index_update_ext_header(struct mbox_sync_context *sync_ctx) +mbox_sync_index_update_ext_header(struct mbox_mailbox *mbox, + struct mail_index_transaction *trans) { - const struct mailbox_update *update = sync_ctx->mbox->sync_hdr_update; - struct mbox_mailbox *mbox = sync_ctx->mbox; + const struct mailbox_update *update = mbox->sync_hdr_update; const void *data; size_t data_size; @@ -1394,7 +1394,7 @@ &data, &data_size); if (data_size != sizeof(mbox->mbox_hdr) || memcmp(data, &mbox->mbox_hdr, data_size) != 0) { - mail_index_update_header_ext(sync_ctx->t, mbox->mbox_ext_idx, + mail_index_update_header_ext(trans, mbox->mbox_ext_idx, 0, &mbox->mbox_hdr, sizeof(mbox->mbox_hdr)); } @@ -1446,7 +1446,7 @@ sync_ctx->mbox->mbox_hdr.sync_mtime = st->st_mtime; sync_ctx->mbox->mbox_hdr.sync_size = st->st_size; - mbox_sync_index_update_ext_header(sync_ctx); + mbox_sync_index_update_ext_header(sync_ctx->mbox, sync_ctx->t); /* only reason not to have UID validity at this point is if the file is entirely empty. In that case just make up a new one if needed. */ @@ -1650,6 +1650,27 @@ return 0; } +int mbox_sync_get_guid(struct mbox_mailbox *mbox) +{ + struct mail_index_transaction *trans; + unsigned int lock_id; + int ret; + + if (mbox_lock(mbox, F_WRLCK, &lock_id) <= 0) + return -1; + + ret = mbox_sync_header_refresh(mbox); + if (ret == 0) { + trans = mail_index_transaction_begin(mbox->box.view, + MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL); + mbox_sync_index_update_ext_header(mbox, trans); + ret = mail_index_transaction_commit(&trans); + } + mbox_unlock(mbox, lock_id); + return ret; + +} + int mbox_sync_has_changed(struct mbox_mailbox *mbox, bool leave_dirty) { bool empty;