[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-file.c, 1.20, 1.21 mbox-lock.c, 1.29, 1.30 mbox-save.c, 1.113, 1.114 mbox-storage.c, 1.183, 1.184 mbox-sync.c, 1.210, 1.211

tss at dovecot.org tss at dovecot.org
Sun May 13 20:10:58 EEST 2007


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

Modified Files:
	mbox-file.c mbox-lock.c mbox-save.c mbox-storage.c mbox-sync.c 
Log Message:
Error handling rewrite.



Index: mbox-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-file.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- mbox-file.c	30 Mar 2007 12:44:06 -0000	1.20
+++ mbox-file.c	13 May 2007 17:10:55 -0000	1.21
@@ -171,6 +171,7 @@
 	if (istream_raw_mbox_seek(mbox->mbox_stream, offset) < 0) {
 		if (offset == 0) {
 			mail_storage_set_error(&mbox->storage->storage,
+				MAIL_ERROR_NOTPOSSIBLE,
 				"Mailbox isn't a valid mbox file");
 			return -1;
 		}

Index: mbox-lock.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-lock.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- mbox-lock.c	30 Mar 2007 12:44:06 -0000	1.29
+++ mbox-lock.c	13 May 2007 17:10:55 -0000	1.30
@@ -263,8 +263,7 @@
 	}
 	if (ret == 0) {
 		mail_storage_set_error(&mbox->storage->storage,
-				       "Timeout while waiting for lock");
-		mbox->storage->storage.temporary_error = TRUE;
+			MAIL_ERROR_TEMP, MAIL_ERRSTR_LOCK_TIMEOUT);
 		return 0;
 	}
 	mbox->mbox_dotlocked = TRUE;
@@ -495,8 +494,7 @@
 			(void)mbox_unlock_files(&ctx);
 		if (ret == 0) {
 			mail_storage_set_error(&mbox->storage->storage,
-				"Timeout while waiting for lock");
-			mbox->storage->storage.temporary_error = TRUE;
+				MAIL_ERROR_TEMP, MAIL_ERRSTR_LOCK_TIMEOUT);
 		}
 		return ret;
 	}

Index: mbox-save.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-save.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- mbox-save.c	11 May 2007 18:57:52 -0000	1.113
+++ mbox-save.c	13 May 2007 17:10:55 -0000	1.114
@@ -59,13 +59,7 @@
 
 static int write_error(struct mbox_save_context *ctx)
 {
-	if (ENOSPACE(errno)) {
-		mail_storage_set_error(&ctx->mbox->storage->storage,
-				       "Not enough disk space");
-	} else {
-		mbox_set_syscall_error(ctx->mbox, "write()");
-	}
-
+	mbox_set_syscall_error(ctx->mbox, "write()");
 	ctx->failed = TRUE;
 	return -1;
 }
