[dovecot-cvs] dovecot/src/lib-storage/index/dbox dbox-file.c, 1.8, 1.9 dbox-keywords.c, 1.1, 1.2 dbox-sync-expunge.c, 1.7, 1.8 dbox-sync.c, 1.8, 1.9

cras at dovecot.org cras at dovecot.org
Fri Feb 24 19:33:51 EET 2006


Update of /var/lib/cvs/dovecot/src/lib-storage/index/dbox
In directory talvi:/tmp/cvs-serv24928

Modified Files:
	dbox-file.c dbox-keywords.c dbox-sync-expunge.c dbox-sync.c 
Log Message:
Fixes



Index: dbox-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-file.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- dbox-file.c	24 Feb 2006 16:06:51 -0000	1.8
+++ dbox-file.c	24 Feb 2006 17:33:48 -0000	1.9
@@ -94,7 +94,8 @@
 	if (memcmp(hdr->magic, DBOX_MAIL_HEADER_MAGIC,
 		   sizeof(hdr->magic)) != 0) {
 		mail_storage_set_critical(STORAGE(mbox->storage),
-			"Corrupted mail header in dbox file %s", file->path);
+			"Corrupted mail header at %"PRIuUOFF_T
+			" in dbox file %s", offset, file->path);
 		return -1;
 	}
 	return 1;

Index: dbox-keywords.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-keywords.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dbox-keywords.c	28 Jan 2006 22:05:48 -0000	1.1
+++ dbox-keywords.c	24 Feb 2006 17:33:48 -0000	1.2
@@ -193,6 +193,7 @@
 
 	str_append_c(keyword_str, '\n');
 	i_assert(str_len(keyword_str) <= file->keyword_list_size_alloc);
+	i_assert(new_pos < str_len(keyword_str));
 
 	/* we can reuse the existing keyword list position */
 	if (pwrite_full(file->fd, str_data(keyword_str) + new_pos,

Index: dbox-sync-expunge.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-sync-expunge.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- dbox-sync-expunge.c	24 Feb 2006 16:06:51 -0000	1.7
+++ dbox-sync-expunge.c	24 Feb 2006 17:33:48 -0000	1.8
@@ -81,10 +81,12 @@
 	struct dbox_file_header hdr;
         struct dbox_uidlist_entry dest_entry;
 	const struct dbox_sync_rec *sync_recs;
-	const char *path;
+	const char *path, *lock_path;
 	uint32_t file_seq, seq, uid1, uid2;
 	unsigned int sync_count;
 	int ret, fd;
+	uoff_t full_size;
+	off_t bytes;
 
 	/* skip mails until we find the first we don't want expunged */
 	ret = dbox_file_seek(mbox, orig_entry->file_seq, orig_offset);
@@ -114,13 +116,25 @@
 
 	file_seq = dbox_uidlist_get_new_file_seq(mbox->uidlist);
 
-	path = t_strdup_printf("%s/"DBOX_MAILDIR_NAME"/"
-			       DBOX_MAIL_FILE_FORMAT,
-			       mbox->path, file_seq);
-	fd = file_dotlock_open(&new_file_dotlock_set, path, 0, &dotlock);
-	if (fd < 0)
-		return -1;
+	for (;; file_seq++) {
+		path = t_strdup_printf("%s/"DBOX_MAILDIR_NAME"/"
+				       DBOX_MAIL_FILE_FORMAT,
+				       mbox->path, file_seq);
+		fd = file_dotlock_open(&new_file_dotlock_set, path,
+				       DOTLOCK_CREATE_FLAG_NONBLOCK, &dotlock);
+		if (fd >= 0)
+			break;
+
+		if (errno != EAGAIN) {
+			mail_storage_set_critical(STORAGE(mbox->storage),
+				"file_dotlock_open(%s) failed: %m", path);
+			return -1;
+		}
+
+		/* try again with another file name */
+	}
 	output = o_stream_create_file(fd, default_pool, 0, FALSE);
+	lock_path = file_dotlock_get_lock_path(dotlock);
 
 	memset(&dest_entry, 0, sizeof(dest_entry));
 	ARRAY_CREATE(&dest_entry.uid_list, pool_datastack_create(),
@@ -131,7 +145,7 @@
 	dbox_file_header_init(&hdr);
 	if (o_stream_send(output, &hdr, sizeof(hdr)) != sizeof(hdr)) {
 		mail_storage_set_critical(STORAGE(mbox->storage),
-			"o_stream_send(%s) failed: %m", path);
+			"o_stream_send(%s) failed: %m", lock_path);
 		ret = -1;
 	}
 
@@ -162,16 +176,27 @@
 				      &hdr_offset, NULL);
 
 		/* copy the mail */
+		full_size = mbox->file->mail_header_size +
+			mbox->file->seeked_mail_size;
 		input = i_stream_create_limit(default_pool, mbox->file->input,
 					      mbox->file->seeked_offset,
-					      mbox->file->mail_header_size +
-					      mbox->file->seeked_mail_size);
-		ret = o_stream_send_istream(output, input);
+					      full_size);
+		bytes = o_stream_send_istream(output, input);
 		i_stream_unref(&input);
 
-		if (ret < 0) {
+		if (bytes < 0) {
 			mail_storage_set_critical(STORAGE(mbox->storage),
-				"o_stream_send_istream(%s) failed: %m", path);
+				"o_stream_send_istream(%s) failed: %m",
+				lock_path);
+			ret = -1;
+			break;
+		}
+		if ((uoff_t)bytes != full_size) {
+			mail_storage_set_critical(STORAGE(mbox->storage),
+				"o_stream_send_istream(%s) wrote only %"
+				PRIuUOFF_T" of %"PRIuUOFF_T" bytes", lock_path,
+				(uoff_t)bytes, full_size);
+			ret = -1;
 			break;
 		}
 
@@ -249,9 +274,8 @@
 		uid = range[i].seq1;
 
 		if (!seen_expunges) {
-			if (uid != first_expunged_uid) {
+			if (uid < first_expunged_uid) {
 				/* range begins with non-expunged messages */
-				i_assert(uid < first_expunged_uid);
 				uid = first_expunged_uid;
 				skipped_expunges = TRUE;
 			}
@@ -353,8 +377,11 @@
 		ret = file_dotlock_create(&new_file_dotlock_set, path,
 					  DOTLOCK_CREATE_FLAG_NONBLOCK,
 					  &dotlock);
-		if (ret < 0)
+		if (ret < 0) {
+			mail_storage_set_critical(STORAGE(ctx->mbox->storage),
+				"file_dotlock_create(%s) failed: %m", path);
 			return -1;
+		}
 
 		if (ret > 0) {
 			/* locked - copy the non-expunged mails after the

Index: dbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-sync.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- dbox-sync.c	24 Feb 2006 16:06:51 -0000	1.8
+++ dbox-sync.c	24 Feb 2006 17:33:48 -0000	1.9
@@ -148,8 +148,10 @@
 
 	while (mbox->file->seeked_uid <= uid2) {
 		for (i = 0; i < flag_count; ) {
-			if (!mask[i])
+			if (!mask[i]) {
+				i++;
 				continue;
+			}
 
 			start = i;
 			while (i < flag_count) {



More information about the dovecot-cvs mailing list