[dovecot-cvs] dovecot/src/lib-storage mail-storage-private.h, 1.45, 1.46 mail-storage.c, 1.72, 1.73

tss at dovecot.org tss at dovecot.org
Fri Mar 30 15:58:52 EEST 2007


Update of /var/lib/cvs/dovecot/src/lib-storage
In directory talvi:/tmp/cvs-serv18585

Modified Files:
	mail-storage-private.h mail-storage.c 
Log Message:
Added virtual mail_storage.alloc() function and changed create() to work
differently.



Index: mail-storage-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mail-storage-private.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- mail-storage-private.h	30 Mar 2007 12:44:01 -0000	1.45
+++ mail-storage-private.h	30 Mar 2007 12:58:50 -0000	1.46
@@ -23,10 +23,11 @@
 	void (*class_init)(void);
 	void (*class_deinit)(void);
 
-	struct mail_storage *
-		(*create)(const char *data, const char *user,
-			  enum mail_storage_flags flags,
-			  enum file_lock_method lock_method);
+	struct mail_storage *(*alloc)(void);
+	int (*create)(struct mail_storage *storage,
+		      const char *data, const char *user,
+		      enum mail_storage_flags flags,
+		      enum file_lock_method lock_method);
 	void (*destroy)(struct mail_storage *storage);
 
 	bool (*autodetect)(const char *data, enum mail_storage_flags flags);

Index: mail-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mail-storage.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- mail-storage.c	29 Mar 2007 11:51:22 -0000	1.72
+++ mail-storage.c	30 Mar 2007 12:58:50 -0000	1.73
@@ -119,14 +119,20 @@
 		    enum mail_storage_flags flags,
 		    enum file_lock_method lock_method)
 {
-	struct mail_storage *storage;
+	struct mail_storage *storage_class, *storage;
 
-	storage = mail_storage_find(driver);
-	if (storage == NULL)
+	storage_class = mail_storage_find(driver);
+	if (storage_class == NULL)
 		return NULL;
 
-	storage = storage->v.create(data, user, flags, lock_method);
-	if (hook_mail_storage_created != NULL && storage != NULL)
+	storage = storage_class->v.alloc();
+	if (storage_class->v.create(storage, data, user,
+				    flags, lock_method) < 0) {
+		pool_unref(storage->pool);
+		return NULL;
+	}
+
+	if (hook_mail_storage_created != NULL)
 		hook_mail_storage_created(storage);
 	return storage;
 }
@@ -141,8 +147,11 @@
 
 	classes = array_get(&storages, &count);
 	for (i = 0; i < count; i++) {
-		storage = classes[i]->v.create(NULL, user, flags, lock_method);
-		if (storage != NULL) {
+		storage = classes[i]->v.alloc();
+		if (classes[i]->v.create(storage, NULL, user,
+					 flags, lock_method) < 0)
+			pool_unref(storage->pool);
+		else {
 			if (hook_mail_storage_created != NULL)
 				hook_mail_storage_created(storage);
 			return storage;
@@ -170,7 +179,7 @@
 			      enum mail_storage_flags flags,
 			      enum file_lock_method lock_method)
 {
-	struct mail_storage *storage;
+	struct mail_storage *storage_class, *storage;
 	const char *p, *name;
 
 	if (data == NULL || *data == '\0')
@@ -189,15 +198,20 @@
 		return mail_storage_create(name, p+1, user, flags, lock_method);
 	}
 
-	storage = mail_storage_autodetect(data, flags);
-	if (storage == NULL) {
+	storage_class = mail_storage_autodetect(data, flags);
+	if (storage_class == NULL) {
 		i_error("Ambiguous mail location setting, "
 			"don't know what to do with it: %s "
 			"(try prefixing it with mbox: or maildir:)",
 			data);
+		storage = NULL;
 	} else {
-		storage = storage->v.create(data, user, flags,
-					    lock_method);
+		storage = storage_class->v.alloc();
+		if (storage_class->v.create(storage, data, user,
+					    flags, lock_method) < 0) {
+			pool_unref(storage->pool);
+			storage = NULL;
+		}
 	}
 
 	if (hook_mail_storage_created != NULL && storage != NULL)



More information about the dovecot-cvs mailing list