annotate src/lib-index/mailbox-list-index.c @ 9458:adee8cb3ff5d HEAD

Minor memory allocation tweaks.
author Timo Sirainen <tss@iki.fi>
date Wed, 28 Oct 2009 14:10:04 -0400
parents 969d23a89379
children 00cd9aacd03c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 8027
diff changeset
1 /* Copyright (c) 2006-2009 Dovecot authors, see the included COPYING file */
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "array.h"
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "crc32.h"
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "ioloop.h"
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "str.h"
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
8 #include "file-cache.h"
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "file-dotlock.h"
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "mmap-util.h"
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "write-full.h"
5972
9fb9dc4d8df8 Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents: 5772
diff changeset
12 #include "nfs-workarounds.h"
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include "mail-index-private.h"
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include "mailbox-list-index-private.h"
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 #include <stdlib.h>
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include <unistd.h>
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include <fcntl.h>
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 #include <sys/stat.h>
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 struct mailbox_list_iter_path {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 const struct mailbox_list_dir_record *dir;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 unsigned int pos;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 unsigned int name_path_len;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 };
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
27 struct mailbox_list_index_view {
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 struct mailbox_list_index *index;
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
29 struct mail_index_view *mail_view;
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
30 };
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
32 struct mailbox_list_iter_ctx {
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
33 struct mailbox_list_index_view *view;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 unsigned int recurse_level;
6087
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
35 uint32_t max_uid;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 struct mailbox_list_iter_path cur;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 ARRAY_DEFINE(path, struct mailbox_list_iter_path);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 string_t *name_path;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 unsigned int failed:1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 };
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43
8027
62cf70991cf2 extern/static fixes (from a sparse check by Diego Liziero)
Timo Sirainen <tss@iki.fi>
parents: 7226
diff changeset
44 static const struct dotlock_settings default_dotlock_set = {
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 MEMBER(temp_prefix) NULL,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 MEMBER(lock_suffix) NULL,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 MEMBER(timeout) 60,
6592
b6631550cf84 dotlocks: Flush NFS attribute cache only if nfs_flush setting is TRUE.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
49 MEMBER(stale_timeout) 30
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 };
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 int mailbox_list_index_set_syscall_error(struct mailbox_list_index *index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 const char *function)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 {
8777
ff1d88068275 Error message fix for currently unused mailbox list index code.
Timo Sirainen <tss@iki.fi>
parents: 8742
diff changeset
55 i_error("%s failed with file %s: %m", function, index->filepath);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 static void mailbox_list_index_unmap(struct mailbox_list_index *index)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 {
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
61 if (index->file_cache != NULL)
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
62 file_cache_invalidate(index->file_cache, 0, (uoff_t)-1);
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
63
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 if (index->mmap_base != NULL) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 if (munmap(index->mmap_base, index->mmap_size) < 0)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 mailbox_list_index_set_syscall_error(index, "munmap()");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 index->mmap_base = NULL;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 }
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
69 index->const_mmap_base = NULL;
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
70 index->mmap_size = 0;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 index->hdr = NULL;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
75 void mailbox_list_index_file_close(struct mailbox_list_index *index)
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 mailbox_list_index_unmap(index);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
79 if (index->file_cache != NULL)
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
80 file_cache_free(&index->file_cache);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 if (index->fd != -1) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 if (close(index->fd) < 0)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 mailbox_list_index_set_syscall_error(index, "close()");
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
84 index->fd = -1;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 int mailbox_list_index_set_corrupted(struct mailbox_list_index *index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 const char *str)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 (void)unlink(index->filepath);
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
92 mailbox_list_index_file_close(index);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 i_error("Corrupted mailbox list index file %s: %s",
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 index->filepath, str);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 static int
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 mailbox_list_index_check_header(struct mailbox_list_index *index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 const struct mailbox_list_index_header *hdr)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 if (hdr->major_version != MAILBOX_LIST_INDEX_MAJOR_VERSION)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 if (hdr->header_size < sizeof(*hdr)) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 return mailbox_list_index_set_corrupted(index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 "header_size is too small");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 if (hdr->header_size > index->mmap_size) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 return mailbox_list_index_set_corrupted(index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 "header_size is too large");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 if (hdr->uid_validity == 0) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 return mailbox_list_index_set_corrupted(index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 "uid_validity is 0");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 if (hdr->next_uid == 0)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 return mailbox_list_index_set_corrupted(index, "next_uid is 0");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121
5772
002aa9bbfcb2 Removed index->hdr. Use index->map->hdr instead.
Timo Sirainen <tss@iki.fi>
parents: 5343
diff changeset
122 if (index->mail_index->map == NULL) {
5320
2d53914a4520 Error handling fixes
Timo Sirainen <tss@iki.fi>
parents: 5317
diff changeset
123 /* index already marked as corrupted */
2d53914a4520 Error handling fixes
Timo Sirainen <tss@iki.fi>
parents: 5317
diff changeset
124 return -1;
2d53914a4520 Error handling fixes
Timo Sirainen <tss@iki.fi>
parents: 5317
diff changeset
125 }
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 return 0;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 int mailbox_list_index_map(struct mailbox_list_index *index)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131 const struct mailbox_list_index_header *hdr;
6101
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
132 struct stat st;
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
133 ssize_t ret;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 mailbox_list_index_unmap(index);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
137 if (!index->mmap_disable) {
6101
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
138 if (fstat(index->fd, &st) < 0) {
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
139 mailbox_list_index_set_syscall_error(index, "fstat()");
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
140 return -1;
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
141 }
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
142 }
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
143
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
144 if (!index->mmap_disable &&
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
145 st.st_size >= MAILBOX_LIST_INDEX_MMAP_MIN_SIZE) {
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
146 index->mmap_size = st.st_size;
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
147 index->mmap_base = mmap(NULL, index->mmap_size,
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
148 PROT_READ | PROT_WRITE,
6805ccf0b82e mmap() mailbox list index only if it's at least 32kB
Timo Sirainen <tss@iki.fi>
parents: 6096
diff changeset
149 MAP_SHARED, index->fd, 0);
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
150 if (index->mmap_base == MAP_FAILED) {
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
151 index->mmap_base = NULL;
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
152 mailbox_list_index_set_syscall_error(index, "mmap()");
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
153 return -1;
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
154 }
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
155
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
156 index->const_mmap_base = index->mmap_base;
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
157 } else {
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
158 if (index->file_cache == NULL)
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
159 index->file_cache = file_cache_new(index->fd);
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
160
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
161 ret = file_cache_read(index->file_cache, 0, SSIZE_T_MAX);
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
162 if (ret < 0) {
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
163 mailbox_list_index_set_syscall_error(index,
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
164 "file_cache_read()");
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
165 return -1;
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
166 }
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
167 index->const_mmap_base = file_cache_get_map(index->file_cache,
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
168 &index->mmap_size);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 if (index->mmap_size < sizeof(*hdr)) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 mailbox_list_index_set_corrupted(index, "File too small");
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
173 index->const_mmap_base = NULL;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 return 0;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
177 hdr = index->const_mmap_base;
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
178 if (mailbox_list_index_check_header(index, hdr) < 0) {
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
179 index->const_mmap_base = NULL;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 return 0;
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
181 }
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 index->hdr = hdr;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 return 1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186
5343
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
187 static int mailbox_list_index_map_area(struct mailbox_list_index *index,
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
188 uoff_t offset, size_t size)
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
189 {
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
190 if (offset < index->mmap_size && size <= index->mmap_size - offset)
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
191 return 1;
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
192
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
193 if (mailbox_list_index_map(index) <= 0)
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
194 return -1;
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
195
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
196 if (offset < index->mmap_size && size <= index->mmap_size - offset)
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
197 return 1;
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
198 /* outside the file */
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
199 return 0;
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
200 }
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
201
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
202 static void
6086
e562c6359cd1 Added increasing file_seq field to list index.
Timo Sirainen <tss@iki.fi>
parents: 6072
diff changeset
203 mailbox_list_index_init_header(struct mailbox_list_index *index,
e562c6359cd1 Added increasing file_seq field to list index.
Timo Sirainen <tss@iki.fi>
parents: 6072
diff changeset
204 struct mailbox_list_index_header *hdr,
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
205 uint32_t uid_validity)
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207 memset(hdr, 0, sizeof(*hdr));
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
208 hdr->major_version = MAILBOX_LIST_INDEX_MAJOR_VERSION;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209 hdr->minor_version = MAILBOX_LIST_INDEX_MINOR_VERSION;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
210
6086
e562c6359cd1 Added increasing file_seq field to list index.
Timo Sirainen <tss@iki.fi>
parents: 6072
diff changeset
211 hdr->file_seq = index->hdr == NULL ? 1 : index->hdr->file_seq + 1;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
212 hdr->header_size = sizeof(*hdr);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213 hdr->used_space = hdr->header_size;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
214
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
215 hdr->uid_validity = uid_validity;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216 hdr->next_uid = 1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219 static int mailbox_list_index_is_recreated(struct mailbox_list_index *index)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
220 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
221 struct stat st1, st2;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
222
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
223 if (index->fd == -1)
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
224 return 1;
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
225
5972
9fb9dc4d8df8 Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents: 5772
diff changeset
226 if (index->mail_index->nfs_flush)
6857
41911abe6fa7 NFS cache flushing updates.
Timo Sirainen <tss@iki.fi>
parents: 6829
diff changeset
227 nfs_flush_file_handle_cache(index->filepath);
5972
9fb9dc4d8df8 Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents: 5772
diff changeset
228
9fb9dc4d8df8 Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents: 5772
diff changeset
229 if (nfs_safe_stat(index->filepath, &st1) < 0) {
6829
dbab5e592577 NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents: 6819
diff changeset
230 if (errno == ENOENT || errno == ESTALE)
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
231 return 1;
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
232
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233 mailbox_list_index_set_syscall_error(index, "stat()");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 if (fstat(index->fd, &st2) < 0) {
6829
dbab5e592577 NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents: 6819
diff changeset
237 if (errno == ESTALE)
dbab5e592577 NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents: 6819
diff changeset
238 return 1;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 mailbox_list_index_set_syscall_error(index, "fstat()");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
240 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
241 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
242
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
243 return st1.st_ino != st2.st_ino ||
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
244 !CMP_DEV_T(st1.st_dev, st2.st_dev);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
246
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
247 int mailbox_list_index_file_create(struct mailbox_list_index *index,
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
248 uint32_t uid_validity)
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
249 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 struct mailbox_list_index_header hdr;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
251 struct dotlock *dotlock;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252 int fd, ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253
4968
1baf9dd3fc40 Added dotlock_use_excl setting.
Timo Sirainen <tss@iki.fi>
parents: 4929
diff changeset
254 fd = file_dotlock_open(&index->dotlock_set, index->filepath,
1baf9dd3fc40 Added dotlock_use_excl setting.
Timo Sirainen <tss@iki.fi>
parents: 4929
diff changeset
255 0, &dotlock);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256 if (fd == -1) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257 mailbox_list_index_set_syscall_error(index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
258 "file_dotlock_open()");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
259 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
260 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
261
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
262 if (index->fd != -1) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
263 /* if the file has been recreated by someone else,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
264 retry opening it */
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 ret = mailbox_list_index_is_recreated(index);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266 if (ret != 0) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
267 (void)file_dotlock_delete(&dotlock);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
268 return ret < 0 ? -1 : 0;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
270 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
271
6086
e562c6359cd1 Added increasing file_seq field to list index.
Timo Sirainen <tss@iki.fi>
parents: 6072
diff changeset
272 mailbox_list_index_init_header(index, &hdr, uid_validity);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273 if (write_full(fd, &hdr, sizeof(hdr)) < 0) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 mailbox_list_index_set_syscall_error(index, "write_full()");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
275 (void)file_dotlock_delete(&dotlock);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278
5972
9fb9dc4d8df8 Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents: 5772
diff changeset
279 if (index->mail_index->nfs_flush && fdatasync(fd) < 0) {
9fb9dc4d8df8 Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents: 5772
diff changeset
280 mailbox_list_index_set_syscall_error(index, "fdatasync()");
9fb9dc4d8df8 Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents: 5772
diff changeset
281 (void)file_dotlock_delete(&dotlock);
9fb9dc4d8df8 Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents: 5772
diff changeset
282 return -1;
9fb9dc4d8df8 Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents: 5772
diff changeset
283 }
9fb9dc4d8df8 Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents: 5772
diff changeset
284
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
285 if (file_dotlock_replace(&dotlock,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
286 DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD) < 0) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
287 mailbox_list_index_set_syscall_error(index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
288 "file_dotlock_replace()");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289 (void)close(fd);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
290 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
293 if (index->fd != -1)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
294 mailbox_list_index_file_close(index);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295 index->fd = fd;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
296
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
297 ret = mailbox_list_index_map(index);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
298 if (ret == 0) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299 i_error("Self-created mailbox list index file %s was corrupted",
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
300 index->filepath);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
301 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
302 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
303 return ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
304 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
305
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
306 static int
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
307 mailbox_list_index_file_try_open_or_create(struct mailbox_list_index *index)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
308 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
309 int ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
310
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
311 i_assert(index->fd == -1);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
312
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
313 index->fd = open(index->filepath, O_RDWR);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314 if (index->fd == -1) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315 if (errno != ENOENT) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
316 mailbox_list_index_set_syscall_error(index, "open()");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
317 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
318 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
319 } else {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
320 ret = mailbox_list_index_map(index);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
321 if (ret != 0) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
322 if (ret < 0)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
323 mailbox_list_index_file_close(index);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
324 return ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
325 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
326 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
327
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
328 ret = mailbox_list_index_file_create(index, ioloop_time);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
329 if (ret <= 0)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
330 mailbox_list_index_file_close(index);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
331 return ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
332 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
333
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
334 int mailbox_list_index_open_or_create(struct mailbox_list_index *index)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
336 int ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338 while ((ret = mailbox_list_index_file_try_open_or_create(index)) == 0) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339 /* file was recreated by someone else, try reopening */
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
340 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
341 return ret < 0 ? -1 : 0;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
342 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
343
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344 struct mailbox_list_index *
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345 mailbox_list_index_alloc(const char *path, char separator,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346 struct mail_index *mail_index)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
347 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
348 struct mailbox_list_index *index;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
349
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
350 index = i_new(struct mailbox_list_index, 1);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
351 index->filepath = i_strdup(path);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
352 index->separator = separator;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
353 index->mail_index = mail_index;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354 index->fd = -1;
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
355 index->mmap_disable = mail_index->mmap_disable;
4968
1baf9dd3fc40 Added dotlock_use_excl setting.
Timo Sirainen <tss@iki.fi>
parents: 4929
diff changeset
356 index->dotlock_set = default_dotlock_set;
1baf9dd3fc40 Added dotlock_use_excl setting.
Timo Sirainen <tss@iki.fi>
parents: 4929
diff changeset
357 index->dotlock_set.use_excl_lock = mail_index->use_excl_dotlocks;
6592
b6631550cf84 dotlocks: Flush NFS attribute cache only if nfs_flush setting is TRUE.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
358 index->dotlock_set.nfs_flush = mail_index->nfs_flush;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
359 return index;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
360 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
361
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
362 void mailbox_list_index_free(struct mailbox_list_index **_index)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
363 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
364 struct mailbox_list_index *index = *_index;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
365
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
366 *_index = NULL;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
368 mailbox_list_index_file_close(index);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
369 i_free(index->filepath);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
370 i_free(index);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373 struct mailbox_list_index_lookup_key {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374 uint32_t name_hash;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
375
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
376 struct mailbox_list_index *index;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377 const char *name;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
378
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
379 bool *failed;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380 };
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
381
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
382 static int
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
383 mailbox_list_get_name(struct mailbox_list_index *index, pool_t pool,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
384 const struct mailbox_list_record *rec,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
385 const char **name_r)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
386 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387 size_t max_len;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
388 const char *name;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
390 if (rec->name_offset >= index->mmap_size) {
8742
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
391 mailbox_list_index_set_corrupted(index, t_strdup_printf(
8799
969d23a89379 Compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents: 8777
diff changeset
392 "record name_offset (%u) points outside file "
969d23a89379 Compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents: 8777
diff changeset
393 "(%"PRIuSIZE_T")", rec->name_offset, index->mmap_size));
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
394 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
395 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
396 max_len = index->mmap_size - rec->name_offset;
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
397 name = CONST_PTR_OFFSET(index->const_mmap_base, rec->name_offset);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
398 /* get name length. don't bother checking if it's not NUL-terminated,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399 because practically it always is even if the file is corrupted.
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
400 just make sure we don't crash if it happens. */
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
401 *name_r = p_strndup(pool, name, max_len);
8742
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
402 if (*name_r == '\0') {
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
403 mailbox_list_index_set_corrupted(index, "Empty mailbox name");
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
404 return -1;
8742
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
405 }
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
406 return 0;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
407 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
408
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
409 int mailbox_list_index_get_dir(struct mailbox_list_index_view *view,
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
410 uint32_t *offset,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411 const struct mailbox_list_dir_record **dir_r)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412 {
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
413 struct mailbox_list_index *index = view->index;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
414 const struct mailbox_list_dir_record *dir;
6087
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
415 uint32_t next_offset, cur_offset = *offset;
5343
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
416 int ret;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
417
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
418 i_assert(index->mmap_size > 0);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
419
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
420 do {
5343
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
421 ret = mailbox_list_index_map_area(index, cur_offset,
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
422 sizeof(*dir));
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
423 if (ret <= 0) {
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
424 if (ret < 0)
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
425 return -1;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
426 return mailbox_list_index_set_corrupted(index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
427 "dir_offset points outside file");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
428 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
429 if ((cur_offset % 4) != 0) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
430 return mailbox_list_index_set_corrupted(index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431 "dir_offset not 32bit aligned");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433
4896
3d00a9636393 Mailbox list index works now with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
434 dir = CONST_PTR_OFFSET(index->const_mmap_base, cur_offset);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435 next_offset = mail_index_offset_to_uint32(dir->next_offset);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
436 if (next_offset != 0 && next_offset <= cur_offset) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 return mailbox_list_index_set_corrupted(index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438 "next_offset points backwards");
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
439 }
8742
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
440
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
441 if (dir->count >
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
442 index->mmap_size / sizeof(struct mailbox_list_record)) {
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
443 return mailbox_list_index_set_corrupted(index,
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
444 "dir count too large");
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
445 }
5343
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
446 if (dir->dir_size < sizeof(*dir) +
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
447 dir->count * sizeof(struct mailbox_list_record)) {
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
448 return mailbox_list_index_set_corrupted(index,
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
449 "dir_size is smaller than record count");
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
450 }
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451 cur_offset = next_offset;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452 } while (cur_offset != 0);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
453
5343
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
454 cur_offset = (const char *)dir - (const char *)index->const_mmap_base;
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
455 ret = mailbox_list_index_map_area(index, cur_offset, dir->dir_size);
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
456 if (ret <= 0) {
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
457 if (ret < 0)
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
458 return -1;
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
459 return mailbox_list_index_set_corrupted(index,
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
460 "dir points outside file");
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
461 }
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
462
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
463 *offset = cur_offset;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
464 *dir_r = dir;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465 return 0;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467
8742
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
468 static int mailbox_list_record_cmp(const void *_key, const void *_rec)
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
469 {
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
470 const struct mailbox_list_index_lookup_key *key = _key;
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
471 const struct mailbox_list_record *rec = _rec;
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
472 int ret;
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
473
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
474 if (key->name_hash < rec->name_hash)
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
475 return -1;
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
476 if (key->name_hash > rec->name_hash)
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
477 return 1;
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
478
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
479 T_BEGIN {
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
480 const char *name;
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
481
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
482 if (mailbox_list_get_name(key->index, unsafe_data_stack_pool,
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
483 rec, &name) < 0) {
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
484 *key->failed = TRUE;
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
485 ret = 0;
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
486 } else {
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
487 ret = strcmp(key->name, name);
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
488 }
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
489 } T_END;
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
490 return ret;
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
491 }
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
492
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
493 int mailbox_list_index_dir_lookup_rec(struct mailbox_list_index *index,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
494 const struct mailbox_list_dir_record *dir,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
495 const char *name,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
496 const struct mailbox_list_record **rec_r)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
497 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
498 const struct mailbox_list_record *rec;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
499 struct mailbox_list_index_lookup_key key;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
500 bool failed = FALSE;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
501
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
502 /* binary search the current hierarchy level name. the values are
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
503 sorted primarily by their hash value and secondarily by the actual
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
504 name */
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
505 memset(&key, 0, sizeof(key));
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
506 key.index = index;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
507 key.name = name;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
508 key.name_hash = crc32_str(name);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
509 key.failed = &failed;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
510
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
511 rec = bsearch(&key, MAILBOX_LIST_RECORDS(dir), dir->count, sizeof(*rec),
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
512 mailbox_list_record_cmp);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
513 if (failed)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
514 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
515 if (rec == NULL)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
516 return 0;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
517
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
518 *rec_r = rec;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
519 return 1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
520 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
521
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
522 static int
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
523 mailbox_list_index_lookup_rec(struct mailbox_list_index_view *view,
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
524 uint32_t dir_offset, const char *name,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
525 const struct mailbox_list_record **rec_r)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
526 {
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
527 struct mailbox_list_index *index = view->index;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
528 const struct mailbox_list_dir_record *dir;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
529 const char *p, *hier_name;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
530 int ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
531
5343
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
532 if (dir_offset == sizeof(*index->hdr) &&
6087
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
533 index->mmap_size <= sizeof(*index->hdr)) {
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
534 /* root doesn't exist in the file yet */
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
535 return 0;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
536 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
537
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
538 if (mailbox_list_index_get_dir(view, &dir_offset, &dir) < 0)
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
539 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
540
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
541 p = strchr(name, index->separator);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
542 hier_name = p == NULL ? name : t_strdup_until(name, p);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
543
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
544 ret = mailbox_list_index_dir_lookup_rec(index, dir, hier_name, rec_r);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
545 if (ret <= 0)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
546 return ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
547
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
548 if (p == NULL) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
549 /* found it */
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
550 return 1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
551 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
552
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
553 /* recurse to children */
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
554 dir_offset = mail_index_offset_to_uint32((*rec_r)->dir_offset);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
555 if (dir_offset == 0)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
556 return 0;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
557
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
558 return mailbox_list_index_lookup_rec(view, dir_offset, p + 1, rec_r);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
559 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
560
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
561 int mailbox_list_index_refresh(struct mailbox_list_index *index)
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
562 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
563 int ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
564
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
565 if ((ret = mailbox_list_index_is_recreated(index)) <= 0) {
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
566 if (ret < 0)
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
567 return -1;
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
568
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
569 if (mailbox_list_index_map(index) < 0)
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
570 ret = -1;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
571 return ret;
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
572 }
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
573
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
574 mailbox_list_index_file_close(index);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
575 return mailbox_list_index_open_or_create(index);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
576 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
577
6069
8576ce5d7fb4 Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
578 int mailbox_list_index_view_init(struct mailbox_list_index *index,
8576ce5d7fb4 Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
579 struct mail_index_view *mail_view,
8576ce5d7fb4 Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
580 struct mailbox_list_index_view **view_r)
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
581 {
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
582 struct mailbox_list_index_view *view;
6072
461496644c67 Handle uid validity changes a bit better.
Timo Sirainen <tss@iki.fi>
parents: 6069
diff changeset
583 const struct mail_index_header *mail_hdr;
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
584
6072
461496644c67 Handle uid validity changes a bit better.
Timo Sirainen <tss@iki.fi>
parents: 6069
diff changeset
585 mail_hdr = mail_view != NULL ? mail_index_get_header(mail_view) : NULL;
8742
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
586 if (mail_hdr != NULL && mail_hdr->uid_validity != 0 &&
37e118a32cd0 Minor changes to mailbox list indexing code. Still disabled/non-working.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
587 index->hdr != NULL &&
6072
461496644c67 Handle uid validity changes a bit better.
Timo Sirainen <tss@iki.fi>
parents: 6069
diff changeset
588 mail_hdr->uid_validity != index->hdr->uid_validity) {
6069
8576ce5d7fb4 Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
589 mail_index_set_error(index->mail_index,
8576ce5d7fb4 Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
590 "uid_validity mismatch in file %s: %u != %u",
8576ce5d7fb4 Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
591 index->filepath, index->hdr->uid_validity,
6072
461496644c67 Handle uid validity changes a bit better.
Timo Sirainen <tss@iki.fi>
parents: 6069
diff changeset
592 mail_hdr->uid_validity);
6069
8576ce5d7fb4 Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
593 return -1;
8576ce5d7fb4 Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
594 }
8576ce5d7fb4 Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
595
8576ce5d7fb4 Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
596 view = *view_r = i_new(struct mailbox_list_index_view, 1);
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
597 view->index = index;
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
598 view->mail_view = mail_view;
6069
8576ce5d7fb4 Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
599 return 0;
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
600 }
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
601
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
602 void mailbox_list_index_view_deinit(struct mailbox_list_index_view **_view)
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
603 {
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
604 struct mailbox_list_index_view *view = *_view;
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
605
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
606 *_view = NULL;
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
607 i_free(view);
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
608 }
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
609
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
610 int mailbox_list_index_lookup(struct mailbox_list_index_view *view,
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
611 const char *name, uint32_t *uid_r)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
612 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
613 const struct mailbox_list_record *rec;
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
614 uint32_t offset = sizeof(*view->index->hdr);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
615 int ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
616
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
617 ret = mailbox_list_index_lookup_rec(view, offset, name, &rec);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
618 if (ret == 0) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
619 /* not found, see if it's found after a refresh */
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
620 if ((ret = mailbox_list_index_refresh(view->index)) <= 0)
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
621 return ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
622
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
623 ret = mailbox_list_index_lookup_rec(view, offset, name, &rec);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
624 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
625
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
626 *uid_r = ret <= 0 ? 0 : rec->uid;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
627 return ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
628 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
629
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
630 struct mailbox_list_iter_ctx *
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
631 mailbox_list_index_iterate_init(struct mailbox_list_index_view *view,
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
632 const char *path, int recurse_level)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
633 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
634 struct mailbox_list_iter_ctx *ctx;
6087
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
635 const struct mail_index_header *mail_hdr;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
636 const struct mailbox_list_record *rec;
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
637 uint32_t offset = sizeof(*view->index->hdr);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
638 int ret;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
639
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
640 ctx = i_new(struct mailbox_list_iter_ctx, 1);
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
641 ctx->view = view;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
642 ctx->recurse_level = recurse_level < 0 ? (unsigned int)-1 :
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
643 (unsigned int)recurse_level;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
644 ctx->name_path = str_new(default_pool, 512);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
645
6087
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
646 if (view->mail_view != NULL) {
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
647 mail_hdr = mail_index_get_header(view->mail_view);
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
648 ctx->max_uid = mail_hdr->next_uid - 1;
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
649 } else {
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
650 ctx->max_uid = (uint32_t)-1;
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
651 }
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
652
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
653 if (mailbox_list_index_refresh(view->index) < 0)
4929
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
654 ctx->failed = TRUE;
791c9c8d3a02 Compress list index when its deleted space amount gets too high. Also fixed
Timo Sirainen <tss@iki.fi>
parents: 4896
diff changeset
655 if (!ctx->failed && *path != '\0') {
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
656 ret = mailbox_list_index_lookup_rec(view, offset, path, &rec);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
657 if (ret < 0)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
658 ctx->failed = TRUE;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
659 else {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
660 offset = ret == 0 ? 0 :
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
661 mail_index_offset_to_uint32(rec->dir_offset);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
662 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
663 }
5343
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
664
6087
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
665 if (view->index->mmap_size <= sizeof(*view->index->hdr)) {
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
666 /* root doesn't exist */
5343
cdf39128dd91 More desyncing fixes
Timo Sirainen <tss@iki.fi>
parents: 5324
diff changeset
667 } else if (!ctx->failed && offset != 0) {
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
668 if (mailbox_list_index_get_dir(view, &offset,
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
669 &ctx->cur.dir) < 0)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
670 ctx->failed = TRUE;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
671 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
672 i_array_init(&ctx->path, I_MIN(ctx->recurse_level, 16));
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
673 return ctx;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
674 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
675
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
676 int mailbox_list_index_iterate_next(struct mailbox_list_iter_ctx *ctx,
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
677 struct mailbox_list_index_info *info_r)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
678 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
679 const struct mailbox_list_iter_path *cur;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
680 const struct mailbox_list_record *recs;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
681 uint32_t dir_offset;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
682 unsigned int count;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
683
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
684 if (ctx->failed)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
685 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
686
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
687 if (ctx->cur.dir == NULL) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
688 /* no mailboxes */
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
689 i_assert(array_count(&ctx->path) == 0);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
690 return 0;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
691 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
692
6087
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
693 for (;;) {
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
694 if (ctx->cur.pos == ctx->cur.dir->count) {
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
695 count = array_count(&ctx->path);
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
696 if (count == 0) {
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
697 /* we're done */
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
698 return 0;
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
699 }
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
700
6087
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
701 /* go back to parent path */
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
702 cur = array_idx(&ctx->path, count-1);
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
703 ctx->cur = *cur;
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
704 array_delete(&ctx->path, count-1, 1);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
705
6087
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
706 ctx->cur.pos++;
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
707 } else {
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
708 recs = MAILBOX_LIST_RECORDS(ctx->cur.dir);
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
709 recs += ctx->cur.pos;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
710
6087
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
711 if (!recs->deleted && recs->uid <= ctx->max_uid)
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
712 break;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
713
6087
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
714 ctx->cur.pos++;
f479a774a416 We can't check if list branch exists in mail_view by checking sync_size
Timo Sirainen <tss@iki.fi>
parents: 6086
diff changeset
715 }
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
716 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
717
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
718 T_BEGIN {
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
719 const char *name;
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
720
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
721 if (mailbox_list_get_name(ctx->view->index,
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
722 unsafe_data_stack_pool,
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
723 recs, &name) < 0)
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
724 ctx->failed = TRUE;
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
725 else {
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
726 str_truncate(ctx->name_path, ctx->cur.name_path_len);
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
727 if (ctx->cur.name_path_len > 0) {
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
728 str_append_c(ctx->name_path,
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
729 ctx->view->index->separator);
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
730 }
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
731 str_append(ctx->name_path, name);
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
732 }
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
733 } T_END;
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6857
diff changeset
734 if (ctx->failed)
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
735 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
736
6096
877d861f2dd3 Crashfix
Timo Sirainen <tss@iki.fi>
parents: 6087
diff changeset
737 info_r->name = str_c(ctx->name_path);
877d861f2dd3 Crashfix
Timo Sirainen <tss@iki.fi>
parents: 6087
diff changeset
738 info_r->uid = recs->uid;
877d861f2dd3 Crashfix
Timo Sirainen <tss@iki.fi>
parents: 6087
diff changeset
739
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
740 dir_offset = mail_index_offset_to_uint32(recs->dir_offset);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
741 if (dir_offset != 0 && array_count(&ctx->path) < ctx->recurse_level) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
742 /* recurse into children */
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
743 array_append(&ctx->path, &ctx->cur, 1);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
744
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
745 ctx->cur.name_path_len = str_len(ctx->name_path);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
746 ctx->cur.pos = 0;
5324
4d3294c59939 Fixed desyncing problems with mail index and mailbox list index.
Timo Sirainen <tss@iki.fi>
parents: 5323
diff changeset
747 if (mailbox_list_index_get_dir(ctx->view, &dir_offset,
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
748 &ctx->cur.dir) < 0) {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
749 ctx->failed = TRUE;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
750 return -1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
751 }
6096
877d861f2dd3 Crashfix
Timo Sirainen <tss@iki.fi>
parents: 6087
diff changeset
752 recs = NULL; /* don't use anymore */
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
753 } else {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
754 ctx->cur.pos++;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
755 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
756 info_r->has_children = dir_offset != 0;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
757 return 1;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
758 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
759
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
760 void mailbox_list_index_iterate_deinit(struct mailbox_list_iter_ctx **_ctx)
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
761 {
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
762 struct mailbox_list_iter_ctx *ctx = *_ctx;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
763
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
764 *_ctx = NULL;
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
765 array_free(&ctx->path);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
766 str_free(&ctx->name_path);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
767 i_free(ctx);
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
768 }