annotate src/lib-storage/index/dbox/dbox-storage.c @ 6340:7b71ba1250e3 HEAD

Initial commit for dbox redesign/rewrite. Currently supports only one message per file mode.
author Timo Sirainen <tss@iki.fi>
date Sat, 01 Sep 2007 03:04:02 +0300
parents 0c9b6ff6fb0b
children 6a64e64fa3a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
1 /* Copyright (C) 2007 Timo Sirainen */
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
4 #include "array.h"
5176
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
5 #include "ioloop.h"
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
6 #include "str.h"
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "mkdir-parents.h"
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "unlink-directory.h"
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
9 #include "index-mail.h"
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "mail-copy.h"
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "dbox-sync.h"
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
12 #include "dbox-index.h"
4203
4141aae720fe Fixed memory leaks
Timo Sirainen <tss@iki.fi>
parents: 4196
diff changeset
13 #include "dbox-file.h"
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include "dbox-storage.h"
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 #include <stdio.h>
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include <stdlib.h>
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include <unistd.h>
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
19 #include <dirent.h>
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #include <sys/stat.h>
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 #define CREATE_MODE 0770 /* umask() should limit it more */
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
24 #define DBOX_LIST_CONTEXT(obj) \
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
25 MODULE_CONTEXT(obj, dbox_mailbox_list_module)
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
26
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 extern struct mail_storage dbox_storage;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 extern struct mailbox dbox_mailbox;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
30 static MODULE_CONTEXT_DEFINE_INIT(dbox_mailbox_list_module,
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
31 &mailbox_list_module_register);
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
32
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
33 static int
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
34 dbox_list_delete_mailbox(struct mailbox_list *list, const char *name);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
35 static int dbox_list_iter_is_mailbox(struct mailbox_list_iterate_context *ctx,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
36 const char *dir, const char *fname,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
37 enum mailbox_list_file_type type,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
38 enum mailbox_info_flags *flags);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
39
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
40 static int
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
41 dbox_get_list_settings(struct mailbox_list_settings *list_set,
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
42 const char *data, enum mail_storage_flags flags,
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
43 const char **error_r)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 {
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3845
diff changeset
45 bool debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
46 const char *p;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 size_t len;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
49 memset(list_set, 0, sizeof(*list_set));
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
50 list_set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME;
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
51 list_set->maildir_name = "";
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
53 if (data == NULL || *data == '\0' || *data == ':') {
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 /* we won't do any guessing for this format. */
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 if (debug)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 i_info("dbox: mailbox location not given");
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
57 *error_r = "Root mail directory not given";
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
58 return -1;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 /* <root dir> [:INDEX=<dir>] */
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 if (debug)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 i_info("dbox: data=%s", data);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 p = strchr(data, ':');
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 if (p == NULL)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
66 list_set->root_dir = data;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 else {
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
68 list_set->root_dir = t_strdup_until(data, p);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 do {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 p++;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 if (strncmp(p, "INDEX=", 6) == 0)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
73 list_set->index_dir = t_strcut(p+6, ':');
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 p = strchr(p, ':');
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 } while (p != NULL);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 /* strip trailing '/' */
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
79 len = strlen(list_set->root_dir);
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
80 if (len > 1 && list_set->root_dir[len-1] == '/')
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
81 list_set->root_dir = t_strndup(list_set->root_dir, len-1);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
83 if (list_set->index_dir != NULL &&
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
84 strcmp(list_set->index_dir, "MEMORY") == 0)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
85 list_set->index_dir = "";
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
86 return 0;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
87 }
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
89 static struct mail_storage *dbox_alloc(void)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
90 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
91 struct dbox_storage *storage;
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
92 pool_t pool;
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
93
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
94 pool = pool_alloconly_create("dbox storage", 512+256);
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
95 storage = p_new(pool, struct dbox_storage, 1);
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
96 storage->storage = dbox_storage;
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
97 storage->storage.pool = pool;
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
98
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
99 return &storage->storage;
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
100 }
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
101
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
102 static int dbox_create(struct mail_storage *_storage, const char *data,
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
103 const char **error_r)
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
104 {
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
105 struct dbox_storage *storage = (struct dbox_storage *)_storage;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
106 struct mailbox_list_settings list_set;
4859
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
107 struct stat st;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
109 if (dbox_get_list_settings(&list_set, data, _storage->flags,
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
110 error_r) < 0)
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
111 return -1;
5461
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
112 list_set.mail_storage_flags = &_storage->flags;
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
113 list_set.lock_method = &_storage->lock_method;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
114
5461
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
115 if ((_storage->flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) {
4859
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
116 if (stat(list_set.root_dir, &st) < 0) {
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
117 if (errno != ENOENT) {
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
118 *error_r = t_strdup_printf(
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
119 "stat(%s) failed: %m",
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
120 list_set.root_dir);
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
121 } else {
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
122 *error_r = t_strdup_printf(
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
123 "Root mail directory doesn't exist: %s",
4859
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
124 list_set.root_dir);
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
125 }
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
126 return -1;
4859
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
127 }
5499
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
128 } else {
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
129 if (mkdir_parents(list_set.root_dir, CREATE_MODE) < 0 &&
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
130 errno != EEXIST) {
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
131 *error_r = t_strdup_printf("mkdir(%s) failed: %m",
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
132 list_set.root_dir);
5499
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
133 return -1;
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
134 }
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
137 if (mailbox_list_alloc("fs", &_storage->list, error_r) < 0)
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
138 return -1;
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
139 storage->list_module_ctx.super = _storage->list->v;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
140 _storage->list->v.iter_is_mailbox = dbox_list_iter_is_mailbox;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
141 _storage->list->v.delete_mailbox = dbox_list_delete_mailbox;
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
142
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
143 MODULE_CONTEXT_SET_FULL(_storage->list, dbox_mailbox_list_module,
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
144 storage, &storage->list_module_ctx);
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
145
6256
0c9b6ff6fb0b Split mailbox_list_init() to _alloc() and _init(). _init() is called only
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
146 /* finish list init after we've overridden vfuncs */
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
147 mailbox_list_init(_storage->list, _storage->ns, &list_set,
6256
0c9b6ff6fb0b Split mailbox_list_init() to _alloc() and _init(). _init() is called only
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
148 mail_storage_get_list_flags(_storage->flags));
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
149 return 0;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
152 static int create_dbox(struct mail_storage *storage, const char *path)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 if (mkdir_parents(path, CREATE_MODE) < 0 && errno != EEXIST) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
155 if (!mail_storage_set_error_from_errno(storage)) {
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
156 mail_storage_set_critical(storage,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
157 "mkdir(%s) failed: %m", path);
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
158 }
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 return 0;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 static struct mailbox *
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 dbox_open(struct dbox_storage *storage, const char *name,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 enum mailbox_open_flags flags)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 {
5459
78eaf595359c Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
168 struct mail_storage *_storage = &storage->storage;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 struct dbox_mailbox *mbox;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 struct mail_index *index;
5618
5ea33dbddbae Moved index directory creation code to index_storage_alloc().
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
171 const char *path, *value;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 pool_t pool;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
174 path = mailbox_list_get_path(_storage->list, name,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
175 MAILBOX_LIST_PATH_TYPE_MAILBOX);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
176 if (create_dbox(_storage, path) < 0)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 return NULL;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178
5618
5ea33dbddbae Moved index directory creation code to index_storage_alloc().
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
179 index = index_storage_alloc(_storage, name, flags, DBOX_INDEX_PREFIX);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180
5024
a8a274b4c87c Use larger default pool sizes
Timo Sirainen <tss@iki.fi>
parents: 4999
diff changeset
181 pool = pool_alloconly_create("dbox mailbox", 1024+512);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182 mbox = p_new(pool, struct dbox_mailbox, 1);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 mbox->ibox.box = dbox_mailbox;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 mbox->ibox.box.pool = pool;
5459
78eaf595359c Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
185 mbox->ibox.storage = &storage->storage;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186 mbox->ibox.mail_vfuncs = &dbox_mail_vfuncs;
5179
2f9ac504ee77 When using KEEP_LOCK, the mbox/uidlist file must be locked before index file
Timo Sirainen <tss@iki.fi>
parents: 5177
diff changeset
187 mbox->ibox.index = index;
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
188 mbox->path = p_strdup(pool, path);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
189 mbox->storage = storage;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
190 mbox->last_interactive_change = ioloop_time;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191
3813
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
192 value = getenv("DBOX_ROTATE_SIZE");
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
193 if (value != NULL)
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
194 mbox->rotate_size = (uoff_t)strtoul(value, NULL, 10) * 1024;
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
195 else
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
196 mbox->rotate_size = DBOX_DEFAULT_ROTATE_SIZE;
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
197 mbox->rotate_size = 0; /* FIXME: currently anything else doesn't work */
3845
18a786df5815 Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents: 3813
diff changeset
198 value = getenv("DBOX_ROTATE_MIN_SIZE");
18a786df5815 Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents: 3813
diff changeset
199 if (value != NULL)
18a786df5815 Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents: 3813
diff changeset
200 mbox->rotate_min_size = (uoff_t)strtoul(value, NULL, 10) * 1024;
18a786df5815 Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents: 3813
diff changeset
201 else
18a786df5815 Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents: 3813
diff changeset
202 mbox->rotate_min_size = DBOX_DEFAULT_ROTATE_MIN_SIZE;
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
203 if (mbox->rotate_min_size > mbox->rotate_size)
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
204 mbox->rotate_min_size = mbox->rotate_size;
3813
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
205 value = getenv("DBOX_ROTATE_DAYS");
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
206 if (value != NULL)
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
207 mbox->rotate_days = (unsigned int)strtoul(value, NULL, 10);
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
208 else
4177
4eaaef28cc38 dbox settings in config file didn't work, and the defaults were also a bit
Timo Sirainen <tss@iki.fi>
parents: 4172
diff changeset
209 mbox->rotate_days = DBOX_DEFAULT_ROTATE_DAYS;
3813
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
210
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
211 value = getenv("DBOX_MAX_OPEN_FILES");
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
212 if (value != NULL)
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
213 mbox->max_open_files = (unsigned int)strtoul(value, NULL, 10);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
214 else
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
215 mbox->max_open_files = DBOX_DEFAULT_MAX_OPEN_FILES;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
216 i_array_init(&mbox->open_files, I_MIN(mbox->max_open_files, 128));
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
218 mbox->dbox_ext_id =
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
219 mail_index_ext_register(index, "dbox", 0,
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
220 sizeof(struct dbox_mail_index_record),
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
221 sizeof(uint32_t));
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
222 mbox->dbox_hdr_ext_id =
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
223 mail_index_ext_register(index, "dbox-hdr",
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
224 sizeof(struct dbox_index_header), 0, 0);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
225 mbox->dbox_index = dbox_index_init(mbox);
5179
2f9ac504ee77 When using KEEP_LOCK, the mbox/uidlist file must be locked before index file
Timo Sirainen <tss@iki.fi>
parents: 5177
diff changeset
226
2f9ac504ee77 When using KEEP_LOCK, the mbox/uidlist file must be locked before index file
Timo Sirainen <tss@iki.fi>
parents: 5177
diff changeset
227 index_storage_mailbox_init(&mbox->ibox, name, flags, FALSE);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
228 return &mbox->ibox.box;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
229 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 static struct mailbox *
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232 dbox_mailbox_open(struct mail_storage *_storage, const char *name,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233 struct istream *input, enum mailbox_open_flags flags)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235 struct dbox_storage *storage = (struct dbox_storage *)_storage;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 const char *path;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237 struct stat st;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
238
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 if (input != NULL) {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
240 mail_storage_set_critical(_storage,
4029
9bdd186d7b7d s/Maildir/dbox/
Timo Sirainen <tss@iki.fi>
parents: 4028
diff changeset
241 "dbox doesn't support streamed mailboxes");
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
242 return NULL;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
243 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
244
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245 if (strcmp(name, "INBOX") == 0)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
246 return dbox_open(storage, "INBOX", flags);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
247
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
248 path = mailbox_list_get_path(_storage->list, name,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
249 MAILBOX_LIST_PATH_TYPE_MAILBOX);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 if (stat(path, &st) == 0) {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
251 return dbox_open(storage, name, flags);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252 } else if (errno == ENOENT) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
253 mail_storage_set_error(_storage, MAIL_ERROR_NOTFOUND,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
254 T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
255 return NULL;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256 } else {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257 mail_storage_set_critical(_storage, "stat(%s) failed: %m",
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
258 path);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
259 return NULL;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
260 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
261 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
262
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
263 static int dbox_storage_mailbox_close(struct mailbox *box)
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
264 {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
265 struct dbox_mailbox *mbox = (struct dbox_mailbox *)box;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
266 int ret;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
267
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
268 ret = dbox_sync(mbox, TRUE);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
269
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
270 dbox_index_deinit(&mbox->dbox_index);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
271 dbox_files_free(mbox);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
272 array_free(&mbox->open_files);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
273
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
274 return index_storage_mailbox_close(box) < 0 ? -1 : ret;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
275 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
276
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 static int dbox_mailbox_create(struct mail_storage *_storage,
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
278 const char *name, bool directory __attr_unused__)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
279 {
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
280 const char *path;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281 struct stat st;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
283 path = mailbox_list_get_path(_storage->list, name,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
284 MAILBOX_LIST_PATH_TYPE_MAILBOX);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
285 if (stat(path, &st) == 0) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
286 mail_storage_set_error(_storage, MAIL_ERROR_NOTPOSSIBLE,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
287 "Mailbox already exists");
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
288 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
290
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
291 return create_dbox(_storage, path);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
293
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
294 static int
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
295 dbox_delete_nonrecursive(struct mailbox_list *list, const char *path,
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
296 const char *name)
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
297 {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
298 DIR *dir;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
299 struct dirent *d;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
300 string_t *full_path;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
301 unsigned int dir_len;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
302 bool unlinked_something = FALSE;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
303
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
304 dir = opendir(path);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
305 if (dir == NULL) {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
306 if (!mailbox_list_set_error_from_errno(list)) {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
307 mailbox_list_set_critical(list,
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
308 "opendir(%s) failed: %m", path);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
309 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
310 return -1;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
311 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
312
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
313 full_path = t_str_new(256);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
314 str_append(full_path, path);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
315 str_append_c(full_path, '/');
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
316 dir_len = str_len(full_path);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
317
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
318 errno = 0;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
319 while ((d = readdir(dir)) != NULL) {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
320 if (d->d_name[0] == '.') {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
321 /* skip . and .. */
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
322 if (d->d_name[1] == '\0')
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
323 continue;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
324 if (d->d_name[1] == '.' && d->d_name[2] == '\0')
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
325 continue;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
326 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
327
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
328 str_truncate(full_path, dir_len);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
329 str_append(full_path, d->d_name);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
330
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
331 /* trying to unlink() a directory gives either EPERM or EISDIR
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
332 (non-POSIX). it doesn't really work anywhere in practise,
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
333 so don't bother stat()ing the file first */
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
334 if (unlink(str_c(full_path)) == 0)
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
335 unlinked_something = TRUE;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
336 else if (errno != ENOENT && errno != EISDIR && errno != EPERM) {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
337 mailbox_list_set_critical(list,
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
338 "unlink_directory(%s) failed: %m",
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
339 str_c(full_path));
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
340 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
341 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
342
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
343 if (closedir(dir) < 0) {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
344 mailbox_list_set_critical(list, "closedir(%s) failed: %m",
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
345 path);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
346 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
347
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
348 if (rmdir(path) == 0)
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
349 unlinked_something = TRUE;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
350 else if (errno != ENOENT && errno != ENOTEMPTY) {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
351 mailbox_list_set_critical(list, "rmdir(%s) failed: %m", path);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
352 return -1;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
353 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
354
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
355 if (!unlinked_something) {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
356 mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
357 t_strdup_printf("Directory %s isn't empty, "
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
358 "can't delete it.", name));
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
359 return -1;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
360 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
361 return 0;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
362 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
363
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
364 static int
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
365 dbox_list_delete_mailbox(struct mailbox_list *list, const char *name)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
366 {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
367 struct dbox_storage *storage = DBOX_LIST_CONTEXT(list);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
368 struct stat st;
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
369 const char *src;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
370
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
371 /* Make sure the indexes are closed before trying to delete the
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
372 directory that contains them. It can still fail with some NFS
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
373 implementations if indexes are opened by another session, but
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
374 that can't really be helped. */
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
375 index_storage_destroy_unrefed();
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
376
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
377 /* delete the index and control directories */
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
378 if (storage->list_module_ctx.super.delete_mailbox(list, name) < 0)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
379 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
381 /* check if the mailbox actually exists */
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
382 src = mailbox_list_get_path(list, name, MAILBOX_LIST_PATH_TYPE_MAILBOX);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
383 if (stat(src, &st) != 0 && errno == ENOENT) {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
384 mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND,
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
385 T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
386 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
388
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
389 return dbox_delete_nonrecursive(list, src, name);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
390 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
391
5465
014236cf3dcc Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents: 5464
diff changeset
392 static void dbox_notify_changes(struct mailbox *box)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
393 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
394 struct dbox_mailbox *mbox = (struct dbox_mailbox *)box;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
395
5465
014236cf3dcc Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents: 5464
diff changeset
396 if (box->notify_callback == NULL)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 index_mailbox_check_remove_all(&mbox->ibox);
5465
014236cf3dcc Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents: 5464
diff changeset
398 else
014236cf3dcc Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents: 5464
diff changeset
399 index_mailbox_check_add(&mbox->ibox, mbox->path);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
400 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
401
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
402 static int dbox_list_iter_is_mailbox(struct mailbox_list_iterate_context *ctx
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
403 __attr_unused__,
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
404 const char *dir, const char *fname,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
405 enum mailbox_list_file_type type,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
406 enum mailbox_info_flags *flags)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
407 {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
408 const char *mail_path;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
409 struct stat st;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
410 int ret = 1;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
411
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
412 /* try to avoid stat() with these checks */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
413 if (type != MAILBOX_LIST_FILE_TYPE_DIR &&
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
414 type != MAILBOX_LIST_FILE_TYPE_SYMLINK &&
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
415 type != MAILBOX_LIST_FILE_TYPE_UNKNOWN) {
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
416 /* it's a file */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
417 *flags |= MAILBOX_NOSELECT | MAILBOX_NOINFERIORS;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
418 return 0;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
419 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
420
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
421 /* need to stat() then */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
422 t_push();
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
423 mail_path = t_strconcat(dir, "/", fname, NULL);
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
424
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
425 if (stat(mail_path, &st) == 0) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
426 if (!S_ISDIR(st.st_mode)) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
427 /* non-directory */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
428 *flags |= MAILBOX_NOSELECT | MAILBOX_NOINFERIORS;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
429 ret = 0;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
430 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
431 } else {
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
432 /* non-selectable. probably either access denied, or symlink
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
433 destination not found. don't bother logging errors. */
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
434 *flags |= MAILBOX_NOSELECT;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
435 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
436 t_pop();
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
437
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
438 return ret;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
439 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
440
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
441 static void dbox_class_init(void)
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
442 {
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
443 dbox_transaction_class_init();
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
444 }
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
445
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
446 static void dbox_class_deinit(void)
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
447 {
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
448 dbox_transaction_class_deinit();
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
449 }
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
450
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451 struct mail_storage dbox_storage = {
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
452 MEMBER(name) DBOX_STORAGE_NAME,
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
453 MEMBER(mailbox_is_file) FALSE,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
454
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
455 {
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
456 dbox_class_init,
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
457 dbox_class_deinit,
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
458 dbox_alloc,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459 dbox_create,
5462
163b48489bc6 Moved all storage destruction code to mail-storage.c and made destroy()
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
460 NULL,
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
461 NULL,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
462 dbox_mailbox_open,
5468
8e58322ef87e Removed virtual mail_storage.get_last_error(). The implementation is always
Timo Sirainen <tss@iki.fi>
parents: 5466
diff changeset
463 dbox_mailbox_create
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
464 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465 };
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467 struct mailbox dbox_mailbox = {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468 MEMBER(name) NULL,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
469 MEMBER(storage) NULL,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
470
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
471 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
472 index_storage_is_readonly,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 index_storage_allow_new_keywords,
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
474 dbox_storage_mailbox_close,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475 index_storage_get_status,
6062
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
476 NULL,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
477 NULL,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
478 dbox_storage_sync_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479 index_mailbox_sync_next,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480 index_mailbox_sync_deinit,
5562
24b751bc0995 Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
481 NULL,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
482 dbox_notify_changes,
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
483 index_transaction_begin,
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
484 index_transaction_commit,
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
485 index_transaction_rollback,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
486 index_keywords_create,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
487 index_keywords_free,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
488 index_storage_get_uids,
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
489 dbox_mail_alloc,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
490 index_header_lookup_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
491 index_header_lookup_deinit,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
492 index_storage_search_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
493 index_storage_search_deinit,
4939
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4894
diff changeset
494 index_storage_search_next_nonblock,
4196
6ac0d63b297f Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents: 4177
diff changeset
495 index_storage_search_next_update_seq,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
496 dbox_save_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
497 dbox_save_continue,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
498 dbox_save_finish,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
499 dbox_save_cancel,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
500 mail_storage_copy,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
501 index_storage_is_inconsistent
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
502 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
503 };