Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-index/mail-index.c @ 6371:8468e3babea2 HEAD
NFS: If index has been deleted, close the index properly before reopening it.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 15 Sep 2007 08:54:09 +0300 |
parents | c54c07f30a97 |
children | f33ea6ff46ea |
rev | line source |
---|---|
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* Copyright (C) 2003-2004 Timo Sirainen */ |
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" |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
7 #include "hash.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #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
|
9 #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
|
10 #include "read-full.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "write-full.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "mail-index-private.h" |
5272
82b4a055e109
mmap_disable=yes crashes with recent changes.
Timo Sirainen <tss@iki.fi>
parents:
5247
diff
changeset
|
13 #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
|
14 #include "mail-index-sync-private.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 #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
|
16 #include "mail-cache.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 #include <stdio.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 #include <stddef.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 #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
|
21 #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
|
22 |
5453
a0a1432bb4e8
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5430
diff
changeset
|
23 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
|
24 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 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
|
26 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 struct mail_index *index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 index = i_new(struct mail_index, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 index->dir = i_strdup(dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 index->prefix = i_strdup(prefix); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 index->fd = -1; |
2116 | 33 |
5028 | 34 index->extension_pool = |
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 index->mode = 0600; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 index->gid = (gid_t)-1; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
43 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
44 index->keywords_ext_id = |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
45 mail_index_ext_register(index, "keywords", 128, 2, 1); |
3086 | 46 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
|
47 i_array_init(&index->keywords, 16); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
48 index->keywords_hash = |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
49 hash_create(default_pool, index->keywords_pool, 0, |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
50 strcase_hash, (hash_cmp_callback_t *)strcasecmp); |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
51 index->log = mail_transaction_log_alloc(index); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 return index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
55 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
|
56 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
57 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
|
58 |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
59 *_index = NULL; |
1967 | 60 mail_index_close(index); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
61 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
62 mail_transaction_log_free(&index->log); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
63 hash_destroy(index->keywords_hash); |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
64 pool_unref(index->extension_pool); |
3086 | 65 pool_unref(index->keywords_pool); |
1967 | 66 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 i_free(index->dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 i_free(index->prefix); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 i_free(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 |
2650
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
77 void mail_index_set_permissions(struct mail_index *index, |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
78 mode_t mode, gid_t gid) |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
79 { |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
80 index->mode = mode & 0666; |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
81 index->gid = gid; |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
82 } |
9b78674428f5
Get index file mode and GID from dovecot-shared file.
Timo Sirainen <tss@iki.fi>
parents:
2618
diff
changeset
|
83 |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 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
|
88 { |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
89 const struct mail_index_registered_ext *extensions; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
90 struct mail_index_registered_ext rext; |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
91 unsigned int i, ext_count; |
2115
f720b3f15333
Modifying extra_records should work now.
Timo Sirainen <tss@iki.fi>
parents:
2114
diff
changeset
|
92 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
93 extensions = array_get(&index->extensions, &ext_count); |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
94 |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
95 /* see if it's already there */ |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
96 for (i = 0; i < ext_count; i++) { |
2683
d41c42a7bf1e
Index extensions can now specify record alignment, and it's possible to
Timo Sirainen <tss@iki.fi>
parents:
2671
diff
changeset
|
97 if (strcmp(extensions[i].name, name) == 0) |
2116 | 98 return i; |
99 } | |
100 | |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
101 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
|
102 rext.name = p_strdup(index->extension_pool, name); |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
103 rext.index_idx = ext_count; |
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
108 array_append(&index->extensions, &rext, 1); |
2671
3b70ddb51771
Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents:
2660
diff
changeset
|
109 return ext_count; |
2563
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
110 } |
5752e5ac88f0
Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents:
2553
diff
changeset
|
111 |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 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
|
116 { |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
117 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
|
118 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4396
diff
changeset
|
119 rext = array_idx_modifiable(&index->extensions, ext_id); |
4616 | 120 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
|
121 |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
126 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
127 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
|
128 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
|
129 { |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
130 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
|
131 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4396
diff
changeset
|
132 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
|
133 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
|
134 |
3817
dc560ef2654b
Moved expunge handlers to mail_index_registered_ext.
Timo Sirainen <tss@iki.fi>
parents:
3816
diff
changeset
|
135 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
|
136 } |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
137 |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 { |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
142 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
|
143 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4396
diff
changeset
|
144 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
|
145 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
|
146 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
147 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
|
148 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
|
149 } |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2825
diff
changeset
|
150 |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
151 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
|
152 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
|
153 { |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
154 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
|
155 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4396
diff
changeset
|
156 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
|
157 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
|
158 |
3816
575c79a0aabc
Cleanup: Created mail_index_registered_ext which is used for
Timo Sirainen <tss@iki.fi>
parents:
3582
diff
changeset
|
159 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
|
160 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
|
161 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
162 |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
163 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
|
164 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
|
165 { |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3179
diff
changeset
|
166 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
|
167 } |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2926
diff
changeset
|
168 |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
169 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
|
170 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
|
171 { |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
172 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
|
173 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
|
174 |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
175 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
|
176 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
|
177 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
|
178 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
|
179 break; |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
180 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
181 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
182 } |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3222
diff
changeset
|
183 |
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
|
184 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
|
185 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
|
186 { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
187 void *value; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
188 |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
189 /* keywords_hash keeps a name => index mapping of keywords. |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
190 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
|
191 for the lifetime of the mail_index. */ |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
192 if (hash_lookup_full(index->keywords_hash, keyword, NULL, &value)) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
193 *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
|
194 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
|
195 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
196 |
6335
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
197 *idx_r = (unsigned int)-1; |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
198 return FALSE; |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
199 } |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
200 |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
201 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
|
202 const char *keyword, |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
203 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
|
204 { |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
205 char *keyword_dup; |
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
206 |
6350
e7f61751822e
Added assert against empty keyword.
Timo Sirainen <tss@iki.fi>
parents:
6349
diff
changeset
|
207 i_assert(*keyword != '\0'); |
e7f61751822e
Added assert against empty keyword.
Timo Sirainen <tss@iki.fi>
parents:
6349
diff
changeset
|
208 |
6335
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
209 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
|
210 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
|
211 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
212 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
|
213 *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
|
214 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
215 hash_insert(index->keywords_hash, keyword_dup, POINTER_CAST(*idx_r)); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
216 array_append(&index->keywords, &keyword, 1); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
217 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
218 |
5853
d9f319a9d6e0
mail_index_map now contains pointer to index, so all functions taking map
Timo Sirainen <tss@iki.fi>
parents:
5827
diff
changeset
|
219 int mail_index_map_parse_keywords(struct mail_index_map *map) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
220 { |
5853
d9f319a9d6e0
mail_index_map now contains pointer to index, so all functions taking map
Timo Sirainen <tss@iki.fi>
parents:
5827
diff
changeset
|
221 struct mail_index *index = map->index; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
222 const struct mail_index_ext *ext; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
223 const struct mail_index_keyword_header *kw_hdr; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
224 const struct mail_index_keyword_header_rec *kw_rec; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
225 const char *name; |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
226 unsigned int i, name_area_end_offset, old_count; |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6341
diff
changeset
|
227 uint32_t idx; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
228 |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6341
diff
changeset
|
229 if (!mail_index_map_lookup_ext(map, "keywords", &idx)) { |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
230 if (array_is_created(&map->keyword_idx_map)) |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
231 array_clear(&map->keyword_idx_map); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
232 return 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
233 } |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6341
diff
changeset
|
234 ext = array_idx(&map->extensions, idx); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
235 |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
236 /* Extension header contains: |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
237 - struct mail_index_keyword_header |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
238 - struct mail_index_keyword_header_rec * keywords_count |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
239 - const char names[] * keywords_count |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
240 */ |
4220 | 241 i_assert(ext->hdr_offset < map->hdr.header_size); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
242 kw_hdr = CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
243 kw_rec = (const void *)(kw_hdr + 1); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
244 name = (const char *)(kw_rec + kw_hdr->keywords_count); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
245 |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
246 old_count = !array_is_created(&map->keyword_idx_map) ? 0 : |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
247 array_count(&map->keyword_idx_map); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
248 |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
249 /* Keywords can only be added into same mapping. Removing requires a |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
250 new mapping (recreating the index file) */ |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
251 if (kw_hdr->keywords_count == old_count) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
252 /* nothing changed */ |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
253 return 0; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
254 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
255 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
256 /* make sure the header is valid */ |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
257 if (kw_hdr->keywords_count < old_count) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
258 mail_index_set_error(index, "Corrupted index file %s: " |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
259 "Keywords removed unexpectedly", |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
260 index->filepath); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
261 return -1; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
262 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
263 |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
264 if ((size_t)(name - (const char *)kw_hdr) > ext->hdr_size) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
265 mail_index_set_error(index, "Corrupted index file %s: " |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
266 "keywords_count larger than header size", |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
267 index->filepath); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
268 return -1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
269 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
270 |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
271 name_area_end_offset = (const char *)kw_hdr + ext->hdr_size - name; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
272 for (i = 0; i < kw_hdr->keywords_count; i++) { |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
273 if (kw_rec[i].name_offset > name_area_end_offset) { |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
274 mail_index_set_error(index, "Corrupted index file %s: " |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
275 "name_offset points outside allocated header", |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
276 index->filepath); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
277 return -1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
278 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
279 } |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
280 if (name[name_area_end_offset-1] != '\0') { |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
281 mail_index_set_error(index, "Corrupted index file %s: " |
3550 | 282 "Keyword header doesn't end with NUL", |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
283 index->filepath); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
284 return -1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
285 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
286 |
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 /* create file -> index mapping */ |
4596
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
288 if (!array_is_created(&map->keyword_idx_map)) |
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
289 i_array_init(&map->keyword_idx_map, kw_hdr->keywords_count); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
290 |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
291 #ifdef DEBUG |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
292 /* Check that existing headers are still the same. It's behind DEBUG |
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
293 since it's pretty useless waste of CPU normally. */ |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
294 for (i = 0; i < array_count(&map->keyword_idx_map); i++) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
295 const char *keyword = name + kw_rec[i].name_offset; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
296 const unsigned int *old_idx; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
297 unsigned int idx; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
298 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
299 old_idx = array_idx(&map->keyword_idx_map, i); |
6335
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
300 if (!mail_index_keyword_lookup(index, keyword, &idx) || |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
301 idx != *old_idx) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
302 mail_index_set_error(index, "Corrupted index file %s: " |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
303 "Keywords changed unexpectedly", |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
304 index->filepath); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
305 return -1; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
306 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
307 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
308 #endif |
3818
6758c0f3c318
Comment updates and minor cleanups
Timo Sirainen <tss@iki.fi>
parents:
3817
diff
changeset
|
309 /* Register the newly seen keywords */ |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
310 i = array_count(&map->keyword_idx_map); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
311 for (; i < kw_hdr->keywords_count; i++) { |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
312 const char *keyword = name + kw_rec[i].name_offset; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
313 unsigned int idx; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
314 |
6321 | 315 if (*keyword == '\0') { |
316 mail_index_set_error(index, "Corrupted index file %s: " | |
6330 | 317 "Empty keyword name in header", |
318 index->filepath); | |
6321 | 319 return -1; |
320 } | |
6335
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6330
diff
changeset
|
321 mail_index_keyword_lookup_or_create(index, keyword, &idx); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
322 array_append(&map->keyword_idx_map, &idx, 1); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
323 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
324 return 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
325 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
326 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4396
diff
changeset
|
327 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
|
328 { |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
329 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
|
330 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2956
diff
changeset
|
331 |
5686
0d2a6a7f2a1b
Moved mail index map related code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
5666
diff
changeset
|
332 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
|
333 { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
334 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
|
335 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
|
336 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
337 /* Note that our caller must close index->fd by itself. */ |
4071
cd3d26cf124a
Renamed safe-open.* to nfs-workarounds.*, safe_open() to nfs_safe_open() and
Timo Sirainen <tss@iki.fi>
parents:
4067
diff
changeset
|
338 index->fd = nfs_safe_open(index->filepath, O_RDWR); |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
339 index->readonly = FALSE; |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
340 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
341 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
|
342 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
|
343 index->readonly = TRUE; |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
344 } |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
345 |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
346 if (index->fd == -1) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
347 if (errno != ENOENT) |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
348 return mail_index_set_syscall_error(index, "open()"); |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
349 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
350 /* have to create it */ |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
351 return 0; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
352 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
353 return 1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
354 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
355 |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
356 static int |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
357 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
|
358 { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
359 int ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
360 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
361 i_assert(index->fd == -1); |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
362 |
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
|
363 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
|
364 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
|
365 |
6165
6418139447fa
Created a new struct mail_index_record_map which can be shared by multiple
Timo Sirainen <tss@iki.fi>
parents:
6022
diff
changeset
|
366 i_assert(index->map == NULL || index->map->rec_map->lock_id == 0); |
5854 | 367 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
|
368 if (ret == 0) { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
369 /* it's corrupted - recreate it */ |
5820
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5819
diff
changeset
|
370 if (index->fd != -1) { |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5819
diff
changeset
|
371 if (close(index->fd) < 0) |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5819
diff
changeset
|
372 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
|
373 index->fd = -1; |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5819
diff
changeset
|
374 } |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
375 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
376 return ret; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
377 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
378 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
379 int mail_index_create_tmp_file(struct mail_index *index, const char **path_r) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 { |
2879
aa93c7216722
dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
381 mode_t old_mask; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 const char *path; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 int fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 |
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
|
385 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
|
386 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
387 path = *path_r = t_strconcat(index->filepath, ".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
|
388 old_mask = umask(0); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 fd = open(path, O_RDWR|O_CREAT|O_TRUNC, 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
|
390 umask(old_mask); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 if (fd == -1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 return mail_index_file_set_syscall_error(index, path, "open()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
393 |
2879
aa93c7216722
dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
394 if (index->gid != (gid_t)-1 && fchown(fd, (uid_t)-1, index->gid) < 0) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
395 mail_index_file_set_syscall_error(index, path, "fchown()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
396 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
398 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
399 return fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
400 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
401 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
402 static bool mail_index_open_files(struct mail_index *index, |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
403 enum mail_index_open_flags flags) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
404 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 int ret; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
406 bool created = FALSE; |
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
|
407 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
408 ret = mail_transaction_log_open(index->log); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
409 if (ret == 0) { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
410 if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
411 return FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 |
5819 | 413 /* if dovecot.index exists, read it first so that we can get |
414 the correct indexid and log sequence */ | |
415 (void)mail_index_try_open(index); | |
416 | |
417 if (index->indexid == 0) { | |
6359
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
418 /* 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
|
419 into memory, index->map doesn't exist yet. */ |
5819 | 420 index->indexid = ioloop_time; |
6359
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
421 if (index->map != NULL) |
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
422 index->map->hdr.indexid = index->indexid; |
5819 | 423 } |
424 | |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
425 ret = mail_transaction_log_create(index->log); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
426 created = TRUE; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
427 } |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
428 if (ret >= 0) { |
5819 | 429 ret = index->map != NULL ? 0 : mail_index_try_open(index); |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
430 if (ret == 0) { |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
431 /* doesn't exist / corrupted */ |
6322
8d9a156ec94e
Handle opening corrupted index files better.
Timo Sirainen <tss@iki.fi>
parents:
6321
diff
changeset
|
432 mail_transaction_log_close(index->log); |
8d9a156ec94e
Handle opening corrupted index files better.
Timo Sirainen <tss@iki.fi>
parents:
6321
diff
changeset
|
433 ret = mail_transaction_log_create(index->log); |
6359
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
434 if (ret == 0) { |
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
435 if (index->map != NULL) |
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
436 mail_index_unmap(&index->map); |
6322
8d9a156ec94e
Handle opening corrupted index files better.
Timo Sirainen <tss@iki.fi>
parents:
6321
diff
changeset
|
437 index->map = mail_index_map_alloc(index); |
6359
c54c07f30a97
Fixed opening indexes to memory.
Timo Sirainen <tss@iki.fi>
parents:
6350
diff
changeset
|
438 } |
2170 | 439 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
440 } |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
441 if (ret < 0) { |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
442 /* 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
|
443 if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
444 return FALSE; |
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
|
445 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
446 if (mail_index_move_to_memory(index) < 0) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
447 return FALSE; |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
448 } |
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
2193
diff
changeset
|
449 |
3129
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3105
diff
changeset
|
450 index->cache = created ? mail_cache_create(index) : |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3105
diff
changeset
|
451 mail_cache_open_or_create(index); |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
452 return TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
453 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
454 |
2723
12b503fbb8af
Replaced fcntl_locks_disable with lock_method, so it's now possible to use
Timo Sirainen <tss@iki.fi>
parents:
2715
diff
changeset
|
455 int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags, |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4795
diff
changeset
|
456 enum file_lock_method lock_method) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
457 { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
458 int i = 0, ret = 1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
459 |
2926
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
460 if (index->opened) { |
5772
002aa9bbfcb2
Removed index->hdr. Use index->map->hdr instead.
Timo Sirainen <tss@iki.fi>
parents:
5714
diff
changeset
|
461 if (index->map != NULL && |
002aa9bbfcb2
Removed index->hdr. Use index->map->hdr instead.
Timo Sirainen <tss@iki.fi>
parents:
5714
diff
changeset
|
462 (index->map->hdr.flags & |
002aa9bbfcb2
Removed index->hdr. Use index->map->hdr instead.
Timo Sirainen <tss@iki.fi>
parents:
5714
diff
changeset
|
463 MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) { |
2926
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
464 /* corrupted, reopen files */ |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
465 mail_index_close(index); |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
466 } else { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
467 i_assert(index->map != NULL); |
4067
96ae9c096bde
mail_index_open(): If index is already open, return 1 instead of 0 so the
Timo Sirainen <tss@iki.fi>
parents:
4053
diff
changeset
|
468 return 1; |
2926
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
469 } |
c035583b4839
Make sure index is reopened if it's marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
2922
diff
changeset
|
470 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
471 |
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
|
472 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
|
473 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
|
474 i_strconcat(index->dir, "/", index->prefix, NULL); |
1967 | 475 |
3824
3e756ea0474b
Comment updates, small cleanups and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
3819
diff
changeset
|
476 for (;;) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
477 index->shared_lock_count = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 index->excl_lock_count = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 index->lock_type = F_UNLCK; |
5854 | 480 index->lock_id_counter = 2; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
481 |
2723
12b503fbb8af
Replaced fcntl_locks_disable with lock_method, so it's now possible to use
Timo Sirainen <tss@iki.fi>
parents:
2715
diff
changeset
|
482 index->readonly = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
483 index->nodiskspace = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
484 index->index_lock_timeout = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
485 index->log_locked = FALSE; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
486 index->mmap_disable = |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
487 (flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) != 0; |
4968
1baf9dd3fc40
Added dotlock_use_excl setting.
Timo Sirainen <tss@iki.fi>
parents:
4919
diff
changeset
|
488 index->use_excl_dotlocks = |
1baf9dd3fc40
Added dotlock_use_excl setting.
Timo Sirainen <tss@iki.fi>
parents:
4919
diff
changeset
|
489 (flags & MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL) != 0; |
4918
2f9173e103fd
Added fsync_disable setting. Also added missing fsync()ing to dbox when
Timo Sirainen <tss@iki.fi>
parents:
4906
diff
changeset
|
490 index->fsync_disable = |
2f9173e103fd
Added fsync_disable setting. Also added missing fsync()ing to dbox when
Timo Sirainen <tss@iki.fi>
parents:
4906
diff
changeset
|
491 (flags & MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE) != 0; |
5972
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
492 index->nfs_flush = |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
493 (flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0; |
2723
12b503fbb8af
Replaced fcntl_locks_disable with lock_method, so it's now possible to use
Timo Sirainen <tss@iki.fi>
parents:
2715
diff
changeset
|
494 index->lock_method = lock_method; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
495 |
5976
3a19830ab7f6
Changed nfs setting conflict error handling
Timo Sirainen <tss@iki.fi>
parents:
5972
diff
changeset
|
496 if (index->nfs_flush && index->fsync_disable) |
3a19830ab7f6
Changed nfs setting conflict error handling
Timo Sirainen <tss@iki.fi>
parents:
5972
diff
changeset
|
497 i_fatal("nfs flush requires fsync_disable=no"); |
3a19830ab7f6
Changed nfs setting conflict error handling
Timo Sirainen <tss@iki.fi>
parents:
5972
diff
changeset
|
498 if (index->nfs_flush && !index->mmap_disable) |
3a19830ab7f6
Changed nfs setting conflict error handling
Timo Sirainen <tss@iki.fi>
parents:
5972
diff
changeset
|
499 i_fatal("nfs flush requires mmap_disable=yes"); |
5972
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
500 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
501 i_assert(!index->opened); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
502 if (!mail_index_open_files(index, flags)) { |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
503 /* doesn't exist and create flag not used */ |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
504 ret = 0; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
505 break; |
2940
0e1481357fbb
Changed assert() to friendly human readable message.
Timo Sirainen <tss@iki.fi>
parents:
2939
diff
changeset
|
506 } |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
507 i_assert(index->map != NULL); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
508 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
509 index->opened = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 if (index->fsck) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
511 index->fsck = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
512 ret = mail_index_fsck(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
513 if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
514 /* completely broken, reopen */ |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
515 if (i++ < 3) { |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
516 mail_index_close(index); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
517 continue; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
518 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
519 /* too many tries */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
520 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
521 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
522 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
523 break; |
3824
3e756ea0474b
Comment updates, small cleanups and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
3819
diff
changeset
|
524 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
525 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
526 if (ret <= 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
527 mail_index_close(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
528 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
529 i_assert(ret <= 0 || index->map != NULL); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
530 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
531 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
532 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
533 static 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
|
534 { |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4795
diff
changeset
|
535 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
|
536 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
|
537 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
538 if (index->fd != -1) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
539 if (close(index->fd) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
540 mail_index_set_syscall_error(index, "close()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
541 index->fd = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
542 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
543 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
544 if (index->lock_type == F_RDLCK) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
545 index->lock_type = F_UNLCK; |
5854 | 546 index->lock_id_counter += 2; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
547 index->shared_lock_count = 0; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
548 } |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
549 |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
550 void mail_index_close(struct mail_index *index) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
551 { |
5827 | 552 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
|
553 mail_index_unmap(&index->map); |
5827 | 554 |
555 mail_index_close_file(index); | |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
556 mail_transaction_log_close(index->log); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
557 if (index->cache != NULL) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
558 mail_cache_free(&index->cache); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
559 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
560 i_free_and_null(index->filepath); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
561 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
562 index->indexid = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
563 index->opened = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
564 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
565 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
566 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
|
567 { |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
568 struct stat st1, st2; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
569 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
570 i_assert(index->excl_lock_count == 0); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
571 |
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
|
572 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
|
573 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
|
574 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
575 if (index->fd == -1) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
576 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
|
577 |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
578 if (fstat(index->fd, &st1) < 0) { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
579 if (errno != ESTALE) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
580 return mail_index_set_syscall_error(index, "fstat()"); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
581 /* deleted/recreated, reopen */ |
6371
8468e3babea2
NFS: If index has been deleted, close the index properly before reopening it.
Timo Sirainen <tss@iki.fi>
parents:
6359
diff
changeset
|
582 mail_index_close_file(index); |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
583 return mail_index_try_open_only(index); |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3912
diff
changeset
|
584 } |
5972
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
585 |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
586 if (index->nfs_flush) |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
587 nfs_flush_attr_cache(index->filepath); |
4225
abdef9d86a94
Added nfs_safe_stat() to transparently work around ESTALE with stat().
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4220
diff
changeset
|
588 if (nfs_safe_stat(index->filepath, &st2) < 0) { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
589 if (errno == ENOENT) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
590 return 0; |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
591 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
592 return mail_index_set_syscall_error(index, "stat()"); |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
593 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
594 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
595 if (st1.st_ino == st2.st_ino && CMP_DEV_T(st1.st_dev, st2.st_dev)) { |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
596 /* the same file */ |
2063
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
597 return 1; |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
598 } |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
599 |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
600 /* 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
|
601 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
|
602 mail_index_close_file(index); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
603 |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5686
diff
changeset
|
604 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
|
605 } |
21a3e5d08290
mail_index_refresh() - allows forcing a refresh check
Timo Sirainen <tss@iki.fi>
parents:
2051
diff
changeset
|
606 |
2936
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
607 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
|
608 { |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
609 int ret; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
610 |
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
|
611 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
|
612 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
|
613 |
2936
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
614 if (index->excl_lock_count > 0) { |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
615 /* we have index exclusively locked, nothing could |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
616 have changed. */ |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
617 return 0; |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
618 } |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
619 |
5854 | 620 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
|
621 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
|
622 } |
57f975a9b63b
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
Timo Sirainen <tss@iki.fi>
parents:
2935
diff
changeset
|
623 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
624 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
|
625 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
626 return index->cache; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
627 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
628 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
629 int mail_index_set_error(struct mail_index *index, const char *fmt, ...) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
630 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
631 va_list va; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
632 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
633 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
634 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
635 if (fmt == NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
636 index->error = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
637 else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
638 va_start(va, fmt); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
639 index->error = i_strdup_vprintf(fmt, va); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
640 va_end(va); |
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 i_error("%s", index->error); |
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 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
645 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
646 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
647 |
3833
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
648 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
|
649 { |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
650 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
|
651 |
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
|
652 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
|
653 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
|
654 |
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
|
655 /* 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
|
656 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
|
657 |
5274
7641e625fbd5
When moving index file to memory, change the filename to be "(in-memory
Timo Sirainen <tss@iki.fi>
parents:
5273
diff
changeset
|
658 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
|
659 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
|
660 |
3912
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
661 if (index->map == NULL) { |
5224 | 662 /* 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
|
663 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
|
664 i_assert(index->fd == -1); |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
665 return -1; |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
666 } |
fc0b638330a4
Added mbox_min_index_size setting.
Timo Sirainen <tss@iki.fi>
parents:
3911
diff
changeset
|
667 |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
668 /* 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
|
669 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
|
670 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
|
671 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
|
672 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
|
673 } |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
674 |
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
|
675 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
|
676 /* 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
|
677 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
|
678 } |
3911
3a2fe49912f3
Fixed mail_index_move_to_memory() to work better and made it public
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
679 |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4795
diff
changeset
|
680 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
|
681 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
|
682 |
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
|
683 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
|
684 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
|
685 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
|
686 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
|
687 } |
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
|
688 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
|
689 } |
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
690 |
1945 | 691 void mail_index_mark_corrupted(struct mail_index *index) |
1943 | 692 { |
5820
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5819
diff
changeset
|
693 index->indexid = 0; |
1945 | 694 |
5772
002aa9bbfcb2
Removed index->hdr. Use index->map->hdr instead.
Timo Sirainen <tss@iki.fi>
parents:
5714
diff
changeset
|
695 index->map->hdr.flags |= MAIL_INDEX_HDR_FLAG_CORRUPTED; |
5775
98d5e3bd4d13
Handle corruption marking by unlinking dovecot.index file. Removed
Timo Sirainen <tss@iki.fi>
parents:
5773
diff
changeset
|
696 if (unlink(index->filepath) < 0 && errno != ENOENT && errno != ESTALE) |
98d5e3bd4d13
Handle corruption marking by unlinking dovecot.index file. Removed
Timo Sirainen <tss@iki.fi>
parents:
5773
diff
changeset
|
697 mail_index_set_syscall_error(index, "unlink()"); |
1943 | 698 } |
699 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
700 int mail_index_set_syscall_error(struct mail_index *index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
701 const char *function) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
702 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
703 i_assert(function != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
704 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
705 if (ENOSPACE(errno)) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
706 index->nodiskspace = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
707 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
708 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
709 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
710 return mail_index_set_error(index, "%s failed with index file %s: %m", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
711 function, index->filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
712 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
713 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
714 int mail_index_file_set_syscall_error(struct mail_index *index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
715 const char *filepath, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
716 const char *function) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
717 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
718 i_assert(filepath != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
719 i_assert(function != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
720 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
721 if (ENOSPACE(errno)) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
722 index->nodiskspace = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
723 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
724 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
725 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
726 return mail_index_set_error(index, "%s failed with file %s: %m", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
727 function, filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
728 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
729 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
730 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
|
731 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
732 return index->error; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
733 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
734 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
735 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
|
736 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
737 if (index->error != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
738 i_free(index->error); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
739 index->error = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
740 } |
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 index->nodiskspace = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
743 index->index_lock_timeout = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
744 } |
2407
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
745 |
5666
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
746 #ifdef WORDS_BIGENDIAN |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
747 /* FIXME: Unfortunately these functions were originally written to use |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
748 endian-specific code and we can't avoid that without breaking backwards |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
749 compatibility. When we do break it, just select one of these. */ |
2407
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
750 uint32_t mail_index_uint32_to_offset(uint32_t offset) |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
751 { |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
752 i_assert(offset < 0x40000000); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
753 i_assert((offset & 3) == 0); |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
754 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
755 offset >>= 2; |
5666
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
756 return 0x00000080 | ((offset & 0x0000007f)) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
757 0x00008000 | ((offset & 0x00003f80) >> 7 << 8) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
758 0x00800000 | ((offset & 0x001fc000) >> 14 << 16) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
759 0x80000000 | ((offset & 0x0fe00000) >> 21 << 24); |
2407
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
760 } |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
761 |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
762 uint32_t mail_index_offset_to_uint32(uint32_t offset) |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
763 { |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
764 if ((offset & 0x80808080) != 0x80808080) |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
765 return 0; |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
766 |
5666
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
767 return (((offset & 0x0000007f)) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
768 ((offset & 0x00007f00) >> 8 << 7) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
769 ((offset & 0x007f0000) >> 16 << 14) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
770 ((offset & 0x7f000000) >> 24 << 21)) << 2; |
2407
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2296
diff
changeset
|
771 } |
5666
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
772 #else |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
773 uint32_t mail_index_uint32_to_offset(uint32_t offset) |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
774 { |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
775 i_assert(offset < 0x40000000); |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
776 i_assert((offset & 3) == 0); |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
777 |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
778 offset >>= 2; |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
779 return 0x80000000 | ((offset & 0x0000007f) << 24) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
780 0x00800000 | ((offset & 0x00003f80) >> 7 << 16) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
781 0x00008000 | ((offset & 0x001fc000) >> 14 << 8) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
782 0x00000080 | ((offset & 0x0fe00000) >> 21); |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
783 } |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
784 |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
785 uint32_t mail_index_offset_to_uint32(uint32_t offset) |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
786 { |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
787 if ((offset & 0x80808080) != 0x80808080) |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
788 return 0; |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
789 |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
790 return (((offset & 0x0000007f) << 21) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
791 ((offset & 0x00007f00) >> 8 << 14) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
792 ((offset & 0x007f0000) >> 16 << 7) | |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
793 ((offset & 0x7f000000) >> 24)) << 2; |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
794 } |
a0e59849a03d
Better implementation for mail_index_uint32_to_offset() and
Timo Sirainen <tss@iki.fi>
parents:
5627
diff
changeset
|
795 #endif |