Mercurial > dovecot > core-2.2
annotate src/lib-storage/index/dbox-common/dbox-storage.c @ 22291:5a81b1690625
sdbox: Don't create index directory when trying to open nonexistent mailboxes
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Tue, 27 Jun 2017 16:55:34 +0300 |
parents | 5c323f23282f |
children | d8bb722cde68 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
19552
diff
changeset
|
1 /* Copyright (c) 2007-2017 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" |
15285 | 4 #include "abspath.h" |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "ioloop.h" |
15170
b6663a4f60fe
Compiler warning fix for previous change
Timo Sirainen <tss@iki.fi>
parents:
15169
diff
changeset
|
6 #include "abspath.h" |
12312
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
7 #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
|
8 #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
|
9 #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
|
10 #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
|
11 #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
|
12 #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
|
13 #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
|
14 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 #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
|
16 #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
|
17 #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
|
18 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 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
|
20 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
|
21 { |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
32 static bool |
15462
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
33 dbox_alt_path_has_changed(const char *root_dir, const char *alt_path, |
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
34 const char *alt_path2, const char *alt_symlink_path) |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
35 { |
15284 | 36 const char *linkpath; |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
37 |
15284 | 38 if (t_readlink(alt_symlink_path, &linkpath) < 0) { |
13269
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 |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
45 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
|
46 i_warning("dbox %s: Original ALT=%s, " |
15284 | 47 "but currently no ALT path set", root_dir, linkpath); |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
48 return TRUE; |
15284 | 49 } else if (strcmp(linkpath, alt_path) != 0) { |
15462
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
50 if (strcmp(linkpath, alt_path2) == 0) { |
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
51 /* FIXME: for backwards compatibility. old versions |
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
52 created the symlink to mailboxes/ directory, which |
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
53 was fine with sdbox, but didn't even exist with |
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
54 mdbox. we'll silently replace the symlink. */ |
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
55 return TRUE; |
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
56 } |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
57 i_warning("dbox %s: Original ALT=%s, " |
15284 | 58 "but currently ALT=%s", root_dir, linkpath, alt_path); |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
59 return TRUE; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
60 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
61 return FALSE; |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
62 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
63 |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
64 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
|
65 { |
15462
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
66 const char *root_dir, *alt_symlink_path, *alt_path, *alt_path2; |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
67 |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
68 root_dir = mailbox_list_get_root_forced(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
|
69 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
|
70 t_strconcat(root_dir, "/"DBOX_ALT_SYMLINK_NAME, NULL); |
15462
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
71 (void)mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_ALT_DIR, |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
72 &alt_path); |
15462
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
73 (void)mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX, |
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
74 &alt_path2); |
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
75 if (!dbox_alt_path_has_changed(root_dir, alt_path, alt_path2, |
b1267f135417
dbox: dbox-alt-root symlink now points to the alt root directory, not to mailboxes dir.
Timo Sirainen <tss@iki.fi>
parents:
15342
diff
changeset
|
76 alt_symlink_path)) |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
77 return; |
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 /* unlink/create the current alt path symlink */ |
19136
fefaa6d09a81
Replaced unlink() calls with i_unlink*() wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
18981
diff
changeset
|
80 i_unlink_if_exists(alt_symlink_path); |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
81 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
|
82 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
|
83 errno != EEXIST) { |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
84 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
|
85 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
|
86 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
87 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
88 } |
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
89 |
12312
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
90 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
|
91 struct mail_namespace *ns, |
15085
8f4ce0932777
lib-fs: fs_init() API changed to allow returning an error.
Timo Sirainen <tss@iki.fi>
parents:
15080
diff
changeset
|
92 const char **error_r) |
12312
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 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
|
95 const struct mail_storage_settings *set = _storage->set; |
15085
8f4ce0932777
lib-fs: fs_init() API changed to allow returning an error.
Timo Sirainen <tss@iki.fi>
parents:
15080
diff
changeset
|
96 const char *error; |
12312
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
97 |
15085
8f4ce0932777
lib-fs: fs_init() API changed to allow returning an error.
Timo Sirainen <tss@iki.fi>
parents:
15080
diff
changeset
|
98 if (*set->mail_attachment_fs != '\0') { |
12312
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
99 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
|
100 |
21808
5c323f23282f
dbox: Allow ":" separator between mail_attachment_fs driver and args.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
101 args = strpbrk(set->mail_attachment_fs, ": "); |
12312
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
102 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
|
103 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
|
104 args = ""; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
105 } else { |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
106 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
|
107 } |
15305
9542732069ff
sdbox: Make sure mail_attachment_fs=sis-queue isn't attempted to be used.
Timo Sirainen <tss@iki.fi>
parents:
15285
diff
changeset
|
108 if (strcmp(name, "sis-queue") == 0 && |
9542732069ff
sdbox: Make sure mail_attachment_fs=sis-queue isn't attempted to be used.
Timo Sirainen <tss@iki.fi>
parents:
15285
diff
changeset
|
109 (_storage->class_flags & MAIL_STORAGE_CLASS_FLAG_FILE_PER_MSG) != 0) { |
9542732069ff
sdbox: Make sure mail_attachment_fs=sis-queue isn't attempted to be used.
Timo Sirainen <tss@iki.fi>
parents:
15285
diff
changeset
|
110 /* FIXME: the deduplication part doesn't work, because |
9542732069ff
sdbox: Make sure mail_attachment_fs=sis-queue isn't attempted to be used.
Timo Sirainen <tss@iki.fi>
parents:
15285
diff
changeset
|
111 sdbox renames the files.. */ |
9542732069ff
sdbox: Make sure mail_attachment_fs=sis-queue isn't attempted to be used.
Timo Sirainen <tss@iki.fi>
parents:
15285
diff
changeset
|
112 *error_r = "mail_attachment_fs: " |
9542732069ff
sdbox: Make sure mail_attachment_fs=sis-queue isn't attempted to be used.
Timo Sirainen <tss@iki.fi>
parents:
15285
diff
changeset
|
113 "sis-queue not currently supported by sdbox"; |
9542732069ff
sdbox: Make sure mail_attachment_fs=sis-queue isn't attempted to be used.
Timo Sirainen <tss@iki.fi>
parents:
15285
diff
changeset
|
114 return -1; |
9542732069ff
sdbox: Make sure mail_attachment_fs=sis-queue isn't attempted to be used.
Timo Sirainen <tss@iki.fi>
parents:
15285
diff
changeset
|
115 } |
12312
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
116 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
|
117 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
|
118 storage->attachment_dir = p_strdup(_storage->pool, dir); |
16944
9d5bfd8e50c9
lib-storage: Added mailbox_list_init_fs() to easily initialize fs.
Timo Sirainen <tss@iki.fi>
parents:
16403
diff
changeset
|
119 |
9d5bfd8e50c9
lib-storage: Added mailbox_list_init_fs() to easily initialize fs.
Timo Sirainen <tss@iki.fi>
parents:
16403
diff
changeset
|
120 if (mailbox_list_init_fs(ns->list, name, args, |
9d5bfd8e50c9
lib-storage: Added mailbox_list_init_fs() to easily initialize fs.
Timo Sirainen <tss@iki.fi>
parents:
16403
diff
changeset
|
121 storage->attachment_dir, |
9d5bfd8e50c9
lib-storage: Added mailbox_list_init_fs() to easily initialize fs.
Timo Sirainen <tss@iki.fi>
parents:
16403
diff
changeset
|
122 &storage->attachment_fs, &error) < 0) { |
15085
8f4ce0932777
lib-fs: fs_init() API changed to allow returning an error.
Timo Sirainen <tss@iki.fi>
parents:
15080
diff
changeset
|
123 *error_r = t_strdup_printf("mail_attachment_fs: %s", |
8f4ce0932777
lib-fs: fs_init() API changed to allow returning an error.
Timo Sirainen <tss@iki.fi>
parents:
15080
diff
changeset
|
124 error); |
8f4ce0932777
lib-fs: fs_init() API changed to allow returning an error.
Timo Sirainen <tss@iki.fi>
parents:
15080
diff
changeset
|
125 return -1; |
8f4ce0932777
lib-fs: fs_init() API changed to allow returning an error.
Timo Sirainen <tss@iki.fi>
parents:
15080
diff
changeset
|
126 } |
8f4ce0932777
lib-fs: fs_init() API changed to allow returning an error.
Timo Sirainen <tss@iki.fi>
parents:
15080
diff
changeset
|
127 } |
13269
8aeeaf770612
dbox: Create symlink to alt root dir, and warn whenever it changes.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
128 |
15159
a14f1d2e2b45
lib-storage: Added ALTNOCHECK option to mail_location.
Timo Sirainen <tss@iki.fi>
parents:
14379
diff
changeset
|
129 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
|
130 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
|
131 return 0; |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
132 } |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
133 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
134 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
|
135 { |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
136 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
|
137 |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
138 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
|
139 fs_deinit(&storage->attachment_fs); |
15272
ca10d2e8d8e3
lib-storage: Moved mail attribute dict to struct mail_storage.
Timo Sirainen <tss@iki.fi>
parents:
15198
diff
changeset
|
140 index_storage_destroy(_storage); |
12312
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
141 } |
28eaaa23f2c6
lib-storage: Added support for saving mail attachments separately via filesystem API.
Timo Sirainen <tss@iki.fi>
parents:
11652
diff
changeset
|
142 |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 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
|
144 { |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 const char *path; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
147 path = mailbox_list_get_root_forced(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
|
148 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
|
149 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
|
150 } |
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 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
|
153 { |
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
|
154 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
|
155 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 if (box->notify_callback == NULL) |
18981
f84c81ed5d09
lib-storage: Moved index/index-mailbox-check.c code to mailbox-watch.c
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
157 mailbox_watch_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
|
158 else { |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
159 if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
160 &dir) <= 0) |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
161 return; |
15341
15dfd6475f64
Replaced *_INDEX_PREFIX macros with a common MAIL_INDEX_PREFIX.
Timo Sirainen <tss@iki.fi>
parents:
15337
diff
changeset
|
162 path = t_strdup_printf("%s/"MAIL_INDEX_PREFIX".log", dir); |
18981
f84c81ed5d09
lib-storage: Moved index/index-mailbox-check.c code to mailbox-watch.c
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
163 mailbox_watch_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
|
164 } |
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 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 static bool |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 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
|
169 { |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 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
|
171 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
|
172 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 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
|
174 return FALSE; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 /* 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
|
177 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
|
178 /* disabled */ |
370e1f945c01
Added mail_temp_scan_interval setting and changed its default from 8h -> 1w.
Timo Sirainen <tss@iki.fi>
parents:
14332
diff
changeset
|
179 } 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
|
180 /* 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
|
181 last checked it. */ |
15080
e708a1d691d3
Compiler warning fixes for 32bit systems.
Timo Sirainen <tss@iki.fi>
parents:
15063
diff
changeset
|
182 } 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
|
183 /* time to scan */ |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 const char *prefix = |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 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
|
186 |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 (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
|
188 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
|
189 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 return TRUE; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 |
22291
5a81b1690625
sdbox: Don't create index directory when trying to open nonexistent mailboxes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21808
diff
changeset
|
193 int dbox_mailbox_check_existence(struct mailbox *box) |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 { |
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
|
195 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
|
196 |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
197 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
|
198 ; |
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
|
199 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
|
200 mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND, |
16182
eece943c7521
"Mailbox doesn't exist" error mixed up using storage and virtual mailbox names.
Timo Sirainen <tss@iki.fi>
parents:
15800
diff
changeset
|
201 T_MAIL_ERR_MAILBOX_NOT_FOUND(box->vname)); |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 return -1; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 } 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
|
204 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
|
205 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
|
206 return -1; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 } else { |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 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
|
209 "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
|
210 return -1; |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 } |
22291
5a81b1690625
sdbox: Don't create index directory when trying to open nonexistent mailboxes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21808
diff
changeset
|
212 return 0; |
5a81b1690625
sdbox: Don't create index directory when trying to open nonexistent mailboxes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21808
diff
changeset
|
213 } |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
214 |
22291
5a81b1690625
sdbox: Don't create index directory when trying to open nonexistent mailboxes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21808
diff
changeset
|
215 int dbox_mailbox_open(struct mailbox *box) |
5a81b1690625
sdbox: Don't create index directory when trying to open nonexistent mailboxes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21808
diff
changeset
|
216 { |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
217 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
|
218 return -1; |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 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
|
223 return 0; |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 } |
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 |
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
|
226 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
|
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 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
|
229 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
|
230 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
|
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 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
|
233 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
|
234 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
|
235 /* 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
|
236 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
|
237 } |
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
|
238 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
|
239 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
|
240 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
|
241 } |
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
|
242 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
|
243 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
|
244 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
|
245 |
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
|
246 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
|
247 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
|
248 } |
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 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
|
250 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
|
251 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
|
252 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
|
253 } |
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 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
|
255 } |
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 |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 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
|
258 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
|
259 { |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10652
diff
changeset
|
260 struct dbox_storage *storage = (struct dbox_storage *)box->storage; |
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
|
261 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
|
262 struct stat st; |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
263 int ret; |
9977
0bb321c347ae
Split dbox (single-dbox) and mdbox (multi-dbox) into separate storage backends.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 |
15112
6e90fc8dfa25
lib-storage: Removed mailbox_list.create_mailbox_dir() virtual function.
Timo Sirainen <tss@iki.fi>
parents:
15100
diff
changeset
|
265 if ((ret = index_storage_mailbox_create(box, directory)) <= 0) |
6e90fc8dfa25
lib-storage: Removed mailbox_list.create_mailbox_dir() virtual function.
Timo Sirainen <tss@iki.fi>
parents:
15100
diff
changeset
|
266 return ret; |
12710
42ca32299617
dbox: mailbox_create/update() might not have updated index header correctly.
Timo Sirainen <tss@iki.fi>
parents:
12387
diff
changeset
|
267 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
|
268 return -1; |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
269 |
15800
004b69090776
dbox: Fail if trying to create a mailbox that already exists.
Timo Sirainen <tss@iki.fi>
parents:
15305
diff
changeset
|
270 if (mail_index_get_header(box->view)->uid_validity != 0) { |
004b69090776
dbox: Fail if trying to create a mailbox that already exists.
Timo Sirainen <tss@iki.fi>
parents:
15305
diff
changeset
|
271 mail_storage_set_error(box->storage, MAIL_ERROR_EXISTS, |
004b69090776
dbox: Fail if trying to create a mailbox that already exists.
Timo Sirainen <tss@iki.fi>
parents:
15305
diff
changeset
|
272 "Mailbox already exists"); |
004b69090776
dbox: Fail if trying to create a mailbox that already exists.
Timo Sirainen <tss@iki.fi>
parents:
15305
diff
changeset
|
273 return -1; |
004b69090776
dbox: Fail if trying to create a mailbox that already exists.
Timo Sirainen <tss@iki.fi>
parents:
15305
diff
changeset
|
274 } |
004b69090776
dbox: Fail if trying to create a mailbox that already exists.
Timo Sirainen <tss@iki.fi>
parents:
15305
diff
changeset
|
275 |
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
|
276 /* 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
|
277 that we don't start overwriting files. */ |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
278 ret = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX, &alt_path); |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
279 if (ret > 0 && stat(alt_path, &st) == 0) { |
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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 "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
|
286 "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
|
287 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
|
288 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
|
289 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
|
290 } |
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
|
291 /* 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
|
292 } |
17331
ed6e472cab0e
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
293 return dbox_mailbox_create_indexes(box, update); |
ed6e472cab0e
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
294 } |
ed6e472cab0e
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
295 |
ed6e472cab0e
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
296 int dbox_mailbox_create_indexes(struct mailbox *box, |
ed6e472cab0e
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
297 const struct mailbox_update *update) |
ed6e472cab0e
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
298 { |
ed6e472cab0e
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
299 struct dbox_storage *storage = (struct dbox_storage *)box->storage; |
ed6e472cab0e
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
300 struct mail_index_sync_ctx *sync_ctx; |
ed6e472cab0e
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
301 struct mail_index_view *view; |
ed6e472cab0e
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
302 struct mail_index_transaction *trans; |
ed6e472cab0e
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
303 int ret; |
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
|
304 |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
305 /* use syncing as a lock */ |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
306 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
|
307 if (ret <= 0) { |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
308 i_assert(ret != 0); |
15342
5479887eb461
lib-storage: Renamed mail_storage_set_index_error() to mailbox_set_index_error()
Timo Sirainen <tss@iki.fi>
parents:
15341
diff
changeset
|
309 mailbox_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
|
310 return -1; |
11484
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
311 } |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
312 |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
313 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
|
314 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
|
315 mail_index_sync_rollback(&sync_ctx); |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
316 return -1; |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
317 } |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
318 } |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
319 |
7fc5db26f6eb
dbox, mdbox: Fixed race conditions when creating mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
320 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
|
321 } |
15095
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
322 |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
323 int dbox_verify_alt_storage(struct mailbox_list *list) |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
324 { |
15118
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15112
diff
changeset
|
325 const char *alt_path; |
15095
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
326 struct stat st; |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
327 |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
328 if (!mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_ALT_DIR, |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
329 &alt_path)) |
15095
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
330 return 0; |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
331 |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
332 /* make sure alt storage is mounted. if it's not, abort the rebuild. */ |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
333 if (stat(alt_path, &st) == 0) |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
334 return 0; |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
335 if (errno != ENOENT) { |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
336 i_error("stat(%s) failed: %m", alt_path); |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
337 return -1; |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
338 } |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
339 |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
340 /* try to create the alt directory. if it fails, it means alt |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
341 storage isn't mounted. */ |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
342 if (mailbox_list_mkdir_root(list, alt_path, |
15118
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15112
diff
changeset
|
343 MAILBOX_LIST_PATH_TYPE_ALT_DIR) < 0) |
15095
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
344 return -1; |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
345 return 0; |
89c319980584
dbox: Renamed dbox_sync_rebuild_verify_alt_storage() to dbox_verify_alt_storage()
Timo Sirainen <tss@iki.fi>
parents:
15085
diff
changeset
|
346 } |
16403
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
347 |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
348 bool dbox_header_have_flag(struct mailbox *box, uint32_t ext_id, |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
349 unsigned int flags_offset, uint8_t flag) |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
350 { |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
351 const void *data; |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
352 size_t data_size; |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
353 uint8_t flags = 0; |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
354 |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
355 mail_index_get_header_ext(box->view, ext_id, &data, &data_size); |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
356 if (flags_offset < data_size) |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
357 flags = *((const uint8_t *)data + flags_offset); |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
358 return (flags & flag) != 0; |
967ef2a7fa6f
dbox: Don't cache pop3.uidl|order unless index header indicates there are those.
Timo Sirainen <tss@iki.fi>
parents:
16198
diff
changeset
|
359 } |