21
21
set->layout = MAILBOX_LIST_NAME_FS;
22
22
if (set->subscription_fname == NULL)
23
23
set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME;
24
if (set->maildir_name == NULL)
24
if (*set->maildir_name == '\0')
25
25
set->maildir_name = DBOX_MAILDIR_NAME;
26
if (set->mailbox_dir_name == NULL)
26
if (*set->mailbox_dir_name == '\0')
27
27
set->mailbox_dir_name = DBOX_MAILBOX_DIR_NAME;
31
dbox_alt_path_has_changed(const char *root_dir,
32
const char *alt_path, const char *alt_symlink_path)
37
ret = readlink(alt_symlink_path, buf, sizeof(buf)-1);
40
return alt_path != NULL;
41
i_error("readlink(%s) failed: %m", alt_symlink_path);
46
if (alt_path == NULL) {
47
i_warning("dbox %s: Original ALT=%s, "
48
"but currently no ALT path set", root_dir, buf);
50
} else if (strcmp(buf, alt_path) != 0) {
51
i_warning("dbox %s: Original ALT=%s, "
52
"but currently ALT=%s", root_dir, buf, alt_path);
58
static void dbox_verify_alt_path(struct mailbox_list *list)
60
const char *root_dir, *alt_symlink_path, *alt_path;
62
root_dir = mailbox_list_get_path(list, NULL,
63
MAILBOX_LIST_PATH_TYPE_DIR);
65
t_strconcat(root_dir, "/"DBOX_ALT_SYMLINK_NAME, NULL);
66
alt_path = mailbox_list_get_path(list, NULL,
67
MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX);
68
if (!dbox_alt_path_has_changed(root_dir, alt_path, alt_symlink_path))
71
/* unlink/create the current alt path symlink */
72
if (unlink(alt_symlink_path) < 0 && errno != ENOENT)
73
i_error("unlink(%s) failed: %m", alt_symlink_path);
74
if (alt_path != NULL) {
75
if (symlink(alt_path, alt_symlink_path) < 0 &&
77
i_error("symlink(%s, %s) failed: %m",
78
alt_path, alt_symlink_path);
30
83
int dbox_storage_create(struct mail_storage *_storage,
31
84
struct mail_namespace *ns,
32
85
const char **error_r ATTR_UNUSED)
92
147
dbox_cleanup_if_exists(struct mailbox_list *list, const char *path)
150
unsigned int interval = list->mail_set->mail_temp_scan_interval;
96
152
if (stat(path, &st) < 0)
99
155
/* check once in a while if there are temp files to clean up */
100
if (st.st_atime > st.st_ctime + DBOX_TMP_DELETE_SECS) {
158
} else if (st.st_atime > st.st_ctime + DBOX_TMP_DELETE_SECS) {
101
159
/* there haven't been any changes to this directory since we
102
160
last checked it. */
103
} else if (st.st_atime < ioloop_time - DBOX_TMP_SCAN_SECS) {
161
} else if (st.st_atime < ioloop_time - interval) {
104
162
/* time to scan */
105
163
const char *prefix =
106
164
mailbox_list_get_global_temp_prefix(list);
114
172
int dbox_mailbox_open(struct mailbox *box)
116
if (dbox_cleanup_if_exists(box->list, box->path)) {
117
return index_storage_mailbox_open(box, FALSE);
118
} else if (errno == ENOENT) {
174
const char *box_path = mailbox_get_path(box);
176
if (dbox_cleanup_if_exists(box->list, box_path))
178
else if (errno == ENOENT || errno == ENAMETOOLONG) {
119
179
mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
120
180
T_MAIL_ERR_MAILBOX_NOT_FOUND(box->name));
122
182
} else if (errno == EACCES) {
123
183
mail_storage_set_critical(box->storage, "%s",
124
mail_error_eacces_msg("stat", box->path));
184
mail_error_eacces_msg("stat", box_path));
127
187
mail_storage_set_critical(box->storage,
128
"stat(%s) failed: %m", box->path);
188
"stat(%s) failed: %m", box_path);
192
if (index_storage_mailbox_open(box, FALSE) < 0)
194
mail_index_set_fsync_mode(box->index,
195
box->storage->set->parsed_fsync_mode,
196
MAIL_INDEX_SYNC_TYPE_APPEND |
197
MAIL_INDEX_SYNC_TYPE_EXPUNGE);
133
201
static int dir_is_empty(struct mail_storage *storage, const char *path)