Mercurial > dovecot > core-2.2
annotate src/lib-storage/index/dbox-common/dbox-storage.c @ 15080:e708a1d691d3
Compiler warning fixes for 32bit systems.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 16 Sep 2012 16:12:03 +0300 |
parents | 0efc12f3eb2a |
children | 8f4ce0932777 |
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 |
14629
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14379
diff
changeset
|
62 root_dir = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_DIR); |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
63 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
|
64 t_strconcat(root_dir, "/"DBOX_ALT_SYMLINK_NAME, NULL); |
14629
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14379
diff
changeset
|
65 alt_path = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX); |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
66 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
|
67 return; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
68 |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
69 /* 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 errno != EEXIST) { |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
75 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
|
76 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
|
77 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
78 } |
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 |
12312
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 { |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
89 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
|
90 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
|
91 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
92 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
|
93 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
|
94 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 args = ""; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
99 } else { |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
100 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
|
101 } |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 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
|
106 } 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
|
107 |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
108 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
|
109 return 0; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
110 } |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
111 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
112 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
|
113 { |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
114 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
|
115 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
116 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
|
117 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
|
118 } |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
119 |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 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
|
121 { |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 const char *path; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 |
14629
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14379
diff
changeset
|
124 path = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_CONTROL); |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 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
|
126 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
|
127 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 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
|
130 { |
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
|
131 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
|
132 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 static bool |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 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
|
145 { |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 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
|
147 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
|
148 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 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
|
150 return FALSE; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 /* 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
|
153 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
|
154 /* disabled */ |
370e1f945c01
Added mail_temp_scan_interval setting and changed its default from 8h -> 1w.
Timo Sirainen <tss@iki.fi>
parents:
14332
diff
changeset
|
155 } 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
|
156 /* 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
|
157 last checked it. */ |
15080
e708a1d691d3
Compiler warning fixes for 32bit systems.
Timo Sirainen <tss@iki.fi>
parents:
15063
diff
changeset
|
158 } else if (st.st_atime < ioloop_time - (time_t)interval) { |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 /* time to scan */ |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 const char *prefix = |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 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
|
162 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 (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
|
164 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
|
165 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 return TRUE; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 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
|
170 { |
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
|
171 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
|
172 |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
173 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
|
174 ; |
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
|
175 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
|
176 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
|
177 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
|
178 return -1; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 } 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
|
180 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
|
181 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
|
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 { |
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, |
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 "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
|
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 } |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
188 |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
189 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
|
190 return -1; |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
191 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
|
192 box->storage->set->parsed_fsync_mode, |
15063
0efc12f3eb2a
lib-index: Changed mail_index_set_fsync_mode() to use a separate enum for the mask.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
193 MAIL_INDEX_FSYNC_MASK_APPENDS | |
0efc12f3eb2a
lib-index: Changed mail_index_set_fsync_mode() to use a separate enum for the mask.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
194 MAIL_INDEX_FSYNC_MASK_EXPUNGES); |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
195 return 0; |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 |
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
|
198 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
|
199 { |
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
|
200 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
|
201 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
|
202 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
|
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 = 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
|
205 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
|
206 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
|
207 /* 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
|
208 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
|
209 } |
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 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
|
211 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
|
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 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
|
215 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
|
216 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
|
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 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
|
219 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
|
220 } |
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 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
|
222 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
|
223 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
|
224 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
|
225 } |
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 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
|
227 } |
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 |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 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
|
230 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
|
231 { |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10652
diff
changeset
|
232 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
|
233 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
|
234 struct mail_index_view *view; |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
235 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
|
236 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
|
237 struct stat st; |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
238 int ret; |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10652
diff
changeset
|
240 if (directory && |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10652
diff
changeset
|
241 (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
|
242 return 0; |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 |
12710
42ca32299617
dbox: mailbox_create/update() might not have updated index header correctly.
Timo Sirainen <tss@iki.fi>
parents:
12387
diff
changeset
|
244 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
|
245 return -1; |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
246 |
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
|
247 /* 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 "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
|
258 "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
|
259 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
|
260 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
|
261 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
|
262 } |
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 /* 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
|
264 } |
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 |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
266 /* use syncing as a lock */ |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
267 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
|
268 if (ret <= 0) { |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
269 i_assert(ret != 0); |
13474
1903d5fd7e76
lib-storage: Minor error handling cleanups.
Timo Sirainen <tss@iki.fi>
parents:
12822
diff
changeset
|
270 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
|
271 return -1; |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
272 } |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
273 |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
274 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
|
275 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
|
276 mail_index_sync_rollback(&sync_ctx); |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
277 return -1; |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
278 } |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
279 } |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
280 |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
281 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
|
282 } |