Mercurial > dovecot > core-2.2
annotate src/lib-index/mail-index.c @ 17904:0a34975b2dcc
lib-index: Added path parameter to mail_index_create_tmp_file()
This allows using it for creating any kind of a new index file with proper
file permissions.
Some of the old code should probably be changed to use this. Maybe even move
this function to public mail-index.h
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 07 Oct 2014 19:04:36 +0300 |
parents | 6aeb2a7e5303 |
children | 71c00e501179 |
rev | line source |
---|---|
17130
add8c00fb3cc
Updated copyright notices to include year 2014.
Timo Sirainen <tss@iki.fi>
parents:
17108
diff
changeset
|
1 /* Copyright (c) 2003-2014 Dovecot authors, see the included COPYING file */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
5819 | 4 #include "ioloop.h" |
3470
346a494c2feb
Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents:
3445
diff
changeset
|
5 #include "array.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "buffer.h" |
9535
bbe4c24faf21
Use eacces_get_error() in more places for handling EACCES errors.
Timo Sirainen <tss@iki.fi>
parents:
9421
diff
changeset
|
7 #include "eacces-error.h" |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
8 #include "hash.h" |
6384
2c8b1d487728
Make sure the extension name doesn't contain control characters. It most
Timo Sirainen <tss@iki.fi>
parents:
6378
diff
changeset
|
9 #include "str-sanitize.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "mmap-util.h" |
4071
cd3d26cf124a
Renamed safe-open.* to nfs-workarounds.*, safe_open() to nfs_safe_open() and
Timo Sirainen <tss@iki.fi>
parents:
4067
diff
changeset
|
11 #include "nfs-workarounds.h" |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
12 #include "read-full.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include "write-full.h" |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
10655
diff
changeset
|
14 #include "mail-index-alloc-cache.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 #include "mail-index-private.h" |
5272
82b4a055e109
mmap_disable=yes crashes with recent changes.
Timo Sirainen <tss@iki.fi>
parents:
5247
diff
changeset
|
16 #include "mail-index-view-private.h" |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
17 #include "mail-index-sync-private.h" |
7620 | 18 #include "mail-index-modseq.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 #include "mail-transaction-log.h" |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
20 #include "mail-cache.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 #include <stdio.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 #include <stddef.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 #include <time.h> |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
25 #include <sys/stat.h> |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
26 |
5453
a0a1432bb4e8
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5430
diff
changeset
|
27 struct mail_index_module_register mail_index_module_register = { 0 }; |
4453
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4451
diff
changeset
|
28 |
17579
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
29 static void mail_index_close_nonopened(struct mail_index *index); |
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
30 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 struct mail_index *mail_index_alloc(const char *dir, const char *prefix) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 struct mail_index *index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 index = i_new(struct mail_index, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 index->dir = i_strdup(dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 index->prefix = i_strdup(prefix); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 index->fd = -1; |
2116 | 39 |
5028 | 40 index->extension_pool = |
41 pool_alloconly_create(MEMPOOL_GROWING"index extension", 1024); | |
4596
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
42 p_array_init(&index->extensions, index->extension_pool, 5); |
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
43 i_array_init(&index->sync_lost_handlers, 4); |
5453
a0a1432bb4e8
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5430
diff
changeset
|
44 i_array_init(&index->module_contexts, |
a0a1432bb4e8
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5430
diff
changeset
|
45 I_MIN(5, mail_index_module_register.id)); |
4453
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4451
diff
changeset
|
46 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 index->mode = 0600; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 index->gid = (gid_t)-1; |
11623
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
49 index->lock_method = FILE_LOCK_METHOD_FCNTL; |
15904
d3cf06639864
Replaced all -1U and (unsigned int)-1 with UINT_MAX.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
50 index->max_lock_timeout_secs = UINT_MAX; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
51 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
52 index->keywords_ext_id = |
8547
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
8146
diff
changeset
|
53 mail_index_ext_register(index, MAIL_INDEX_EXT_KEYWORDS, |
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
8146
diff
changeset
|
54 128, 2, 1); |
3086 | 55 index->keywords_pool = pool_alloconly_create("keywords", 512); |
4596
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
56 i_array_init(&index->keywords, 16); |
14918
8eae4e205c82
Hash table API is now (mostly) type safe.
Timo Sirainen <tss@iki.fi>
parents:
14917
diff
changeset
|
57 hash_table_create(&index->keywords_hash, index->keywords_pool, 0, |
8eae4e205c82
Hash table API is now (mostly) type safe.
Timo Sirainen <tss@iki.fi>
parents:
14917
diff
changeset
|
58 strcase_hash, strcasecmp); |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
59 index->log = mail_transaction_log_alloc(index); |
7620 | 60 mail_index_modseq_init(index); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 return index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
64 void mail_index_free(struct mail_index **_index) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
66 struct mail_index *index = *_index; |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
67 |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
68 *_index = NULL; |
10677
93fe3aa23bdb
lib-index: Don't close index files if they're still being used by another mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10674
diff
changeset
|
69 |
93fe3aa23bdb
lib-index: Don't close index files if they're still being used by another mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10674
diff
changeset
|
70 i_assert(index->open_count == 0); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
71 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
72 mail_transaction_log_free(&index->log); |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
8572
diff
changeset
|
73 hash_table_destroy(&index->keywords_hash); |
6428
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6417
diff
changeset
|
74 pool_unref(&index->extension_pool); |
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6417
diff
changeset
|
75 pool_unref(&index->keywords_pool); |
1967 | 76 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
77 array_free(&index->sync_lost_handlers); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
78 array_free(&index->keywords); |
5453
a0a1432bb4e8
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5430
diff
changeset
|
79 array_free(&index->module_contexts); |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
80 |
14079
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
81 i_free(index->ext_hdr_init_data); |
9537
b373de4973cd
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
9535
diff
changeset
|
82 i_free(index->gid_origin); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 i_free(index->dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 i_free(index->prefix); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 i_free(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 |
11634
7f19062f58fd
Renamed fsync_disable to mail_fsync=optimized|always|never.
Timo Sirainen <tss@iki.fi>
parents:
11623
diff
changeset
|
89 void mail_index_set_fsync_mode(struct mail_index *index, |
7f19062f58fd
Renamed fsync_disable to mail_fsync=optimized|always|never.
Timo Sirainen <tss@iki.fi>
parents:
11623
diff
changeset
|
90 enum fsync_mode 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:
14923
diff
changeset
|
91 enum mail_index_fsync_mask mask) |
6736
3e189cbb7e7a
fsync transaction commits only if the transaction contains change types
Timo Sirainen <tss@iki.fi>
parents:
6686
diff
changeset
|
92 { |
11634
7f19062f58fd
Renamed fsync_disable to mail_fsync=optimized|always|never.
Timo Sirainen <tss@iki.fi>
parents:
11623
diff
changeset
|
93 index->fsync_mode = mode; |
7f19062f58fd
Renamed fsync_disable to mail_fsync=optimized|always|never.
Timo Sirainen <tss@iki.fi>
parents:
11623
diff
changeset
|
94 index->fsync_mask = mask; |
6736
3e189cbb7e7a
fsync transaction commits only if the transaction contains change types
Timo Sirainen <tss@iki.fi>
parents:
6686
diff
changeset
|
95 } |
3e189cbb7e7a
fsync transaction commits only if the transaction contains change types
Timo Sirainen <tss@iki.fi>
parents:
6686
diff
changeset
|
96 |
2650
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
97 void mail_index_set_permissions(struct mail_index *index, |
9537
b373de4973cd
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
9535
diff
changeset
|
98 mode_t mode, gid_t gid, const char *gid_origin) |
2650
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
99 { |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
100 index->mode = mode & 0666; |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
101 index->gid = gid; |
9537
b373de4973cd
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
9535
diff
changeset
|
102 |
b373de4973cd
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
9535
diff
changeset
|
103 i_free(index->gid_origin); |
b373de4973cd
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
9535
diff
changeset
|
104 index->gid_origin = i_strdup(gid_origin); |
2650
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
105 } |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
106 |
11623
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
107 void mail_index_set_lock_method(struct mail_index *index, |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
108 enum file_lock_method lock_method, |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
109 unsigned int max_timeout_secs) |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
110 { |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
111 index->lock_method = lock_method; |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
112 index->max_lock_timeout_secs = max_timeout_secs; |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
113 } |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
114 |
14079
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
115 void mail_index_set_ext_init_data(struct mail_index *index, uint32_t ext_id, |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
116 const void *data, size_t size) |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
117 { |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
118 const struct mail_index_registered_ext *rext; |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
119 |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
120 i_assert(index->ext_hdr_init_data == NULL || |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
121 index->ext_hdr_init_id == ext_id); |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
122 |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
123 rext = array_idx(&index->extensions, ext_id); |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
124 i_assert(rext->hdr_size == size); |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
125 |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
126 index->ext_hdr_init_id = ext_id; |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
127 i_free(index->ext_hdr_init_data); |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
128 index->ext_hdr_init_data = i_malloc(size); |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
129 memcpy(index->ext_hdr_init_data, data, size); |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
130 } |
2ab26bb55346
lib-index: Added mail_index_set_ext_init_data() for adding data to index on creation.
Timo Sirainen <tss@iki.fi>
parents:
13384
diff
changeset
|
131 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
132 uint32_t mail_index_ext_register(struct mail_index *index, const char *name, |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
133 uint32_t default_hdr_size, |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
134 uint16_t default_record_size, |
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
135 uint16_t default_record_align) |
2114
4aedcb4c51cb
Added support for per-index sized mail_index_record.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
136 { |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
137 struct mail_index_registered_ext rext; |
6679 | 138 uint32_t ext_id; |
2115
f720b3f15333
Modifying extra_records should work now.
Timo Sirainen <tss@iki.fi>
parents:
2114
diff
changeset
|
139 |
6871
f7ec019fd3f6
mail_index_ext_register(): Panic if parameters aren't correct.
Timo Sirainen <tss@iki.fi>
parents:
6857
diff
changeset
|
140 if (*name == '\0' || strcmp(name, str_sanitize(name, -1)) != 0) |
6384
2c8b1d487728
Make sure the extension name doesn't contain control characters. It most
Timo Sirainen <tss@iki.fi>
parents:
6378
diff
changeset
|
141 i_panic("mail_index_ext_register(%s): Invalid name", name); |
2c8b1d487728
Make sure the extension name doesn't contain control characters. It most
Timo Sirainen <tss@iki.fi>
parents:
6378
diff
changeset
|
142 |
7361
11eb0bd76299
mail_index_ext_register(): Allow registering an extension without record or
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
143 if (default_record_size != 0 && default_record_align == 0) { |
6871
f7ec019fd3f6
mail_index_ext_register(): Panic if parameters aren't correct.
Timo Sirainen <tss@iki.fi>
parents:
6857
diff
changeset
|
144 i_panic("mail_index_ext_register(%s): " |
7361
11eb0bd76299
mail_index_ext_register(): Allow registering an extension without record or
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
145 "Invalid record alignment", name); |
6871
f7ec019fd3f6
mail_index_ext_register(): Panic if parameters aren't correct.
Timo Sirainen <tss@iki.fi>
parents:
6857
diff
changeset
|
146 } |
f7ec019fd3f6
mail_index_ext_register(): Panic if parameters aren't correct.
Timo Sirainen <tss@iki.fi>
parents:
6857
diff
changeset
|
147 |
6679 | 148 if (mail_index_ext_lookup(index, name, &ext_id)) |
149 return ext_id; | |
2116 | 150 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
151 memset(&rext, 0, sizeof(rext)); |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
152 rext.name = p_strdup(index->extension_pool, name); |
6679 | 153 rext.index_idx = array_count(&index->extensions); |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
154 rext.hdr_size = default_hdr_size; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
155 rext.record_size = default_record_size; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
156 rext.record_align = default_record_align; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
157 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
158 array_append(&index->extensions, &rext, 1); |
6679 | 159 return rext.index_idx; |
160 } | |
161 | |
162 bool mail_index_ext_lookup(struct mail_index *index, const char *name, | |
163 uint32_t *ext_id_r) | |
164 { | |
165 const struct mail_index_registered_ext *extensions; | |
166 unsigned int i, count; | |
167 | |
168 extensions = array_get(&index->extensions, &count); | |
169 for (i = 0; i < count; i++) { | |
170 if (strcmp(extensions[i].name, name) == 0) { | |
171 *ext_id_r = i; | |
172 return TRUE; | |
173 } | |
174 } | |
175 | |
176 *ext_id_r = (uint32_t)-1; | |
177 return FALSE; | |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
178 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
179 |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
180 void mail_index_register_expunge_handler(struct mail_index *index, |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
181 uint32_t ext_id, bool call_always, |
4490
56d17f2e1d66
Added support for calling expunge handler for an extension even if the
Timo Sirainen <tss@iki.fi>
parents:
4453
diff
changeset
|
182 mail_index_expunge_handler_t *cb, |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
183 void *context) |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
184 { |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
185 struct mail_index_registered_ext *rext; |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
186 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4396
diff
changeset
|
187 rext = array_idx_modifiable(&index->extensions, ext_id); |
4616 | 188 i_assert(rext->expunge_handler == NULL || rext->expunge_handler == cb); |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
189 |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
190 rext->expunge_handler = cb; |
4490
56d17f2e1d66
Added support for calling expunge handler for an extension even if the
Timo Sirainen <tss@iki.fi>
parents:
4453
diff
changeset
|
191 rext->expunge_context = context; |
56d17f2e1d66
Added support for calling expunge handler for an extension even if the
Timo Sirainen <tss@iki.fi>
parents:
4453
diff
changeset
|
192 rext->expunge_handler_call_always = call_always; |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
193 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
194 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
195 void mail_index_unregister_expunge_handler(struct mail_index *index, |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
196 uint32_t ext_id) |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
197 { |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
198 struct mail_index_registered_ext *rext; |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
199 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4396
diff
changeset
|
200 rext = array_idx_modifiable(&index->extensions, ext_id); |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
201 i_assert(rext->expunge_handler != NULL); |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
202 |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
203 rext->expunge_handler = NULL; |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
204 } |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
205 |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
206 void mail_index_register_sync_handler(struct mail_index *index, uint32_t ext_id, |
2869
d2daf90c79f1
Cache invalidating needed to hook into view syncing as well.
Timo Sirainen <tss@iki.fi>
parents:
2857
diff
changeset
|
207 mail_index_sync_handler_t *cb, |
d2daf90c79f1
Cache invalidating needed to hook into view syncing as well.
Timo Sirainen <tss@iki.fi>
parents:
2857
diff
changeset
|
208 enum mail_index_sync_handler_type type) |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
209 { |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
210 struct mail_index_registered_ext *rext; |
2869
d2daf90c79f1
Cache invalidating needed to hook into view syncing as well.
Timo Sirainen <tss@iki.fi>
parents:
2857
diff
changeset
|
211 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4396
diff
changeset
|
212 rext = array_idx_modifiable(&index->extensions, ext_id); |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
213 i_assert(rext->sync_handler.callback == NULL); |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
214 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
215 rext->sync_handler.callback = cb; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
216 rext->sync_handler.type = type; |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
217 } |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
218 |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
219 void mail_index_unregister_sync_handler(struct mail_index *index, |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
220 uint32_t ext_id) |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
221 { |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
222 struct mail_index_registered_ext *rext; |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
223 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4396
diff
changeset
|
224 rext = array_idx_modifiable(&index->extensions, ext_id); |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
225 i_assert(rext->sync_handler.callback != NULL); |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
226 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
227 rext->sync_handler.callback = NULL; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
228 rext->sync_handler.type = 0; |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
229 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
230 |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
231 void mail_index_register_sync_lost_handler(struct mail_index *index, |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
232 mail_index_sync_lost_handler_t *cb) |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
233 { |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
234 array_append(&index->sync_lost_handlers, &cb, 1); |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
235 } |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
236 |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
237 void mail_index_unregister_sync_lost_handler(struct mail_index *index, |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
238 mail_index_sync_lost_handler_t *cb) |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
239 { |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
240 mail_index_sync_lost_handler_t *const *handlers; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
241 unsigned int i, count; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
242 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
243 handlers = array_get(&index->sync_lost_handlers, &count); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
244 for (i = 0; i < count; i++) { |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
245 if (handlers[i] == cb) { |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
246 array_delete(&index->sync_lost_handlers, i, 1); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
247 break; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
248 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
249 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
250 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
251 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
252 bool mail_index_keyword_lookup(struct mail_index *index, |
6335
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
253 const char *keyword, unsigned int *idx_r) |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
254 { |
14923
96fd2c3bf932
Reverted "support for non-pointers" part of the hash table API changes.
Timo Sirainen <tss@iki.fi>
parents:
14918
diff
changeset
|
255 char *key; |
96fd2c3bf932
Reverted "support for non-pointers" part of the hash table API changes.
Timo Sirainen <tss@iki.fi>
parents:
14918
diff
changeset
|
256 void *value; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
257 |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
258 /* keywords_hash keeps a name => index mapping of keywords. |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
259 Keywords are never removed from it, so the index values are valid |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
260 for the lifetime of the mail_index. */ |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
8572
diff
changeset
|
261 if (hash_table_lookup_full(index->keywords_hash, keyword, |
14629
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14231
diff
changeset
|
262 &key, &value)) { |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
263 *idx_r = POINTER_CAST_TO(value, unsigned int); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
264 return TRUE; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
265 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
266 |
15904
d3cf06639864
Replaced all -1U and (unsigned int)-1 with UINT_MAX.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
267 *idx_r = UINT_MAX; |
6335
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
268 return FALSE; |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
269 } |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
270 |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
271 void mail_index_keyword_lookup_or_create(struct mail_index *index, |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
272 const char *keyword, |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
273 unsigned int *idx_r) |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
274 { |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
275 char *keyword_dup; |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
276 |
6350
e7f61751822e
Added assert against empty keyword.
Timo Sirainen <tss@iki.fi>
parents:
6349
diff
changeset
|
277 i_assert(*keyword != '\0'); |
e7f61751822e
Added assert against empty keyword.
Timo Sirainen <tss@iki.fi>
parents:
6349
diff
changeset
|
278 |
6335
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
279 if (mail_index_keyword_lookup(index, keyword, idx_r)) |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
280 return; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
281 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
282 keyword = keyword_dup = p_strdup(index->keywords_pool, keyword); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
283 *idx_r = array_count(&index->keywords); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
284 |
14923
96fd2c3bf932
Reverted "support for non-pointers" part of the hash table API changes.
Timo Sirainen <tss@iki.fi>
parents:
14918
diff
changeset
|
285 hash_table_insert(index->keywords_hash, keyword_dup, |
96fd2c3bf932
Reverted "support for non-pointers" part of the hash table API changes.
Timo Sirainen <tss@iki.fi>
parents:
14918
diff
changeset
|
286 POINTER_CAST(*idx_r)); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
287 array_append(&index->keywords, &keyword, 1); |
13306
ba03935cc599
mail_index_get_keywords() / status.keywords weren't actually guaranteed to be NULL terminated
Timo Sirainen <tss@iki.fi>
parents:
12936
diff
changeset
|
288 |
ba03935cc599
mail_index_get_keywords() / status.keywords weren't actually guaranteed to be NULL terminated
Timo Sirainen <tss@iki.fi>
parents:
12936
diff
changeset
|
289 /* keep the array NULL-terminated, but the NULL itself invisible */ |
14686
9ff19c1d5f69
Added array_append_zero() to write a zero-filled record to an array.
Timo Sirainen <tss@iki.fi>
parents:
14682
diff
changeset
|
290 array_append_zero(&index->keywords); |
13306
ba03935cc599
mail_index_get_keywords() / status.keywords weren't actually guaranteed to be NULL terminated
Timo Sirainen <tss@iki.fi>
parents:
12936
diff
changeset
|
291 array_delete(&index->keywords, array_count(&index->keywords)-1, 1); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
292 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
293 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4396
diff
changeset
|
294 const ARRAY_TYPE(keywords) *mail_index_get_keywords(struct mail_index *index) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
295 { |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
296 return &index->keywords; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
297 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
298 |
9613
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
299 struct mail_keywords * |
9614
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
300 mail_index_keywords_create(struct mail_index *index, |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
301 const char *const keywords[]) |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
302 { |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
303 struct mail_keywords *k; |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
304 unsigned int src, dest, i, count; |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
305 |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
306 count = str_array_length(keywords); |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
307 if (count == 0) { |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
308 k = i_new(struct mail_keywords, 1); |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
309 k->index = index; |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
310 k->refcount = 1; |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
311 return k; |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
312 } |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
313 |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
314 /* @UNSAFE */ |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
315 k = i_malloc(sizeof(struct mail_keywords) + |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
316 (sizeof(k->idx) * (count-1))); |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
317 k->index = index; |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
318 k->refcount = 1; |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
319 |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
320 /* look up the keywords from index. they're never removed from there |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
321 so we can permanently store indexes to them. */ |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
322 for (src = dest = 0; src < count; src++) { |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
323 mail_index_keyword_lookup_or_create(index, keywords[src], |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
324 &k->idx[dest]); |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
325 /* ignore if this is a duplicate */ |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
326 for (i = 0; i < src; i++) { |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
327 if (k->idx[i] == k->idx[dest]) |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
328 break; |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
329 } |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
330 if (i == src) |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
331 dest++; |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
332 } |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
333 k->count = dest; |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
334 return k; |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
335 } |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
336 |
d670b5d66302
Previous commit accidentally removed mail_index_keywords_create().
Timo Sirainen <tss@iki.fi>
parents:
9613
diff
changeset
|
337 struct mail_keywords * |
9613
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
338 mail_index_keywords_create_from_indexes(struct mail_index *index, |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
339 const ARRAY_TYPE(keyword_indexes) |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
340 *keyword_indexes) |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
341 { |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
342 struct mail_keywords *k; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
343 const unsigned int *indexes; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
344 unsigned int src, dest, i, count; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
345 |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
346 indexes = array_get(keyword_indexes, &count); |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
347 if (count == 0) { |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
348 k = i_new(struct mail_keywords, 1); |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
349 k->index = index; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
350 k->refcount = 1; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
351 return k; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
352 } |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
353 |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
354 /* @UNSAFE */ |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
355 k = i_malloc(sizeof(struct mail_keywords) + |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
356 (sizeof(k->idx) * (count-1))); |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
357 k->index = index; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
358 k->refcount = 1; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
359 |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
360 /* copy but skip duplicates */ |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
361 for (src = dest = 0; src < count; src++) { |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
362 for (i = 0; i < src; i++) { |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
363 if (k->idx[i] == indexes[src]) |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
364 break; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
365 } |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
366 if (i == src) |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
367 k->idx[dest++] = indexes[src]; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
368 } |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
369 k->count = dest; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
370 return k; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
371 } |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
372 |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
373 void mail_index_keywords_ref(struct mail_keywords *keywords) |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
374 { |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
375 keywords->refcount++; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
376 } |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
377 |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
378 void mail_index_keywords_unref(struct mail_keywords **_keywords) |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
379 { |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
380 struct mail_keywords *keywords = *_keywords; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
381 |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
382 i_assert(keywords->refcount > 0); |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
383 |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
384 *_keywords = NULL; |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
385 if (--keywords->refcount == 0) |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
386 i_free(keywords); |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
387 } |
ed9b4bc28913
Moved mail_index_keywords_*() to mail-index.c.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
388 |
5686
0d2a6a7f2a1b
Moved mail index map related code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
5666
diff
changeset
|
389 int mail_index_try_open_only(struct mail_index *index) |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
390 { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
391 i_assert(index->fd == -1); |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
392 i_assert(!MAIL_INDEX_IS_IN_MEMORY(index)); |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
393 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
394 /* Note that our caller must close index->fd by itself. */ |
6686
610f3d9813b5
Added MAIL_INDEX_OPEN_FLAG_READONLY.
Timo Sirainen <tss@iki.fi>
parents:
6679
diff
changeset
|
395 if (index->readonly) |
610f3d9813b5
Added MAIL_INDEX_OPEN_FLAG_READONLY.
Timo Sirainen <tss@iki.fi>
parents:
6679
diff
changeset
|
396 errno = EACCES; |
610f3d9813b5
Added MAIL_INDEX_OPEN_FLAG_READONLY.
Timo Sirainen <tss@iki.fi>
parents:
6679
diff
changeset
|
397 else { |
610f3d9813b5
Added MAIL_INDEX_OPEN_FLAG_READONLY.
Timo Sirainen <tss@iki.fi>
parents:
6679
diff
changeset
|
398 index->fd = nfs_safe_open(index->filepath, O_RDWR); |
610f3d9813b5
Added MAIL_INDEX_OPEN_FLAG_READONLY.
Timo Sirainen <tss@iki.fi>
parents:
6679
diff
changeset
|
399 index->readonly = FALSE; |
610f3d9813b5
Added MAIL_INDEX_OPEN_FLAG_READONLY.
Timo Sirainen <tss@iki.fi>
parents:
6679
diff
changeset
|
400 } |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
401 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
402 if (index->fd == -1 && errno == EACCES) { |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
403 index->fd = open(index->filepath, O_RDONLY); |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
404 index->readonly = TRUE; |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
405 } |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
406 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
407 if (index->fd == -1) { |
14682
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
408 if (errno != ENOENT) { |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
409 mail_index_set_syscall_error(index, "open()"); |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
410 return -1; |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
411 } |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
412 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
413 /* have to create it */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
414 return 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
415 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
416 return 1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
417 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
418 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
419 static int |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
420 mail_index_try_open(struct mail_index *index) |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
421 { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
422 int ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
423 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
424 i_assert(index->fd == -1); |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
425 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
426 if (MAIL_INDEX_IS_IN_MEMORY(index)) |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
427 return 0; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
428 |
5854 | 429 ret = mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD); |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
430 if (ret == 0) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
431 /* it's corrupted - recreate it */ |
5820
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5819
diff
changeset
|
432 if (index->fd != -1) { |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5819
diff
changeset
|
433 if (close(index->fd) < 0) |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5819
diff
changeset
|
434 mail_index_set_syscall_error(index, "close()"); |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5819
diff
changeset
|
435 index->fd = -1; |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5819
diff
changeset
|
436 } |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
437 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
438 return ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
439 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
440 |
17904
0a34975b2dcc
lib-index: Added path parameter to mail_index_create_tmp_file()
Timo Sirainen <tss@iki.fi>
parents:
17900
diff
changeset
|
441 int mail_index_create_tmp_file(struct mail_index *index, |
0a34975b2dcc
lib-index: Added path parameter to mail_index_create_tmp_file()
Timo Sirainen <tss@iki.fi>
parents:
17900
diff
changeset
|
442 const char *path_prefix, const char **path_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
443 { |
2879
aa93c7216722
dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
444 mode_t old_mask; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
445 const char *path; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
446 int fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
447 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
448 i_assert(!MAIL_INDEX_IS_IN_MEMORY(index)); |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
449 |
17904
0a34975b2dcc
lib-index: Added path parameter to mail_index_create_tmp_file()
Timo Sirainen <tss@iki.fi>
parents:
17900
diff
changeset
|
450 path = *path_r = t_strconcat(path_prefix, ".tmp", NULL); |
2879
aa93c7216722
dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
451 old_mask = umask(0); |
12702
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
452 fd = open(path, O_RDWR|O_CREAT|O_EXCL, index->mode); |
2879
aa93c7216722
dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
453 umask(old_mask); |
12702
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
454 if (fd == -1 && errno == EEXIST) { |
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
455 /* stale temp file. unlink and recreate rather than overwriting, |
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
456 just to make sure locking problems won't cause corruption */ |
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
457 if (unlink(path) < 0) { |
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
458 i_error("unlink(%s) failed: %m", path); |
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
459 return -1; |
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
460 } |
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
461 old_mask = umask(0); |
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
462 fd = open(path, O_RDWR|O_CREAT|O_EXCL, index->mode); |
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
463 umask(old_mask); |
7ecc5e10da57
lib-index: Avoid corrupting dovecot.index file when recreating it even in case of broken file locking.
Timo Sirainen <tss@iki.fi>
parents:
12249
diff
changeset
|
464 } |
10686
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
465 if (fd == -1) { |
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
466 mail_index_file_set_syscall_error(index, path, "creat()"); |
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
467 return -1; |
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
468 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 |
9420
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
470 mail_index_fchown(index, fd, path); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
471 return fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
474 static int mail_index_open_files(struct mail_index *index, |
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
475 enum mail_index_open_flags flags) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
477 int ret; |
3582
bfa542369fdc
When creating a new index file, mark its log offsets so that the possibly
Timo Sirainen <tss@iki.fi>
parents:
3556
diff
changeset
|
478 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
479 ret = mail_transaction_log_open(index->log); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
480 if (ret == 0) { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
481 if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0) |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
482 return 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
483 |
5819 | 484 /* if dovecot.index exists, read it first so that we can get |
485 the correct indexid and log sequence */ | |
486 (void)mail_index_try_open(index); | |
487 | |
488 if (index->indexid == 0) { | |
6359
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
489 /* Create a new indexid for us. If we're opening index |
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
490 into memory, index->map doesn't exist yet. */ |
5819 | 491 index->indexid = ioloop_time; |
7573
de08cc81da73
Fixes to handling races in initial index creation.
Timo Sirainen <tss@iki.fi>
parents:
7361
diff
changeset
|
492 index->initial_create = TRUE; |
6359
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
493 if (index->map != NULL) |
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
494 index->map->hdr.indexid = index->indexid; |
5819 | 495 } |
496 | |
7573
de08cc81da73
Fixes to handling races in initial index creation.
Timo Sirainen <tss@iki.fi>
parents:
7361
diff
changeset
|
497 ret = mail_transaction_log_create(index->log, FALSE); |
9950
7aea0156986a
Avoid assert-crashing when two processes try to create index at the same time.
Timo Sirainen <tss@iki.fi>
parents:
9698
diff
changeset
|
498 if (index->map != NULL) { |
7aea0156986a
Avoid assert-crashing when two processes try to create index at the same time.
Timo Sirainen <tss@iki.fi>
parents:
9698
diff
changeset
|
499 /* log creation could have changed it if someone else |
7aea0156986a
Avoid assert-crashing when two processes try to create index at the same time.
Timo Sirainen <tss@iki.fi>
parents:
9698
diff
changeset
|
500 just created it. */ |
7aea0156986a
Avoid assert-crashing when two processes try to create index at the same time.
Timo Sirainen <tss@iki.fi>
parents:
9698
diff
changeset
|
501 index->map->hdr.indexid = index->indexid; |
7aea0156986a
Avoid assert-crashing when two processes try to create index at the same time.
Timo Sirainen <tss@iki.fi>
parents:
9698
diff
changeset
|
502 } |
7573
de08cc81da73
Fixes to handling races in initial index creation.
Timo Sirainen <tss@iki.fi>
parents:
7361
diff
changeset
|
503 index->initial_create = FALSE; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
504 } |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
505 if (ret >= 0) { |
7573
de08cc81da73
Fixes to handling races in initial index creation.
Timo Sirainen <tss@iki.fi>
parents:
7361
diff
changeset
|
506 ret = index->map != NULL ? 1 : mail_index_try_open(index); |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
507 if (ret == 0) { |
7573
de08cc81da73
Fixes to handling races in initial index creation.
Timo Sirainen <tss@iki.fi>
parents:
7361
diff
changeset
|
508 /* corrupted */ |
6322
8d9a156ec94e
Handle opening corrupted index files better.
Timo Sirainen <tss@iki.fi>
parents:
6321
diff
changeset
|
509 mail_transaction_log_close(index->log); |
7573
de08cc81da73
Fixes to handling races in initial index creation.
Timo Sirainen <tss@iki.fi>
parents:
7361
diff
changeset
|
510 ret = mail_transaction_log_create(index->log, TRUE); |
6359
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
511 if (ret == 0) { |
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
512 if (index->map != NULL) |
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
513 mail_index_unmap(&index->map); |
6322
8d9a156ec94e
Handle opening corrupted index files better.
Timo Sirainen <tss@iki.fi>
parents:
6321
diff
changeset
|
514 index->map = mail_index_map_alloc(index); |
6359
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
515 } |
2170 | 516 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
517 } |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
518 if (ret < 0) { |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
519 /* open/create failed, fallback to in-memory indexes */ |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
520 if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0) |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
521 return -1; |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
522 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
523 if (mail_index_move_to_memory(index) < 0) |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
524 return -1; |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
525 } |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
526 |
17900
6aeb2a7e5303
lib-index: Fixed cache file creation race condition.
Timo Sirainen <tss@iki.fi>
parents:
17579
diff
changeset
|
527 if (index->cache == NULL) |
6aeb2a7e5303
lib-index: Fixed cache file creation race condition.
Timo Sirainen <tss@iki.fi>
parents:
17579
diff
changeset
|
528 index->cache = mail_cache_open_or_create(index); |
13384
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
529 return 1; |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
530 } |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
531 |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
532 static int |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
533 mail_index_open_opened(struct mail_index *index, |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
534 enum mail_index_open_flags flags) |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
535 { |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
536 int ret; |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
537 |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
538 i_assert(index->map != NULL); |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
539 |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
540 if ((index->map->hdr.flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) { |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
541 /* index was marked corrupted. we'll probably need to |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
542 recreate the files. */ |
17464
203b3a6f508f
Removed pointless NULL checks.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
543 mail_index_unmap(&index->map); |
13384
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
544 mail_index_close_file(index); |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
545 mail_transaction_log_close(index->log); |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
546 if ((ret = mail_index_open_files(index, flags)) <= 0) |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
547 return ret; |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
548 } |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
549 |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
550 index->open_count++; |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
551 return 1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
552 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
553 |
11623
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
554 int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
555 { |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
556 int ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
557 |
10677
93fe3aa23bdb
lib-index: Don't close index files if they're still being used by another mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10674
diff
changeset
|
558 if (index->open_count > 0) { |
13384
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
559 if ((ret = mail_index_open_opened(index, flags)) <= 0) { |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
560 /* doesn't exist and create flag not used */ |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
561 } |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
562 return ret; |
2926
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
563 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
564 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
565 index->filepath = MAIL_INDEX_IS_IN_MEMORY(index) ? |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
566 i_strdup("(in-memory index)") : |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
567 i_strconcat(index->dir, "/", index->prefix, NULL); |
1967 | 568 |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
569 index->lock_type = F_UNLCK; |
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
570 index->lock_id_counter = 2; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
571 |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
572 index->readonly = FALSE; |
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
573 index->nodiskspace = FALSE; |
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
574 index->index_lock_timeout = FALSE; |
12249
41e99ee5c1dd
lib-index: Avoid unnecessary pread()s at end of transaction log file.
Timo Sirainen <tss@iki.fi>
parents:
12202
diff
changeset
|
575 index->log_sync_locked = FALSE; |
9696
126132cb1c19
index: Removed duplication of mail_index_open_flags from struct mail_index.
Timo Sirainen <tss@iki.fi>
parents:
9614
diff
changeset
|
576 index->flags = flags; |
6686
610f3d9813b5
Added MAIL_INDEX_OPEN_FLAG_READONLY.
Timo Sirainen <tss@iki.fi>
parents:
6679
diff
changeset
|
577 index->readonly = (flags & MAIL_INDEX_OPEN_FLAG_READONLY) != 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
578 |
9696
126132cb1c19
index: Removed duplication of mail_index_open_flags from struct mail_index.
Timo Sirainen <tss@iki.fi>
parents:
9614
diff
changeset
|
579 if ((flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0 && |
11634
7f19062f58fd
Renamed fsync_disable to mail_fsync=optimized|always|never.
Timo Sirainen <tss@iki.fi>
parents:
11623
diff
changeset
|
580 index->fsync_mode != FSYNC_MODE_ALWAYS) |
7f19062f58fd
Renamed fsync_disable to mail_fsync=optimized|always|never.
Timo Sirainen <tss@iki.fi>
parents:
11623
diff
changeset
|
581 i_fatal("nfs flush requires mail_fsync=always"); |
9696
126132cb1c19
index: Removed duplication of mail_index_open_flags from struct mail_index.
Timo Sirainen <tss@iki.fi>
parents:
9614
diff
changeset
|
582 if ((flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0 && |
126132cb1c19
index: Removed duplication of mail_index_open_flags from struct mail_index.
Timo Sirainen <tss@iki.fi>
parents:
9614
diff
changeset
|
583 (flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) == 0) |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
584 i_fatal("nfs flush requires mmap_disable=yes"); |
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
585 |
13384
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
586 /* NOTE: increase open_count only after mail_index_open_files(). |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
587 it's used elsewhere to check if we're doing an initial opening |
33dc66d4286d
lib-index: Fixed reopening index file that was marked as corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13379
diff
changeset
|
588 of the index files */ |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
589 if ((ret = mail_index_open_files(index, flags)) <= 0) { |
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
590 /* doesn't exist and create flag not used */ |
17579
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
591 mail_index_close_nonopened(index); |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
592 return ret; |
3824
3e756ea0474b
Comment updates, small cleanups and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
3819
diff
changeset
|
593 } |
12202
8af455e61dad
lib-index: Avoid refreshing transaction log immediately after it was opened.
Timo Sirainen <tss@iki.fi>
parents:
12009
diff
changeset
|
594 index->open_count++; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
595 |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
596 i_assert(index->map != NULL); |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
10655
diff
changeset
|
597 mail_index_alloc_cache_index_opened(index); |
6375
fc2f5607108d
fsck the index while it's being mapped.
Timo Sirainen <tss@iki.fi>
parents:
6372
diff
changeset
|
598 return 1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
599 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
600 |
8953
f80f26822262
Added mail_index_open_or_create().
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
601 int mail_index_open_or_create(struct mail_index *index, |
11623
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
602 enum mail_index_open_flags flags) |
8953
f80f26822262
Added mail_index_open_or_create().
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
603 { |
f80f26822262
Added mail_index_open_or_create().
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
604 int ret; |
f80f26822262
Added mail_index_open_or_create().
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
605 |
f80f26822262
Added mail_index_open_or_create().
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
606 flags |= MAIL_INDEX_OPEN_FLAG_CREATE; |
11623
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
10722
diff
changeset
|
607 ret = mail_index_open(index, flags); |
8953
f80f26822262
Added mail_index_open_or_create().
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
608 i_assert(ret != 0); |
f80f26822262
Added mail_index_open_or_create().
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
609 return ret < 0 ? -1 : 0; |
f80f26822262
Added mail_index_open_or_create().
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
610 } |
f80f26822262
Added mail_index_open_or_create().
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
611 |
6390
ff48b008150f
Fix ESTALE handling when reading main index.
Timo Sirainen <tss@iki.fi>
parents:
6384
diff
changeset
|
612 void mail_index_close_file(struct mail_index *index) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
613 { |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4795
diff
changeset
|
614 if (index->file_lock != NULL) |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4795
diff
changeset
|
615 file_lock_free(&index->file_lock); |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
616 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
617 if (index->fd != -1) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
618 if (close(index->fd) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
619 mail_index_set_syscall_error(index, "close()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
620 index->fd = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
621 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
622 |
5854 | 623 index->lock_id_counter += 2; |
6372
f33ea6ff46ea
Drop also exclusive locks when closing index files (there shouldn't be any
Timo Sirainen <tss@iki.fi>
parents:
6371
diff
changeset
|
624 index->lock_type = F_UNLCK; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
625 } |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
626 |
17579
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
627 static void mail_index_close_nonopened(struct mail_index *index) |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
628 { |
12762
74300385cce0
lib-index: Give better assert-crashes if view or log view isn't closed.
Timo Sirainen <tss@iki.fi>
parents:
12702
diff
changeset
|
629 i_assert(!index->syncing); |
17108
3f352534af56
lib-index: Keep track of views and transactions in linked lists.
Timo Sirainen <tss@iki.fi>
parents:
15904
diff
changeset
|
630 i_assert(index->views == NULL); |
12762
74300385cce0
lib-index: Give better assert-crashes if view or log view isn't closed.
Timo Sirainen <tss@iki.fi>
parents:
12702
diff
changeset
|
631 |
5827 | 632 if (index->map != NULL) |
5853
d9f319a9d6e0
mail_index_map now contains pointer to index, so all functions taking map
Timo Sirainen <tss@iki.fi>
parents:
5827
diff
changeset
|
633 mail_index_unmap(&index->map); |
5827 | 634 |
635 mail_index_close_file(index); | |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
636 mail_transaction_log_close(index->log); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
637 if (index->cache != NULL) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
638 mail_cache_free(&index->cache); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
639 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
640 i_free_and_null(index->filepath); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
641 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
642 index->indexid = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
643 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
644 |
17579
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
645 void mail_index_close(struct mail_index *index) |
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
646 { |
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
647 i_assert(index->open_count > 0); |
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
648 |
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
649 mail_index_alloc_cache_index_closing(index); |
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
650 if (--index->open_count == 0) |
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
651 mail_index_close_nonopened(index); |
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
652 } |
092137bd092b
lib-index: Fixed error handling in mail_index_open()
Timo Sirainen <tss@iki.fi>
parents:
17578
diff
changeset
|
653 |
9311 | 654 int mail_index_unlink(struct mail_index *index) |
655 { | |
656 const char *path; | |
657 int last_errno = 0; | |
658 | |
10006
a425ba46a64c
lib-index: Take MAIL_INDEX_OPEN_FLAG_READONLY more seriously.
Timo Sirainen <tss@iki.fi>
parents:
9950
diff
changeset
|
659 if (MAIL_INDEX_IS_IN_MEMORY(index) || index->readonly) |
9311 | 660 return 0; |
661 | |
662 /* main index */ | |
663 if (unlink(index->filepath) < 0 && errno != ENOENT) | |
664 last_errno = errno; | |
665 | |
666 /* logs */ | |
667 path = t_strconcat(index->filepath, MAIL_TRANSACTION_LOG_SUFFIX, NULL); | |
668 if (unlink(path) < 0 && errno != ENOENT) | |
669 last_errno = errno; | |
670 | |
671 path = t_strconcat(index->filepath, | |
672 MAIL_TRANSACTION_LOG_SUFFIX".2", NULL); | |
673 if (unlink(path) < 0 && errno != ENOENT) | |
674 last_errno = errno; | |
675 | |
676 /* cache */ | |
677 path = t_strconcat(index->filepath, MAIL_CACHE_FILE_SUFFIX, NULL); | |
678 if (unlink(path) < 0 && errno != ENOENT) | |
679 last_errno = errno; | |
680 | |
681 if (last_errno == 0) | |
682 return 0; | |
683 else { | |
684 errno = last_errno; | |
685 return -1; | |
686 } | |
687 } | |
688 | |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
689 int mail_index_reopen_if_changed(struct mail_index *index) |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
690 { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
691 struct stat st1, st2; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
692 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
693 if (MAIL_INDEX_IS_IN_MEMORY(index)) |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
694 return 0; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3231
diff
changeset
|
695 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
696 if (index->fd == -1) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
697 return mail_index_try_open_only(index); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
698 |
9696
126132cb1c19
index: Removed duplication of mail_index_open_flags from struct mail_index.
Timo Sirainen <tss@iki.fi>
parents:
9614
diff
changeset
|
699 if ((index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) |
6857 | 700 nfs_flush_file_handle_cache(index->filepath); |
6797
a59deefc552f
NFS attribute cache flushing fixes. nfs_flush_attr_cache() takes now
Timo Sirainen <tss@iki.fi>
parents:
6755
diff
changeset
|
701 if (nfs_safe_stat(index->filepath, &st2) < 0) { |
a59deefc552f
NFS attribute cache flushing fixes. nfs_flush_attr_cache() takes now
Timo Sirainen <tss@iki.fi>
parents:
6755
diff
changeset
|
702 if (errno == ENOENT) |
a59deefc552f
NFS attribute cache flushing fixes. nfs_flush_attr_cache() takes now
Timo Sirainen <tss@iki.fi>
parents:
6755
diff
changeset
|
703 return 0; |
14682
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
704 mail_index_set_syscall_error(index, "stat()"); |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
705 return -1; |
6797
a59deefc552f
NFS attribute cache flushing fixes. nfs_flush_attr_cache() takes now
Timo Sirainen <tss@iki.fi>
parents:
6755
diff
changeset
|
706 } |
a59deefc552f
NFS attribute cache flushing fixes. nfs_flush_attr_cache() takes now
Timo Sirainen <tss@iki.fi>
parents:
6755
diff
changeset
|
707 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
708 if (fstat(index->fd, &st1) < 0) { |
14682
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
709 if (!ESTALE_FSTAT(errno)) { |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
710 mail_index_set_syscall_error(index, "fstat()"); |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
711 return -1; |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
712 } |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
713 /* deleted/recreated, reopen */ |
6829
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6819
diff
changeset
|
714 } else if (st1.st_ino == st2.st_ino && |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6819
diff
changeset
|
715 CMP_DEV_T(st1.st_dev, st2.st_dev)) { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
716 /* the same file */ |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
717 return 1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
718 } |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
719 |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
720 /* new file, new locks. the old fd can keep its locks, they don't |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
721 matter anymore as no-one's going to modify the file. */ |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
722 mail_index_close_file(index); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
723 |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
724 return mail_index_try_open_only(index); |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
725 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
726 |
2936
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
727 int mail_index_refresh(struct mail_index *index) |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
728 { |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
729 int ret; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
730 |
5854 | 731 ret = mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD); |
2936
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
732 return ret <= 0 ? -1 : 0; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
733 } |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
734 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
735 struct mail_cache *mail_index_get_cache(struct mail_index *index) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
736 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
737 return index->cache; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
738 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
739 |
14682
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
740 void mail_index_set_error(struct mail_index *index, const char *fmt, ...) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
741 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
742 va_list va; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
743 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
744 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
745 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
746 if (fmt == NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
747 index->error = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
748 else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
749 va_start(va, fmt); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
750 index->error = i_strdup_vprintf(fmt, va); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
751 va_end(va); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
752 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
753 i_error("%s", index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
754 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
755 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
756 |
9099
67369ba9f447
maildir: When saving messages, in some race conditions we might have written a duplicate UID.
Timo Sirainen <tss@iki.fi>
parents:
8973
diff
changeset
|
757 bool mail_index_is_in_memory(struct mail_index *index) |
67369ba9f447
maildir: When saving messages, in some race conditions we might have written a duplicate UID.
Timo Sirainen <tss@iki.fi>
parents:
8973
diff
changeset
|
758 { |
67369ba9f447
maildir: When saving messages, in some race conditions we might have written a duplicate UID.
Timo Sirainen <tss@iki.fi>
parents:
8973
diff
changeset
|
759 return MAIL_INDEX_IS_IN_MEMORY(index); |
67369ba9f447
maildir: When saving messages, in some race conditions we might have written a duplicate UID.
Timo Sirainen <tss@iki.fi>
parents:
8973
diff
changeset
|
760 } |
67369ba9f447
maildir: When saving messages, in some race conditions we might have written a duplicate UID.
Timo Sirainen <tss@iki.fi>
parents:
8973
diff
changeset
|
761 |
3833
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
762 int mail_index_move_to_memory(struct mail_index *index) |
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
763 { |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
764 struct mail_index_map *map; |
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
765 |
4394
0462137fa4ce
mail_index_move_to_memory(): Don't break if the index is already in memory.
Timo Sirainen <tss@iki.fi>
parents:
4312
diff
changeset
|
766 if (MAIL_INDEX_IS_IN_MEMORY(index)) |
5430
c8bb83980ff7
If mail_index_move_to_memory() fails, make sure the future calls to it also
Timo Sirainen <tss@iki.fi>
parents:
5323
diff
changeset
|
767 return index->map == NULL ? -1 : 0; |
4394
0462137fa4ce
mail_index_move_to_memory(): Don't break if the index is already in memory.
Timo Sirainen <tss@iki.fi>
parents:
4312
diff
changeset
|
768 |
9696
126132cb1c19
index: Removed duplication of mail_index_open_flags from struct mail_index.
Timo Sirainen <tss@iki.fi>
parents:
9614
diff
changeset
|
769 if ((index->flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) != 0) |
8973
f295678cef1e
dbox: Make sure indexes are never moved to memory (in case of out-of-disk space).
Timo Sirainen <tss@iki.fi>
parents:
8960
diff
changeset
|
770 return -1; |
f295678cef1e
dbox: Make sure indexes are never moved to memory (in case of out-of-disk space).
Timo Sirainen <tss@iki.fi>
parents:
8960
diff
changeset
|
771 |
4919
d54145736f99
If mail_index_move_to_memory() was called before index file was opened, we
Timo Sirainen <tss@iki.fi>
parents:
4918
diff
changeset
|
772 /* set the index as being into memory */ |
d54145736f99
If mail_index_move_to_memory() was called before index file was opened, we
Timo Sirainen <tss@iki.fi>
parents:
4918
diff
changeset
|
773 i_free_and_null(index->dir); |
d54145736f99
If mail_index_move_to_memory() was called before index file was opened, we
Timo Sirainen <tss@iki.fi>
parents:
4918
diff
changeset
|
774 |
5274
7641e625fbd5
When moving index file to memory, change the filename to be "(in-memory
Timo Sirainen <tss@iki.fi>
parents:
5273
diff
changeset
|
775 i_free(index->filepath); |
7641e625fbd5
When moving index file to memory, change the filename to be "(in-memory
Timo Sirainen <tss@iki.fi>
parents:
5273
diff
changeset
|
776 index->filepath = i_strdup("(in-memory index)"); |
7641e625fbd5
When moving index file to memory, change the filename to be "(in-memory
Timo Sirainen <tss@iki.fi>
parents:
5273
diff
changeset
|
777 |
3912
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
778 if (index->map == NULL) { |
5224 | 779 /* index was never even opened. just mark it as being in |
3912
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
780 memory and let the caller re-open the index. */ |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
781 i_assert(index->fd == -1); |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
782 return -1; |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
783 } |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
784 |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
785 /* move index map to memory */ |
5278
d569caa88a66
If we run out of disk space, move to in-memory indexes.
Timo Sirainen <tss@iki.fi>
parents:
5274
diff
changeset
|
786 if (!MAIL_INDEX_MAP_IS_IN_MEMORY(index->map)) { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
787 map = mail_index_map_clone(index->map); |
5853
d9f319a9d6e0
mail_index_map now contains pointer to index, so all functions taking map
Timo Sirainen <tss@iki.fi>
parents:
5827
diff
changeset
|
788 mail_index_unmap(&index->map); |
5278
d569caa88a66
If we run out of disk space, move to in-memory indexes.
Timo Sirainen <tss@iki.fi>
parents:
5274
diff
changeset
|
789 index->map = map; |
d569caa88a66
If we run out of disk space, move to in-memory indexes.
Timo Sirainen <tss@iki.fi>
parents:
5274
diff
changeset
|
790 } |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
791 |
4053
94b3363165c8
If transaction log opening fails, don't crash when trying to move it to
Timo Sirainen <tss@iki.fi>
parents:
4026
diff
changeset
|
792 if (index->log != NULL) { |
94b3363165c8
If transaction log opening fails, don't crash when trying to move it to
Timo Sirainen <tss@iki.fi>
parents:
4026
diff
changeset
|
793 /* move transaction log to memory */ |
5714
dcf5dbb6a76a
mail_transaction_log_move_to_memory() can't fail anymore. Moved the code to
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
794 mail_transaction_log_move_to_memory(index->log); |
4053
94b3363165c8
If transaction log opening fails, don't crash when trying to move it to
Timo Sirainen <tss@iki.fi>
parents:
4026
diff
changeset
|
795 } |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
796 |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4795
diff
changeset
|
797 if (index->file_lock != NULL) |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4795
diff
changeset
|
798 file_lock_free(&index->file_lock); |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4795
diff
changeset
|
799 |
6022
8da2881df0dc
mail_index_move_to_memory(): Don't log an error if index fd is already closed
Timo Sirainen <tss@iki.fi>
parents:
5976
diff
changeset
|
800 if (index->fd != -1) { |
8da2881df0dc
mail_index_move_to_memory(): Don't log an error if index fd is already closed
Timo Sirainen <tss@iki.fi>
parents:
5976
diff
changeset
|
801 if (close(index->fd) < 0) |
8da2881df0dc
mail_index_move_to_memory(): Don't log an error if index fd is already closed
Timo Sirainen <tss@iki.fi>
parents:
5976
diff
changeset
|
802 mail_index_set_syscall_error(index, "close()"); |
8da2881df0dc
mail_index_move_to_memory(): Don't log an error if index fd is already closed
Timo Sirainen <tss@iki.fi>
parents:
5976
diff
changeset
|
803 index->fd = -1; |
8da2881df0dc
mail_index_move_to_memory(): Don't log an error if index fd is already closed
Timo Sirainen <tss@iki.fi>
parents:
5976
diff
changeset
|
804 } |
5714
dcf5dbb6a76a
mail_transaction_log_move_to_memory() can't fail anymore. Moved the code to
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
805 return 0; |
3833
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
806 } |
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
807 |
1945 | 808 void mail_index_mark_corrupted(struct mail_index *index) |
1943 | 809 { |
5820
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5819
diff
changeset
|
810 index->indexid = 0; |
1945 | 811 |
5772
002aa9bbfcb2
Removed index->hdr. Use index->map->hdr instead.
Timo Sirainen <tss@iki.fi>
parents:
5714
diff
changeset
|
812 index->map->hdr.flags |= MAIL_INDEX_HDR_FLAG_CORRUPTED; |
10006
a425ba46a64c
lib-index: Take MAIL_INDEX_OPEN_FLAG_READONLY more seriously.
Timo Sirainen <tss@iki.fi>
parents:
9950
diff
changeset
|
813 if (!index->readonly) { |
a425ba46a64c
lib-index: Take MAIL_INDEX_OPEN_FLAG_READONLY more seriously.
Timo Sirainen <tss@iki.fi>
parents:
9950
diff
changeset
|
814 if (unlink(index->filepath) < 0 && |
a425ba46a64c
lib-index: Take MAIL_INDEX_OPEN_FLAG_READONLY more seriously.
Timo Sirainen <tss@iki.fi>
parents:
9950
diff
changeset
|
815 errno != ENOENT && errno != ESTALE) |
a425ba46a64c
lib-index: Take MAIL_INDEX_OPEN_FLAG_READONLY more seriously.
Timo Sirainen <tss@iki.fi>
parents:
9950
diff
changeset
|
816 mail_index_set_syscall_error(index, "unlink()"); |
13379
7b240ecc37b5
lib-index: When marking index corrupted, delete also transaction log file.
Timo Sirainen <tss@iki.fi>
parents:
13327
diff
changeset
|
817 (void)mail_transaction_log_unlink(index->log); |
10006
a425ba46a64c
lib-index: Take MAIL_INDEX_OPEN_FLAG_READONLY more seriously.
Timo Sirainen <tss@iki.fi>
parents:
9950
diff
changeset
|
818 } |
1943 | 819 } |
820 | |
10655
fc0ac73f0b36
Added support for marking mailbox index deleted. Don't allow any changes after that.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
821 bool mail_index_is_deleted(struct mail_index *index) |
fc0ac73f0b36
Added support for marking mailbox index deleted. Don't allow any changes after that.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
822 { |
10674
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
823 return index->index_delete_requested || index->index_deleted; |
10655
fc0ac73f0b36
Added support for marking mailbox index deleted. Don't allow any changes after that.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
824 } |
fc0ac73f0b36
Added support for marking mailbox index deleted. Don't allow any changes after that.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
825 |
10722
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
826 int mail_index_get_modification_time(struct mail_index *index, time_t *mtime_r) |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
827 { |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
828 struct stat st; |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
829 |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
830 if (mail_transaction_log_get_mtime(index->log, mtime_r) < 0) |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
831 return -1; |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
832 |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
833 if (*mtime_r == 0) { |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
834 if (stat(index->filepath, &st) < 0) { |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
835 mail_index_set_syscall_error(index, "stat()"); |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
836 return -1; |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
837 } |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
838 *mtime_r = st.st_mtime; |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
839 } |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
840 return 0; |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
841 } |
31aca1df525b
lib-index: Added mail_index_get_modification_time().
Timo Sirainen <tss@iki.fi>
parents:
10686
diff
changeset
|
842 |
9420
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
843 void mail_index_fchown(struct mail_index *index, int fd, const char *path) |
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
844 { |
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
845 mode_t mode; |
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
846 |
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
847 if (index->gid == (gid_t)-1) { |
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
848 /* no gid changing */ |
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
849 return; |
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
850 } else if (fchown(fd, (uid_t)-1, index->gid) == 0) { |
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
851 /* success */ |
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
852 return; |
9421
14ed9ca980d1
More group permission handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
9420
diff
changeset
|
853 } if ((index->mode & 0060) >> 3 == (index->mode & 0006)) { |
14ed9ca980d1
More group permission handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
9420
diff
changeset
|
854 /* group and world permissions are the same, so group doesn't |
14ed9ca980d1
More group permission handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
9420
diff
changeset
|
855 really matter. ignore silently. */ |
9420
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
856 return; |
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
857 } |
9698
37bdd5ce828f
mail_index_chown(): Check for fchown() failing with EPERM, not EACCES.
Timo Sirainen <tss@iki.fi>
parents:
9696
diff
changeset
|
858 if (errno != EPERM) |
9537
b373de4973cd
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
9535
diff
changeset
|
859 mail_index_file_set_syscall_error(index, path, "fchown()"); |
b373de4973cd
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
9535
diff
changeset
|
860 else { |
b373de4973cd
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
9535
diff
changeset
|
861 mail_index_set_error(index, "%s", |
b373de4973cd
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
9535
diff
changeset
|
862 eperm_error_get_chgrp("fchown", path, index->gid, |
b373de4973cd
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
9535
diff
changeset
|
863 index->gid_origin)); |
b373de4973cd
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
9535
diff
changeset
|
864 } |
9421
14ed9ca980d1
More group permission handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
9420
diff
changeset
|
865 |
14ed9ca980d1
More group permission handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
9420
diff
changeset
|
866 /* continue, but change permissions so that only the common |
14ed9ca980d1
More group permission handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
9420
diff
changeset
|
867 subset of group and world is used. this makes sure no one |
14ed9ca980d1
More group permission handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
9420
diff
changeset
|
868 gets any extra permissions. */ |
14ed9ca980d1
More group permission handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
9420
diff
changeset
|
869 mode = ((index->mode & 0060) >> 3) & (index->mode & 0006); |
14ed9ca980d1
More group permission handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
9420
diff
changeset
|
870 mode |= (mode << 3) | (index->mode & 0600); |
14ed9ca980d1
More group permission handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
9420
diff
changeset
|
871 if (fchmod(fd, mode) < 0) |
14ed9ca980d1
More group permission handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
9420
diff
changeset
|
872 mail_index_file_set_syscall_error(index, path, "fchmod()"); |
9420
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
873 } |
c496f137c843
index: Handle better errors where a new file's group can't be changed.
Timo Sirainen <tss@iki.fi>
parents:
9394
diff
changeset
|
874 |
14682
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
875 void mail_index_set_syscall_error(struct mail_index *index, |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
876 const char *function) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
877 { |
14682
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
878 mail_index_file_set_syscall_error(index, index->filepath, function); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
879 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
880 |
14682
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
881 void mail_index_file_set_syscall_error(struct mail_index *index, |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
882 const char *filepath, |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
883 const char *function) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
884 { |
10686
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
885 const char *errstr; |
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
886 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
887 i_assert(filepath != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
888 i_assert(function != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
889 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
890 if (ENOSPACE(errno)) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
891 index->nodiskspace = TRUE; |
9696
126132cb1c19
index: Removed duplication of mail_index_open_flags from struct mail_index.
Timo Sirainen <tss@iki.fi>
parents:
9614
diff
changeset
|
892 if ((index->flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) == 0) |
14682
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
893 return; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
894 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
895 |
9535
bbe4c24faf21
Use eacces_get_error() in more places for handling EACCES errors.
Timo Sirainen <tss@iki.fi>
parents:
9421
diff
changeset
|
896 if (errno == EACCES) { |
10686
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
897 function = t_strcut(function, '('); |
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
898 if (strcmp(function, "creat") == 0 || |
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
899 strncmp(function, "file_dotlock_", 13) == 0) |
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
900 errstr = eacces_error_get_creating(function, filepath); |
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
901 else |
442c980d6221
lib-index: Fixed logging file creation EACCES failures.
Timo Sirainen <tss@iki.fi>
parents:
10677
diff
changeset
|
902 errstr = eacces_error_get(function, filepath); |
14682
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
903 mail_index_set_error(index, "%s", errstr); |
9535
bbe4c24faf21
Use eacces_get_error() in more places for handling EACCES errors.
Timo Sirainen <tss@iki.fi>
parents:
9421
diff
changeset
|
904 } else { |
12009
706f30fa4028
lib-index: Give a clearer error message for syscall failing with EFBIG.
Timo Sirainen <tss@iki.fi>
parents:
12008
diff
changeset
|
905 const char *suffix = errno != EFBIG ? "" : |
706f30fa4028
lib-index: Give a clearer error message for syscall failing with EFBIG.
Timo Sirainen <tss@iki.fi>
parents:
12008
diff
changeset
|
906 " (process was started with ulimit -f limit)"; |
14682
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
907 mail_index_set_error(index, "%s failed with file %s: " |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
908 "%m%s", function, filepath, suffix); |
9535
bbe4c24faf21
Use eacces_get_error() in more places for handling EACCES errors.
Timo Sirainen <tss@iki.fi>
parents:
9421
diff
changeset
|
909 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
910 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
911 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
912 const char *mail_index_get_error_message(struct mail_index *index) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
913 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
914 return index->error; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
915 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
916 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
917 void mail_index_reset_error(struct mail_index *index) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
918 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
919 if (index->error != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
920 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
921 index->error = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
922 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
923 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
924 index->nodiskspace = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
925 index->index_lock_timeout = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
926 } |