mail-index.c revision ea91861234475257f436dc07925f80cf4ac32b71
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2003-2015 Dovecot authors, see the included COPYING file */
5694eeb99b69dea8033ca77ad69743c6b4871370Timo Sirainenstruct mail_index_module_register mail_index_module_register = { 0 };
5694eeb99b69dea8033ca77ad69743c6b4871370Timo Sirainenstatic void mail_index_close_nonopened(struct mail_index *index);
697ff56bf3cdc9e7989ea2a70accf866b14b64d1Timo Sirainenstruct mail_index *mail_index_alloc(const char *dir, const char *prefix)
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen pool_alloconly_create(MEMPOOL_GROWING"index extension", 1024);
697ff56bf3cdc9e7989ea2a70accf866b14b64d1Timo Sirainen p_array_init(&index->extensions, index->extension_pool, 5);
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen mail_index_ext_register(index, MAIL_INDEX_EXT_KEYWORDS,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen index->keywords_pool = pool_alloconly_create("keywords", 512);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen hash_table_create(&index->keywords_hash, index->keywords_pool, 0,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen index->log = mail_transaction_log_alloc(index);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenvoid mail_index_free(struct mail_index **_index)
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenvoid mail_index_set_fsync_mode(struct mail_index *index,
a24519c36d5f8fa22f58b2c693ba547e8d175a54Timo Sirainenvoid mail_index_set_permissions(struct mail_index *index,
a24519c36d5f8fa22f58b2c693ba547e8d175a54Timo Sirainen mode_t mode, gid_t gid, const char *gid_origin)
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenvoid mail_index_set_lock_method(struct mail_index *index,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen index->max_lock_timeout_secs = max_timeout_secs;
db8b0a3f74a20528d66a3c4be7df920e5c4554c2Timo Sirainenvoid mail_index_set_ext_init_data(struct mail_index *index, uint32_t ext_id,
ac2defed599a97c4a71a9e90ba185929dfe59226Josef 'Jeff' Sipek i_assert(index->ext_hdr_init_data == NULL ||
2649b237dd4690575e75a30b2bf3b39ebd37b835Timo Sirainenuint32_t mail_index_ext_register(struct mail_index *index, const char *name,
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen if (*name == '\0' || strcmp(name, str_sanitize(name, -1)) != 0)
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen i_panic("mail_index_ext_register(%s): Invalid name", name);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen if (default_record_size != 0 && default_record_align == 0) {
3fe67ec75ccae1230bb9eb9f16affc48377f6441Timo Sirainen if (mail_index_ext_lookup(index, name, &ext_id))
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen rext.name = p_strdup(index->extension_pool, name);
2a6dcd984104fed84bed8795ccdfabb20e41ce52Timo Sirainen rext.index_idx = array_count(&index->extensions);
638600575ee95f2513c683ef09cb188f76eacd22Timo Sirainenvoid mail_index_ext_register_resize_defaults(struct mail_index *index,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen rext = array_idx_modifiable(&index->extensions, ext_id);
5214b67a7dabab87da74e04bb8b227f94b95bce4Timo Sirainenbool mail_index_ext_lookup(struct mail_index *index, const char *name,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen const struct mail_index_registered_ext *extensions;
27586e4785d56aeb76e1fd96af8db799688dc64aTimo Sirainen unsigned int i, count;
fd8b93ca5cbeba64fe6fa5dc98a3e580fb046791Timo Sirainen extensions = array_get(&index->extensions, &count);
12b4dbf933ee54f7b96968ba150095baa985fdafTimo Sirainen for (i = 0; i < count; i++) {
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenvoid mail_index_register_expunge_handler(struct mail_index *index,
917498e6f84969d2b93410c1e479735abe8e0ed7Timo Sirainen rext = array_idx_modifiable(&index->extensions, ext_id);
917498e6f84969d2b93410c1e479735abe8e0ed7Timo Sirainen i_assert(rext->expunge_handler == NULL || rext->expunge_handler == cb);
917498e6f84969d2b93410c1e479735abe8e0ed7Timo Sirainen rext->expunge_handler_call_always = call_always;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainenvoid mail_index_unregister_expunge_handler(struct mail_index *index,
e5acc283bf030b0b5c79ca4e52d315c516a299faPascal Volk rext = array_idx_modifiable(&index->extensions, ext_id);
db8b0a3f74a20528d66a3c4be7df920e5c4554c2Timo Sirainenvoid mail_index_register_sync_handler(struct mail_index *index, uint32_t ext_id,
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen rext = array_idx_modifiable(&index->extensions, ext_id);
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen i_assert(rext->sync_handler.callback == NULL);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainenvoid mail_index_unregister_sync_handler(struct mail_index *index,
0bf25546c91ccafff9e2cc93368d2d25acb5c39eTimo Sirainen rext = array_idx_modifiable(&index->extensions, ext_id);
94b0ff77495c3ed14bdd4b5d7ae1eb37e8c9efb5Timo Sirainen i_assert(rext->sync_handler.callback != NULL);
94b0ff77495c3ed14bdd4b5d7ae1eb37e8c9efb5Timo Sirainenvoid mail_index_register_sync_lost_handler(struct mail_index *index,
b365bd121cdc87f63e1dd47c5085a27091118e00Timo Sirainen array_append(&index->sync_lost_handlers, &cb, 1);
94b0ff77495c3ed14bdd4b5d7ae1eb37e8c9efb5Timo Sirainenvoid mail_index_unregister_sync_lost_handler(struct mail_index *index,
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen mail_index_sync_lost_handler_t *const *handlers;
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen unsigned int i, count;
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen handlers = array_get(&index->sync_lost_handlers, &count);
c1d19144dd7b1de6822df6ed1d10af0c9cb38840Timo Sirainen for (i = 0; i < count; i++) {
c1d19144dd7b1de6822df6ed1d10af0c9cb38840Timo Sirainen array_delete(&index->sync_lost_handlers, i, 1);
c1d19144dd7b1de6822df6ed1d10af0c9cb38840Timo Sirainenbool mail_index_keyword_lookup(struct mail_index *index,
c1d19144dd7b1de6822df6ed1d10af0c9cb38840Timo Sirainen /* keywords_hash keeps a name => index mapping of keywords.
c1d19144dd7b1de6822df6ed1d10af0c9cb38840Timo Sirainen Keywords are never removed from it, so the index values are valid
c1d19144dd7b1de6822df6ed1d10af0c9cb38840Timo Sirainen for the lifetime of the mail_index. */
c1d19144dd7b1de6822df6ed1d10af0c9cb38840Timo Sirainen if (hash_table_lookup_full(index->keywords_hash, keyword,
33525312d3f45995686aa0b538dea1cd6eb936e2Timo Sirainen *idx_r = POINTER_CAST_TO(value, unsigned int);
0bf25546c91ccafff9e2cc93368d2d25acb5c39eTimo Sirainenvoid mail_index_keyword_lookup_or_create(struct mail_index *index,
0bf25546c91ccafff9e2cc93368d2d25acb5c39eTimo Sirainen unsigned int *idx_r)
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen if (mail_index_keyword_lookup(index, keyword, idx_r))
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen keyword = keyword_dup = p_strdup(index->keywords_pool, keyword);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen hash_table_insert(index->keywords_hash, keyword_dup,
94b0ff77495c3ed14bdd4b5d7ae1eb37e8c9efb5Timo Sirainen /* keep the array NULL-terminated, but the NULL itself invisible */
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen array_delete(&index->keywords, array_count(&index->keywords)-1, 1);
c58c12049c883b281c088d47a2a7278c21c390e1Timo Sirainenconst ARRAY_TYPE(keywords) *mail_index_get_keywords(struct mail_index *index)
c1d19144dd7b1de6822df6ed1d10af0c9cb38840Timo Sirainenmail_index_keywords_create(struct mail_index *index,
1c1cecd3dfaf71b0c9499b044023e631841e88aaTimo Sirainen const char *const keywords[])
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen /* @UNSAFE */
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen /* look up the keywords from index. they're never removed from there
638600575ee95f2513c683ef09cb188f76eacd22Timo Sirainen so we can permanently store indexes to them. */
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen mail_index_keyword_lookup_or_create(index, keywords[src],
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen /* ignore if this is a duplicate */
b365bd121cdc87f63e1dd47c5085a27091118e00Timo Sirainen for (i = 0; i < src; i++) {
fd8b93ca5cbeba64fe6fa5dc98a3e580fb046791Timo Sirainenmail_index_keywords_create_from_indexes(struct mail_index *index,
12b4dbf933ee54f7b96968ba150095baa985fdafTimo Sirainen const unsigned int *indexes;
1728ff34ee03de825ad3aeed67d19f8ae140ee2eTimo Sirainen /* @UNSAFE */
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen /* copy but skip duplicates */
0bf25546c91ccafff9e2cc93368d2d25acb5c39eTimo Sirainen for (i = 0; i < src; i++) {
1728ff34ee03de825ad3aeed67d19f8ae140ee2eTimo Sirainenvoid mail_index_keywords_ref(struct mail_keywords *keywords)
49c48631cfd07017d5f93d83713fffe4f13730c4Timo Sirainenvoid mail_index_keywords_unref(struct mail_keywords **_keywords)
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainenint mail_index_try_open_only(struct mail_index *index)
0bf25546c91ccafff9e2cc93368d2d25acb5c39eTimo Sirainen /* Note that our caller must close index->fd by itself. */
0b4e1043e596bfb36d999dacbf1d4d63ee96d75fTimo Sirainen index->fd = nfs_safe_open(index->filepath, O_RDWR);
1433bf361ddb0bba8878c8ada5726d0284edad57Timo Sirainen mail_index_set_syscall_error(index, "open()");
0b4e1043e596bfb36d999dacbf1d4d63ee96d75fTimo Sirainen /* have to create it */
0b4e1043e596bfb36d999dacbf1d4d63ee96d75fTimo Sirainen ret = mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD);
0bf25546c91ccafff9e2cc93368d2d25acb5c39eTimo Sirainen /* it's corrupted - recreate it */
d9a7e950a9cd21f2b4a90ec7759fca9e8fcc7995Timo Sirainen mail_index_set_syscall_error(index, "close()");
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainenint mail_index_create_tmp_file(struct mail_index *index,
d508ab8db2b0f74b5e225d199b4aaa5293342746Timo Sirainen path = *path_r = t_strconcat(path_prefix, ".tmp", NULL);
d508ab8db2b0f74b5e225d199b4aaa5293342746Timo Sirainen fd = open(path, O_RDWR|O_CREAT|O_EXCL, index->mode);
d508ab8db2b0f74b5e225d199b4aaa5293342746Timo Sirainen /* stale temp file. unlink and recreate rather than overwriting,
d508ab8db2b0f74b5e225d199b4aaa5293342746Timo Sirainen just to make sure locking problems won't cause corruption */
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen fd = open(path, O_RDWR|O_CREAT|O_EXCL, index->mode);
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen mail_index_file_set_syscall_error(index, path, "creat()");
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainenstatic int mail_index_open_files(struct mail_index *index,
6f970b9a0dadb80e120d017c75c637b5a3879dacTimo Sirainen if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0)
d508ab8db2b0f74b5e225d199b4aaa5293342746Timo Sirainen /* if dovecot.index exists, read it first so that we can get
d508ab8db2b0f74b5e225d199b4aaa5293342746Timo Sirainen the correct indexid and log sequence */
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen /* Create a new indexid for us. If we're opening index
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen into memory, index->map doesn't exist yet. */
a4e2101473cfd7ce960fc49b3ce097c3f89ec2adTimo Sirainen ret = mail_transaction_log_create(index->log, FALSE);
a4e2101473cfd7ce960fc49b3ce097c3f89ec2adTimo Sirainen /* log creation could have changed it if someone else
a4e2101473cfd7ce960fc49b3ce097c3f89ec2adTimo Sirainen just created it. */
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen ret = index->map != NULL ? 1 : mail_index_try_open(index);
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen /* corrupted */
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen ret = mail_transaction_log_create(index->log, TRUE);
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen /* open/create failed, fallback to in-memory indexes */
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0)
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen index->cache = mail_cache_open_or_create(index);
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainenmail_index_open_opened(struct mail_index *index,
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen if ((index->map->hdr.flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) {
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen /* index was marked corrupted. we'll probably need to
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen recreate the files. */
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen if ((ret = mail_index_open_files(index, flags)) <= 0)
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainenint mail_index_open(struct mail_index *index, enum mail_index_open_flags flags)
636f017be100bce67d66fd3ae1544a47681efd33Timo Sirainen if ((ret = mail_index_open_opened(index, flags)) <= 0) {
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen /* doesn't exist and create flag not used */
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen index->filepath = MAIL_INDEX_IS_IN_MEMORY(index) ?
494a5de15db3b2806ab31d5ecc3e1c306ae14d06Timo Sirainen i_strconcat(index->dir, "/", index->prefix, NULL);
9d4c027e7de01ab948d6221bc27c9b45d32d1ea5Timo Sirainen index->readonly = (flags & MAIL_INDEX_OPEN_FLAG_READONLY) != 0;
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainen if ((flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0 &&
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainen i_fatal("nfs flush requires mail_fsync=always");
08ed4ab71fd2a4e800d9025a736f0f46b771ea90Timo Sirainen if ((flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0 &&
08ed4ab71fd2a4e800d9025a736f0f46b771ea90Timo Sirainen (flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) == 0)
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainen i_fatal("nfs flush requires mmap_disable=yes");
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainen /* NOTE: increase open_count only after mail_index_open_files().
1c1cecd3dfaf71b0c9499b044023e631841e88aaTimo Sirainen it's used elsewhere to check if we're doing an initial opening
1c1cecd3dfaf71b0c9499b044023e631841e88aaTimo Sirainen of the index files */
1c1cecd3dfaf71b0c9499b044023e631841e88aaTimo Sirainen if ((ret = mail_index_open_files(index, flags)) <= 0) {
1c1cecd3dfaf71b0c9499b044023e631841e88aaTimo Sirainen /* doesn't exist and create flag not used */
e4cb3bfcd42f1f2c9e676ece6f7f53803f5c6a16Timo Sirainenint mail_index_open_or_create(struct mail_index *index,
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainenvoid mail_index_close_file(struct mail_index *index)
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen mail_index_set_syscall_error(index, "close()");
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainenstatic void mail_index_close_nonopened(struct mail_index *index)
a4e2101473cfd7ce960fc49b3ce097c3f89ec2adTimo Sirainenvoid mail_index_close(struct mail_index *index)
a4e2101473cfd7ce960fc49b3ce097c3f89ec2adTimo Sirainenint mail_index_unlink(struct mail_index *index)
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen if (MAIL_INDEX_IS_IN_MEMORY(index) || index->readonly)
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen /* main index */
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen if (unlink(index->filepath) < 0 && errno != ENOENT)
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen path = t_strconcat(index->filepath, MAIL_TRANSACTION_LOG_SUFFIX, NULL);
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen path = t_strconcat(index->filepath, MAIL_CACHE_FILE_SUFFIX, NULL);
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainenint mail_index_reopen_if_changed(struct mail_index *index)
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen if ((index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0)
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen if (nfs_safe_stat(index->filepath, &st2) < 0) {
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen mail_index_set_syscall_error(index, "stat()");
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen mail_index_set_syscall_error(index, "fstat()");
1f4399a277b861419b82758ab0462e90c00a4c41Timo Sirainen /* the same file */
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen /* new file, new locks. the old fd can keep its locks, they don't
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainen matter anymore as no-one's going to modify the file. */
636f017be100bce67d66fd3ae1544a47681efd33Timo Sirainenint mail_index_refresh(struct mail_index *index)
9b00ecffbe74fd864d0d72e6112ec53b86f619baTimo Sirainen ret = mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD);
9b00ecffbe74fd864d0d72e6112ec53b86f619baTimo Sirainenstruct mail_cache *mail_index_get_cache(struct mail_index *index)
0bd259973f98837cf0e41fdee3e2a578e51ad09eTimo Sirainenvoid mail_index_set_error(struct mail_index *index, const char *fmt, ...)
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainenbool mail_index_is_in_memory(struct mail_index *index)
69af83d4e6c2c5c825a17edd7a41a4fb014caa8fTimo Sirainenint mail_index_move_to_memory(struct mail_index *index)
6f970b9a0dadb80e120d017c75c637b5a3879dacTimo Sirainen if ((index->flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) != 0)
6f970b9a0dadb80e120d017c75c637b5a3879dacTimo Sirainen /* set the index as being into memory */
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainen index->filepath = i_strdup("(in-memory index)");
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen /* index was never even opened. just mark it as being in
e7d0bea63a08b08c47c4b5c187d2cb7127859657Timo Sirainen memory and let the caller re-open the index. */
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen /* move index map to memory */
dc5606fb66d30a659459446b6ca1a8b4f1146052Timo Sirainen if (!MAIL_INDEX_MAP_IS_IN_MEMORY(index->map)) {
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainen /* move transaction log to memory */
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainen mail_transaction_log_move_to_memory(index->log);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen mail_index_set_syscall_error(index, "close()");
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainenvoid mail_index_mark_corrupted(struct mail_index *index)
bd4e36a8cd7257cca7d1434c49a1e343ed7c5100Timo Sirainen index->map->hdr.flags |= MAIL_INDEX_HDR_FLAG_CORRUPTED;
37847ec8eaec9ad55c9df10ae109efe7b37ac573Timo Sirainen mail_index_set_syscall_error(index, "unlink()");
4654cf737f538f5de032b8c9908913f121917366Timo Sirainen (void)mail_transaction_log_unlink(index->log);
4654cf737f538f5de032b8c9908913f121917366Timo Sirainenbool mail_index_is_deleted(struct mail_index *index)
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen return index->index_delete_requested || index->index_deleted;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenint mail_index_get_modification_time(struct mail_index *index, time_t *mtime_r)
ae2b61a8c6318e56dabd44de17e227c95985aedaTimo Sirainen if (mail_transaction_log_get_mtime(index->log, mtime_r) < 0)
ae2b61a8c6318e56dabd44de17e227c95985aedaTimo Sirainen mail_index_set_syscall_error(index, "stat()");
c58906589cafc32df4c04ffbef933baadd3f2276Timo Sirainenvoid mail_index_fchown(struct mail_index *index, int fd, const char *path)
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen /* no gid changing */
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen } else if (fchown(fd, (uid_t)-1, index->gid) == 0) {
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen /* success */
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen } if ((index->mode & 0060) >> 3 == (index->mode & 0006)) {
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen /* group and world permissions are the same, so group doesn't
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen really matter. ignore silently. */
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen mail_index_file_set_syscall_error(index, path, "fchown()");
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainen eperm_error_get_chgrp("fchown", path, index->gid,
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainen /* continue, but change permissions so that only the common
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainen subset of group and world is used. this makes sure no one
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainen gets any extra permissions. */
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainen mode = ((index->mode & 0060) >> 3) & (index->mode & 0006);
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainen mail_index_file_set_syscall_error(index, path, "fchmod()");
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainenvoid mail_index_set_syscall_error(struct mail_index *index,
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainen mail_index_file_set_syscall_error(index, index->filepath, function);
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainenvoid mail_index_file_set_syscall_error(struct mail_index *index,
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainen if ((index->flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) == 0)
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainen errstr = eacces_error_get_creating(function, filepath);
d2e74f2af690b8e2d536400f02f397cbed1334b7Timo Sirainen errstr = eacces_error_get(function, filepath);
8709b2fe6ec2b5ca1d90a63490f8371472062efdTimo Sirainen " (process was started with ulimit -f limit)";
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen mail_index_set_error(index, "%s failed with file %s: "
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainenconst char *mail_index_get_error_message(struct mail_index *index)