@@ -266,10 +260,11 @@
 		    struct mbox_transaction_context *t, bool want_mail)
 {
 	struct mbox_mailbox *mbox = ctx->mbox;
+	struct mail_storage *storage = &mbox->storage->storage;
 	int ret;
 
 	if (ctx->mbox->mbox_readonly) {
-		mail_storage_set_error(&ctx->mbox->storage->storage,
+		mail_storage_set_error(storage, MAIL_ERROR_PERM,
 				       "Read-only mbox");
 		return -1;
 	}
@@ -284,8 +279,8 @@
 				/* FIXME: we shouldn't fail here. it's just
 				   a locking issue that should be possible to
 				   fix.. */
-				mail_storage_set_error(
-					&ctx->mbox->storage->storage,
+				mail_storage_set_error(storage,
+					MAIL_ERROR_NOTPOSSIBLE,
 					"Can't copy mails inside same mailbox");
 				return -1;
 			}

Index: mbox-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.c,v
retrieving revision 1.183
retrieving revision 1.184
diff -u -d -r1.183 -r1.184
--- mbox-storage.c	17 Apr 2007 12:41:29 -0000	1.183
+++ mbox-storage.c	13 May 2007 17:10:55 -0000	1.184
@@ -84,7 +84,7 @@
 
 	if (ENOSPACE(errno)) {
 		mail_storage_set_error(&mbox->storage->storage,
-				       "Not enough disk space");
+			MAIL_ERROR_NOSPACE, MAIL_ERRSTR_NO_SPACE);
 	} else {
 		mail_storage_set_critical(&mbox->storage->storage,
 					  "%s failed with mbox file %s: %m",
@@ -648,7 +648,7 @@
 		  struct istream *input, enum mailbox_open_flags flags)
 {
 	struct mbox_storage *storage = (struct mbox_storage *)_storage;
-	const char *path, *error;
+	const char *path;
 	struct stat st;
 
 	if (input != NULL)
@@ -665,8 +665,9 @@
 				     MAILBOX_LIST_PATH_TYPE_MAILBOX);
 	if (stat(path, &st) == 0) {
 		if (S_ISDIR(st.st_mode)) {
-			mail_storage_set_error(_storage,
-				"Mailbox isn't selectable: %s", name);
+			mail_storage_set_error(_storage, MAIL_ERROR_NOTPOSSIBLE,
+				t_strdup_printf("Mailbox isn't selectable: %s",
+						name));
 			return NULL;
 		}
 
@@ -674,11 +675,9 @@
 	}
 
 	if (ENOTFOUND(errno)) {
-		mail_storage_set_error(_storage,
-			MAILBOX_LIST_ERR_MAILBOX_NOT_FOUND, name);
-	} else if (mail_storage_errno2str(&error))
-		mail_storage_set_error(_storage, "%s", error);
-	else {
+		mail_storage_set_error(_storage, MAIL_ERROR_NOTFOUND,
+			T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
+	} else if (!mail_storage_set_error_from_errno(_storage)) {
 		mail_storage_set_critical(_storage, "stat(%s) failed: %m",
 					  path);
 	}
@@ -689,7 +688,7 @@
 static int mbox_mailbox_create(struct mail_storage *_storage, const char *name,
 			       bool directory)
 {
-	const char *path, *p, *error;
+	const char *path, *p;
 	struct stat st;
 	int fd;
 
@@ -698,17 +697,16 @@
 	path = mailbox_list_get_path(_storage->list, name,
 				     MAILBOX_LIST_PATH_TYPE_MAILBOX);
 	if (stat(path, &st) == 0) {
-		mail_storage_set_error(_storage, "Mailbox already exists");
+		mail_storage_set_error(_storage, MAIL_ERROR_NOTPOSSIBLE,
+				       "Mailbox already exists");
 		return -1;
 	}
 
 	if (errno != ENOENT) {
 		if (errno == ENOTDIR) {
-			mail_storage_set_error(_storage,
+			mail_storage_set_error(_storage, MAIL_ERROR_NOTPOSSIBLE,
 				"Mailbox doesn't allow inferior mailboxes");
-		} else if (mail_storage_errno2str(&error))
-			mail_storage_set_error(_storage, "%s", error);
-		else {
+		} else if (!mail_storage_set_error_from_errno(_storage)) {
 			mail_storage_set_critical(_storage,
 				"stat() failed for mbox file %s: %m", path);
 		}
@@ -720,9 +718,7 @@
 	if (p != NULL) {
 		p = t_strdup_until(path, p);
 		if (mkdir_parents(p, CREATE_MODE) < 0) {
-			if (mail_storage_errno2str(&error))
-				mail_storage_set_error(_storage, "%s", error);
-			else {
+			if (!mail_storage_set_error_from_errno(_storage)) {
 				mail_storage_set_critical(_storage,
 					"mkdir_parents(%s) failed: %m", p);
 			}
@@ -744,10 +740,9 @@
 
 	if (errno == EEXIST) {
 		/* mailbox was just created between stat() and open() call.. */
-		mail_storage_set_error(_storage, "Mailbox already exists");
-	} else if (mail_storage_errno2str(&error))
-		mail_storage_set_error(_storage, "%s", error);
-	else {
+		mail_storage_set_error(_storage, MAIL_ERROR_NOTPOSSIBLE,
+				       "Mailbox already exists");
+	} else if (!mail_storage_set_error_from_errno(_storage)) {
 		mail_storage_set_critical(_storage,
 			"Can't create mailbox %s: %m", name);
 	}
@@ -883,17 +878,15 @@
 {
 	struct mbox_storage *storage = MBOX_LIST_CONTEXT(list);
 	struct stat st;
-	const char *path, *index_dir, *error;
+	const char *path, *index_dir;
 
 	path = mailbox_list_get_path(list, name,
 				     MAILBOX_LIST_PATH_TYPE_MAILBOX);
 	if (lstat(path, &st) < 0) {
 		if (ENOTFOUND(errno)) {
-			mailbox_list_set_error(list, t_strdup_printf(
-				MAILBOX_LIST_ERR_MAILBOX_NOT_FOUND, name));
-		} else if (mail_storage_errno2str(&error))
-			mailbox_list_set_error(list, error);
-		else {
+			mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND,
+				T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
+		} else if (!mailbox_list_set_error_from_errno(list)) {
 			mailbox_list_set_critical(list,
 				"lstat() failed for %s: %m", path);
 		}
@@ -911,9 +904,7 @@
 
 		if (*index_dir != '\0' && rmdir(index_dir) < 0 &&
 		    !ENOTFOUND(errno) && errno != ENOTEMPTY) {
-			if (mail_storage_errno2str(&error))
-				mailbox_list_set_error(list, error);
-			else {
+			if (!mailbox_list_set_error_from_errno(list)) {
 				mailbox_list_set_critical(list,
 					"rmdir() failed for %s: %m", index_dir);
 			}
@@ -924,15 +915,13 @@
 			return 0;
 
 		if (ENOTFOUND(errno)) {
-			mailbox_list_set_error(list, t_strdup_printf(
-				MAILBOX_LIST_ERR_MAILBOX_NOT_FOUND, name));
+			mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND,
+				T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
 		} else if (errno == ENOTEMPTY) {
-			mailbox_list_set_error(list, t_strdup_printf(
-				"Directory %s isn't empty, can't delete it.",
-				name));
-		} else if (mail_storage_errno2str(&error))
-			mailbox_list_set_error(list, error);
-		else {
+			mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
+				t_strdup_printf("Directory %s isn't empty, "
+						"can't delete it.", name));
+		} else if (!mailbox_list_set_error_from_errno(list)) {
 			mailbox_list_set_critical(list,
 				"rmdir() failed for %s: %m", path);
 		}
@@ -946,11 +935,9 @@
 
 	if (unlink(path) < 0) {
 		if (ENOTFOUND(errno)) {
-			mailbox_list_set_error(list, t_strdup_printf(
-				MAILBOX_LIST_ERR_MAILBOX_NOT_FOUND, name));
-		} else if (mail_storage_errno2str(&error))
-			mailbox_list_set_error(list, error);
-		else {
+			mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND,
+				T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
+		} else if (!mailbox_list_set_error_from_errno(list)) {
 			mailbox_list_set_critical(list,
 				"unlink() failed for %s: %m", path);
 		}

Index: mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.210
retrieving revision 1.211
diff -u -d -r1.210 -r1.211
--- mbox-sync.c	17 Apr 2007 15:09:14 -0000	1.210
+++ mbox-sync.c	13 May 2007 17:10:55 -0000	1.211
@@ -946,6 +946,7 @@
 	if (seq == 0) {
 		if (istream_raw_mbox_seek(mbox->mbox_stream, 0) < 0) {
 			mail_storage_set_error(&mbox->storage->storage,
+				MAIL_ERROR_NOTPOSSIBLE,
 				"Mailbox isn't a valid mbox file");
 			return -1;
 		}



More information about the dovecot-cvs mailing list