[dovecot-cvs]
dovecot/src/imap cmd-copy.c,1.10,1.11 cmd-store.c,1.15,1.16
imap-fetch.c,1.7,1.8
cras at procontrol.fi
cras at procontrol.fi
Wed Jul 23 06:55:14 EEST 2003
Update of /home/cvs/dovecot/src/imap
In directory danu:/tmp/cvs-serv11704/imap
Modified Files:
cmd-copy.c cmd-store.c imap-fetch.c
Log Message:
Explicit lock() method for mailbox.
Index: cmd-copy.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-copy.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- cmd-copy.c 23 Jul 2003 01:44:16 -0000 1.10
+++ cmd-copy.c 23 Jul 2003 02:55:12 -0000 1.11
@@ -12,8 +12,7 @@
int failed = FALSE;
fetch_ctx = box->fetch_init(box, MAIL_FETCH_STREAM_HEADER |
- MAIL_FETCH_STREAM_BODY, FALSE,
- messageset, uidset);
+ MAIL_FETCH_STREAM_BODY, messageset, uidset);
if (fetch_ctx == NULL)
return FALSE;
@@ -56,10 +55,15 @@
return TRUE;
}
- /* FIXME: copying from mailbox to itself is kind of kludgy here.
- currently it works simply because copy_init() will lock mbox
- exclusively and fetching wont drop it. */
- copy_ctx = destbox->copy_init(destbox);
+ if (destbox == client->mailbox) {
+ /* copying inside same mailbox, make sure we get the
+ locking right */
+ if (!destbox->lock(destbox, MAILBOX_LOCK_READ |
+ MAILBOX_LOCK_SAVE))
+ failed = TRUE;
+ }
+
+ copy_ctx = failed ? NULL : destbox->copy_init(destbox);
if (copy_ctx == NULL)
failed = TRUE;
else {
@@ -71,6 +75,8 @@
failed = TRUE;
}
+ (void)destbox->lock(destbox, MAILBOX_LOCK_UNLOCK);
+
if (failed)
client_send_storage_error(client);
else if (!all_found) {
@@ -79,7 +85,10 @@
client_send_tagline(client,
"NO Some of the requested messages no longer exist.");
} else {
- client_sync_full_fast(client);
+ if (destbox == client->mailbox)
+ client_sync_full(client);
+ else
+ client_sync_full_fast(client);
client_send_tagline(client, "OK Copy completed.");
}
Index: cmd-store.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-store.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- cmd-store.c 23 Jul 2003 01:44:16 -0000 1.15
+++ cmd-store.c 23 Jul 2003 02:55:12 -0000 1.16
@@ -95,8 +95,11 @@
/* and update the flags */
box = client->mailbox;
- fetch_ctx = box->fetch_init(box, MAIL_FETCH_FLAGS, TRUE,
- messageset, client->cmd_uid);
+
+ failed = !box->lock(box, MAILBOX_LOCK_FLAGS | MAILBOX_LOCK_READ);
+ fetch_ctx = failed ? NULL :
+ box->fetch_init(box, MAIL_FETCH_FLAGS,
+ messageset, client->cmd_uid);
if (fetch_ctx == NULL)
failed = TRUE;
else {
@@ -118,6 +121,8 @@
if (!box->fetch_deinit(fetch_ctx, &all_found))
failed = TRUE;
+
+ (void)box->lock(box, MAILBOX_LOCK_UNLOCK);
if (!failed) {
if (client->cmd_uid)
Index: imap-fetch.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/imap-fetch.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- imap-fetch.c 23 Jul 2003 01:44:16 -0000 1.7
+++ imap-fetch.c 23 Jul 2003 02:55:12 -0000 1.8
@@ -262,6 +262,7 @@
struct imap_fetch_body_data *bodies,
const char *messageset, int uidset)
{
+ struct mailbox *box = client->mailbox;
struct imap_fetch_context ctx;
struct mail *mail;
int all_found;
@@ -274,7 +275,7 @@
ctx.select_counter = client->select_counter;
ctx.seen_flag.flags = MAIL_SEEN;
- if (!client->mailbox->readonly) {
+ if (!box->readonly) {
/* If we have any BODY[..] sections, \Seen flag is added for
all messages */
struct imap_fetch_body_data *body;
@@ -290,22 +291,29 @@
ctx.update_seen = TRUE;
}
- ctx.fetch_ctx = client->mailbox->
- fetch_init(client->mailbox, fetch_data, ctx.update_seen,
- messageset, uidset);
+ if (ctx.update_seen) {
+ if (!box->lock(box, MAILBOX_LOCK_FLAGS | MAILBOX_LOCK_READ))
+ return -1;
+ }
+
+ ctx.fetch_ctx = box->fetch_init(box, fetch_data, messageset, uidset);
if (ctx.fetch_ctx == NULL)
- return -1;
+ ctx.failed = TRUE;
+ else {
+ ctx.str = str_new(default_pool, 8192);
+ while ((mail = box->fetch_next(ctx.fetch_ctx)) != NULL) {
+ if (!fetch_mail(&ctx, mail)) {
+ ctx.failed = TRUE;
+ break;
+ }
+ }
+ str_free(ctx.str);
- ctx.str = str_new(default_pool, 8192);
- while ((mail = client->mailbox->fetch_next(ctx.fetch_ctx)) != NULL) {
- if (!fetch_mail(&ctx, mail)) {
+ if (!box->fetch_deinit(ctx.fetch_ctx, &all_found))
ctx.failed = TRUE;
- break;
- }
}
- str_free(ctx.str);
- if (!client->mailbox->fetch_deinit(ctx.fetch_ctx, &all_found))
- return -1;
+ (void)box->lock(box, MAILBOX_LOCK_UNLOCK);
+
return ctx.failed ? -1 : all_found;
}
More information about the dovecot-cvs
mailing list