Mercurial > dovecot > core-2.2
annotate src/lib-storage/index/dbox-common/dbox-storage.c @ 15159:a14f1d2e2b45
lib-storage: Added ALTNOCHECK option to mail_location.
By default Dovecot verifies that $rootdir/dbox-alt-root symlink matches the
ALT directory location, and logs an error if not. This is mainly to avoid
accidents during initial configuration when for example alt dir was set in
global mail_location but was forgotten to be set in userdb reply's
mail_location. The ALTNOCHECK setting simply doesn't check or create this
symlink, giving a (very) small performance improvement.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 24 Sep 2012 14:42:38 +0300 |
parents | 370e1f945c01 |
children | e3175ee39483 75aadea5c2a2 |
rev | line source |
---|---|
14133
ba770cba5598
Updated copyright notices to include year 2012.
Timo Sirainen <tss@iki.fi>
parents:
14046
diff
changeset
|
1 /* Copyright (c) 2007-2012 Dovecot authors, see the included COPYING file */ |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "ioloop.h" |
12312
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
5 #include "fs-api.h" |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "mkdir-parents.h" |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "unlink-old-files.h" |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "mailbox-uidvalidity.h" |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "mailbox-list-private.h" |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "index-storage.h" |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "dbox-storage.h" |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include <stdio.h> |
11652
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
14 #include <dirent.h> |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
15 #include <unistd.h> |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 void dbox_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED, |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 struct mailbox_list_settings *set) |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 { |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 if (set->layout == NULL) |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 set->layout = MAILBOX_LIST_NAME_FS; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 if (set->subscription_fname == NULL) |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME; |
14046
db8c1dde0b41
lib-storage: And another fix to previous maildir_name/mailbox_dir_name changes.
Timo Sirainen <tss@iki.fi>
parents:
13509
diff
changeset
|
24 if (*set->maildir_name == '\0') |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 set->maildir_name = DBOX_MAILDIR_NAME; |
14046
db8c1dde0b41
lib-storage: And another fix to previous maildir_name/mailbox_dir_name changes.
Timo Sirainen <tss@iki.fi>
parents:
13509
diff
changeset
|
26 if (*set->mailbox_dir_name == '\0') |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 set->mailbox_dir_name = DBOX_MAILBOX_DIR_NAME; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
30 static bool |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
31 dbox_alt_path_has_changed(const char *root_dir, |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
32 const char *alt_path, const char *alt_symlink_path) |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
33 { |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
34 char buf[PATH_MAX]; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
35 ssize_t ret; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
36 |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
37 ret = readlink(alt_symlink_path, buf, sizeof(buf)-1); |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
38 if (ret < 0) { |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
39 if (errno == ENOENT) |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
40 return alt_path != NULL; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
41 i_error("readlink(%s) failed: %m", alt_symlink_path); |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
42 return FALSE; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
43 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
44 buf[ret] = '\0'; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
45 |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
46 if (alt_path == NULL) { |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
47 i_warning("dbox %s: Original ALT=%s, " |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
48 "but currently no ALT path set", root_dir, buf); |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
49 return TRUE; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
50 } else if (strcmp(buf, alt_path) != 0) { |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
51 i_warning("dbox %s: Original ALT=%s, " |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
52 "but currently ALT=%s", root_dir, buf, alt_path); |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
53 return TRUE; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
54 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
55 return FALSE; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
56 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
57 |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
58 static void dbox_verify_alt_path(struct mailbox_list *list) |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
59 { |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
60 const char *root_dir, *alt_symlink_path, *alt_path; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
61 |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
62 root_dir = mailbox_list_get_path(list, NULL, |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
63 MAILBOX_LIST_PATH_TYPE_DIR); |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
64 alt_symlink_path = |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
65 t_strconcat(root_dir, "/"DBOX_ALT_SYMLINK_NAME, NULL); |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
66 alt_path = mailbox_list_get_path(list, NULL, |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
67 MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX); |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
68 if (!dbox_alt_path_has_changed(root_dir, alt_path, alt_symlink_path)) |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
69 return; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
70 |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
71 /* unlink/create the current alt path symlink */ |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
72 if (unlink(alt_symlink_path) < 0 && errno != ENOENT) |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
73 i_error("unlink(%s) failed: %m", alt_symlink_path); |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
74 if (alt_path != NULL) { |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
75 if (symlink(alt_path, alt_symlink_path) < 0 && |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
76 errno != EEXIST) { |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
77 i_error("symlink(%s, %s) failed: %m", |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
78 alt_path, alt_symlink_path); |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
79 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
80 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
81 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
82 |
12312
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
83 int dbox_storage_create(struct mail_storage *_storage, |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
84 struct mail_namespace *ns, |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
85 const char **error_r ATTR_UNUSED) |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
86 { |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
87 struct dbox_storage *storage = (struct dbox_storage *)_storage; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
88 const struct mail_storage_settings *set = _storage->set; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
89 struct fs_settings fs_set; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
90 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
91 memset(&fs_set, 0, sizeof(fs_set)); |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
92 fs_set.temp_file_prefix = mailbox_list_get_global_temp_prefix(ns->list); |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
93 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
94 if (*set->mail_attachment_fs != '\0') T_BEGIN { |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
95 const char *name, *args, *dir; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
96 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
97 args = strchr(set->mail_attachment_fs, ' '); |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
98 if (args == NULL) { |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
99 name = set->mail_attachment_fs; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
100 args = ""; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
101 } else { |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
102 name = t_strdup_until(set->mail_attachment_fs, args++); |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
103 } |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
104 dir = mail_user_home_expand(_storage->user, |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
105 set->mail_attachment_dir); |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
106 storage->attachment_dir = p_strdup(_storage->pool, dir); |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
107 storage->attachment_fs = fs_init(name, args, &fs_set); |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
108 } T_END; |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
109 |
15159
a14f1d2e2b45
lib-storage: Added ALTNOCHECK option to mail_location.
Timo Sirainen <tss@iki.fi>
parents:
14379
diff
changeset
|
110 if (!ns->list->set.alt_dir_nocheck) |
a14f1d2e2b45
lib-storage: Added ALTNOCHECK option to mail_location.
Timo Sirainen <tss@iki.fi>
parents:
14379
diff
changeset
|
111 dbox_verify_alt_path(ns->list); |
12312
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
112 return 0; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
113 } |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
114 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
115 void dbox_storage_destroy(struct mail_storage *_storage) |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
116 { |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
117 struct dbox_storage *storage = (struct dbox_storage *)_storage; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
118 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
119 if (storage->attachment_fs != NULL) |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
120 fs_deinit(&storage->attachment_fs); |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
121 } |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
122 |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 uint32_t dbox_get_uidvalidity_next(struct mailbox_list *list) |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 { |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 const char *path; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 path = mailbox_list_get_path(list, NULL, |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 MAILBOX_LIST_PATH_TYPE_CONTROL); |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 path = t_strconcat(path, "/"DBOX_UIDVALIDITY_FILE_NAME, NULL); |
10475
7f2e9c793af8
dovecot-uidvalidity*: Create files with correct permission.
Timo Sirainen <tss@iki.fi>
parents:
10254
diff
changeset
|
130 return mailbox_uidvalidity_next(list, path); |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 void dbox_notify_changes(struct mailbox *box) |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 { |
10254
ea4a80ee0283
dbox notify: Look for dbox index files from index dir, not mail root dir.
Timo Sirainen <tss@iki.fi>
parents:
9977
diff
changeset
|
135 const char *dir, *path; |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 if (box->notify_callback == NULL) |
10660
56b1d4dd9c7d
lib-storage: *_mailboxes don't descend from index_mailbox anymore, it's now a context.
Timo Sirainen <tss@iki.fi>
parents:
10653
diff
changeset
|
138 index_mailbox_check_remove_all(box); |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 else { |
10254
ea4a80ee0283
dbox notify: Look for dbox index files from index dir, not mail root dir.
Timo Sirainen <tss@iki.fi>
parents:
9977
diff
changeset
|
140 dir = mailbox_list_get_path(box->list, box->name, |
ea4a80ee0283
dbox notify: Look for dbox index files from index dir, not mail root dir.
Timo Sirainen <tss@iki.fi>
parents:
9977
diff
changeset
|
141 MAILBOX_LIST_PATH_TYPE_INDEX); |
ea4a80ee0283
dbox notify: Look for dbox index files from index dir, not mail root dir.
Timo Sirainen <tss@iki.fi>
parents:
9977
diff
changeset
|
142 path = t_strdup_printf("%s/"DBOX_INDEX_PREFIX".log", dir); |
10660
56b1d4dd9c7d
lib-storage: *_mailboxes don't descend from index_mailbox anymore, it's now a context.
Timo Sirainen <tss@iki.fi>
parents:
10653
diff
changeset
|
143 index_mailbox_check_add(box, path); |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 static bool |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 dbox_cleanup_if_exists(struct mailbox_list *list, const char *path) |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 { |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 struct stat st; |
14379
370e1f945c01
Added mail_temp_scan_interval setting and changed its default from 8h -> 1w.
Timo Sirainen <tss@iki.fi>
parents:
14332
diff
changeset
|
151 unsigned int interval = list->mail_set->mail_temp_scan_interval; |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 if (stat(path, &st) < 0) |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 return FALSE; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 /* check once in a while if there are temp files to clean up */ |
14379
370e1f945c01
Added mail_temp_scan_interval setting and changed its default from 8h -> 1w.
Timo Sirainen <tss@iki.fi>
parents:
14332
diff
changeset
|
157 if (interval == 0) { |
370e1f945c01
Added mail_temp_scan_interval setting and changed its default from 8h -> 1w.
Timo Sirainen <tss@iki.fi>
parents:
14332
diff
changeset
|
158 /* disabled */ |
370e1f945c01
Added mail_temp_scan_interval setting and changed its default from 8h -> 1w.
Timo Sirainen <tss@iki.fi>
parents:
14332
diff
changeset
|
159 } else if (st.st_atime > st.st_ctime + DBOX_TMP_DELETE_SECS) { |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 /* there haven't been any changes to this directory since we |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 last checked it. */ |
14379
370e1f945c01
Added mail_temp_scan_interval setting and changed its default from 8h -> 1w.
Timo Sirainen <tss@iki.fi>
parents:
14332
diff
changeset
|
162 } else if (st.st_atime < ioloop_time - interval) { |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 /* time to scan */ |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 const char *prefix = |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 mailbox_list_get_global_temp_prefix(list); |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 (void)unlink_old_files(path, prefix, |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 ioloop_time - DBOX_TMP_DELETE_SECS); |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 return TRUE; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 int dbox_mailbox_open(struct mailbox *box) |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 { |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12387
diff
changeset
|
175 const char *box_path = mailbox_get_path(box); |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12387
diff
changeset
|
176 |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
177 if (dbox_cleanup_if_exists(box->list, box_path)) |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
178 ; |
14332
37d6dd0f053b
lib-storage: Don't log errors if trying to open a mailbox with too long name.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
179 else if (errno == ENOENT || errno == ENAMETOOLONG) { |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
180 mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND, |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 T_MAIL_ERR_MAILBOX_NOT_FOUND(box->name)); |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
182 return -1; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 } else if (errno == EACCES) { |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 mail_storage_set_critical(box->storage, "%s", |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12387
diff
changeset
|
185 mail_error_eacces_msg("stat", box_path)); |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 return -1; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 } else { |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 mail_storage_set_critical(box->storage, |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12387
diff
changeset
|
189 "stat(%s) failed: %m", box_path); |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 return -1; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 } |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
192 |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
193 if (index_storage_mailbox_open(box, FALSE) < 0) |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
194 return -1; |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
195 mail_index_set_fsync_mode(box->index, |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
196 box->storage->set->parsed_fsync_mode, |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
197 MAIL_INDEX_SYNC_TYPE_APPEND | |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
198 MAIL_INDEX_SYNC_TYPE_EXPUNGE); |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
199 return 0; |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 |
11652
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
202 static int dir_is_empty(struct mail_storage *storage, const char *path) |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
203 { |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
204 DIR *dir; |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
205 struct dirent *d; |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
206 int ret = 1; |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
207 |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
208 dir = opendir(path); |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
209 if (dir == NULL) { |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
210 if (errno == ENOENT) { |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
211 /* race condition with DELETE/RENAME? */ |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
212 return 1; |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
213 } |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
214 mail_storage_set_critical(storage, "opendir(%s) failed: %m", |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
215 path); |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
216 return -1; |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
217 } |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
218 while ((d = readdir(dir)) != NULL) { |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
219 if (*d->d_name == '.') |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
220 continue; |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
221 |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
222 ret = 0; |
12387
ed94f6d615ef
dbox: Minor optimization when creating a mailbox when its alt dir already existed.
Timo Sirainen <tss@iki.fi>
parents:
12312
diff
changeset
|
223 break; |
11652
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
224 } |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
225 if (closedir(dir) < 0) { |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
226 mail_storage_set_critical(storage, "closedir(%s) failed: %m", |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
227 path); |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
228 ret = -1; |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
229 } |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
230 return ret; |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
231 } |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
232 |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 int dbox_mailbox_create(struct mailbox *box, |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 const struct mailbox_update *update, bool directory) |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
235 { |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10652
diff
changeset
|
236 struct dbox_storage *storage = (struct dbox_storage *)box->storage; |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
237 struct mail_index_sync_ctx *sync_ctx; |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
238 struct mail_index_view *view; |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
239 struct mail_index_transaction *trans; |
11652
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
240 const char *alt_path; |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
241 struct stat st; |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
242 int ret; |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10652
diff
changeset
|
244 if (directory && |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10652
diff
changeset
|
245 (box->list->props & MAILBOX_LIST_PROP_NO_NOSELECT) == 0) |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10652
diff
changeset
|
246 return 0; |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 |
12710
42ca32299617
dbox: mailbox_create/update() might not have updated index header correctly.
Timo Sirainen <tss@iki.fi>
parents:
12387
diff
changeset
|
248 if (mailbox_open(box) < 0) |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 return -1; |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
250 |
11652
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
251 /* if alt path already exists and contains files, rebuild storage so |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
252 that we don't start overwriting files. */ |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
253 alt_path = mailbox_list_get_path(box->list, box->name, |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
254 MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX); |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
255 if (alt_path != NULL && stat(alt_path, &st) == 0) { |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
256 ret = dir_is_empty(box->storage, alt_path); |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
257 if (ret < 0) |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
258 return -1; |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
259 if (ret == 0) { |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
260 mail_storage_set_critical(&storage->storage, |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
261 "Mailbox %s has existing files in alt path, " |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
262 "rebuilding storage to avoid losing messages", |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
263 box->vname); |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
264 storage->v.set_mailbox_corrupted(box); |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
265 return -1; |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
266 } |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
267 /* dir is empty, ignore it */ |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
268 } |
ad122febbf26
[m]dbox: If alt-dir exists for a mailbox while trying to create it, rebuild mailbox indexes.
Timo Sirainen <tss@iki.fi>
parents:
11484
diff
changeset
|
269 |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
270 /* use syncing as a lock */ |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
271 ret = mail_index_sync_begin(box->index, &sync_ctx, &view, &trans, 0); |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
272 if (ret <= 0) { |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
273 i_assert(ret != 0); |
13474
1903d5fd7e76
lib-storage: Minor error handling cleanups.
Timo Sirainen <tss@iki.fi>
parents:
12822
diff
changeset
|
274 mail_storage_set_index_error(box); |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 return -1; |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
276 } |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
277 |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
278 if (mail_index_get_header(view)->uid_validity == 0) { |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
279 if (storage->v.mailbox_create_indexes(box, update, trans) < 0) { |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
280 mail_index_sync_rollback(&sync_ctx); |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
281 return -1; |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
282 } |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
283 } |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
284 |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
285 return mail_index_sync_commit(&sync_ctx); |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
286 } |