changeset 8286:68a7068c7675 HEAD

IMAP: Make sure pending syncs are done before a mailbox-changing command is run.
author Timo Sirainen <tss@iki.fi>
date Sun, 24 May 2009 18:08:58 -0400
parents 24f9aca75de0
children 5039adc82996
files src/imap/client.c
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/client.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/imap/client.c	Sun May 24 18:08:58 2009 -0400
@@ -357,13 +357,14 @@
 
 static struct client_command_context *
 client_command_find_with_flags(struct client_command_context *new_cmd,
-			       enum command_flags flags)
+			       enum command_flags flags,
+			       enum client_command_state max_state)
 {
 	struct client_command_context *cmd;
 
 	cmd = new_cmd->client->command_queue;
 	for (; cmd != NULL; cmd = cmd->next) {
-		if (cmd->state < CLIENT_COMMAND_STATE_WAIT_SYNC &&
+		if (cmd->state <= max_state &&
 		    cmd != new_cmd && (cmd->cmd_flags & flags) != 0)
 			return cmd;
 	}
@@ -373,6 +374,8 @@
 static bool client_command_check_ambiguity(struct client_command_context *cmd)
 {
 	enum command_flags flags;
+	enum client_command_state max_state =
+		CLIENT_COMMAND_STATE_WAIT_UNAMBIGUITY;
 	bool broken_client = FALSE;
 
 	if ((cmd->cmd_flags & COMMAND_FLAG_BREAKS_MAILBOX) ==
@@ -380,6 +383,7 @@
 		/* there must be no other command running that uses the
 		   selected mailbox */
 		flags = COMMAND_FLAG_USES_MAILBOX;
+		max_state = CLIENT_COMMAND_STATE_DONE;
 	} else if ((cmd->cmd_flags & COMMAND_FLAG_USES_SEQS) != 0) {
 		/* no existing command must be breaking sequences */
 		flags = COMMAND_FLAG_BREAKS_SEQS;
@@ -391,7 +395,7 @@
 		return FALSE;
 	}
 
-	if (client_command_find_with_flags(cmd, flags) == NULL) {
+	if (client_command_find_with_flags(cmd, flags, max_state) == NULL) {
 		if (cmd->client->syncing) {
 			/* don't do anything until syncing is finished */
 			return TRUE;