comparison src/lib-index/mail-index-open.c @ 296:d66aa1f1fb2d HEAD

Added fast-flag for mailbox opening, which doesn't do any index compressing or cache updating. This flag is set when mailbox is opened by APPEND, COPY or STATUS (ie. not SELECT/EXAMINE).
author Timo Sirainen <tss@iki.fi>
date Mon, 23 Sep 2002 13:42:20 +0300
parents bd51b6445bcd
children 0dc59fd3faed
comparison
equal deleted inserted replaced
295:c6c0e376008f 296:d66aa1f1fb2d
150 } 150 }
151 151
152 return TRUE; 152 return TRUE;
153 } 153 }
154 154
155 static int index_open_and_fix(MailIndex *index, int update_recent) 155 static int index_open_and_fix(MailIndex *index, int update_recent, int fast)
156 { 156 {
157 int rebuild; 157 int rebuild;
158 158
159 if (!mail_index_mmap_update(index)) 159 if (!mail_index_mmap_update(index))
160 return FALSE; 160 return FALSE;
198 /* index needs fscking */ 198 /* index needs fscking */
199 if (!index->fsck(index)) 199 if (!index->fsck(index))
200 return FALSE; 200 return FALSE;
201 } 201 }
202 202
203 if (index->header->flags & MAIL_INDEX_FLAG_COMPRESS) { 203 if (fast && (index->header->flags & MAIL_INDEX_FLAG_COMPRESS)) {
204 /* remove deleted blocks from index file */ 204 /* remove deleted blocks from index file */
205 if (!mail_index_compress(index)) 205 if (!mail_index_compress(index))
206 return FALSE; 206 return FALSE;
207 } 207 }
208 208
214 /* sync before updating cached fields so it won't print 214 /* sync before updating cached fields so it won't print
215 warnings if mails were deleted */ 215 warnings if mails were deleted */
216 if (!index->sync(index)) 216 if (!index->sync(index))
217 return FALSE; 217 return FALSE;
218 218
219 if (index->header->flags & MAIL_INDEX_FLAG_CACHE_FIELDS) { 219 if (fast && (index->header->flags & MAIL_INDEX_FLAG_CACHE_FIELDS)) {
220 /* need to update cached fields */ 220 /* need to update cached fields */
221 if (!mail_index_update_cache(index)) 221 if (!mail_index_update_cache(index))
222 return FALSE; 222 return FALSE;
223 } 223 }
224 224
225 if (index->header->flags & MAIL_INDEX_FLAG_COMPRESS_DATA) { 225 if (fast && (index->header->flags & MAIL_INDEX_FLAG_COMPRESS_DATA)) {
226 /* remove unused space from index data file. 226 /* remove unused space from index data file.
227 keep after cache_fields which may move data 227 keep after cache_fields which may move data
228 and create unused space.. */ 228 and create unused space.. */
229 if (!mail_index_compress_data(index)) 229 if (!mail_index_compress_data(index))
230 return FALSE; 230 return FALSE;
238 238
239 return TRUE; 239 return TRUE;
240 } 240 }
241 241
242 static int mail_index_open_file(MailIndex *index, const char *path, 242 static int mail_index_open_file(MailIndex *index, const char *path,
243 int update_recent) 243 int update_recent, int fast)
244 { 244 {
245 MailIndexHeader hdr; 245 MailIndexHeader hdr;
246 int fd; 246 int fd;
247 247
248 /* the index file should already be checked that it exists and 248 /* the index file should already be checked that it exists and
274 274
275 index->fd = fd; 275 index->fd = fd;
276 index->filepath = i_strdup(path); 276 index->filepath = i_strdup(path);
277 index->indexid = hdr.indexid; 277 index->indexid = hdr.indexid;
278 278
279 if (!index_open_and_fix(index, update_recent)) { 279 if (!index_open_and_fix(index, update_recent, fast)) {
280 mail_index_close(index); 280 mail_index_close(index);
281 return FALSE; 281 return FALSE;
282 } 282 }
283 283
284 return TRUE; 284 return TRUE;
475 hdr->used_file_size = sizeof(MailIndexHeader); 475 hdr->used_file_size = sizeof(MailIndexHeader);
476 hdr->uid_validity = ioloop_time; 476 hdr->uid_validity = ioloop_time;
477 hdr->next_uid = 1; 477 hdr->next_uid = 1;
478 } 478 }
479 479
480 int mail_index_open(MailIndex *index, int update_recent) 480 int mail_index_open(MailIndex *index, int update_recent, int fast)
481 { 481 {
482 const char *name, *path; 482 const char *name, *path;
483 483
484 i_assert(!index->opened); 484 i_assert(!index->opened);
485 485
489 name = mail_find_index(index); 489 name = mail_find_index(index);
490 if (name == NULL) 490 if (name == NULL)
491 return FALSE; 491 return FALSE;
492 492
493 path = t_strconcat(index->dir, "/", name, NULL); 493 path = t_strconcat(index->dir, "/", name, NULL);
494 if (!mail_index_open_file(index, path, update_recent)) 494 if (!mail_index_open_file(index, path, update_recent, fast))
495 return FALSE; 495 return FALSE;
496 496
497 index->opened = TRUE; 497 index->opened = TRUE;
498 return TRUE; 498 return TRUE;
499 } 499 }
500 500
501 int mail_index_open_or_create(MailIndex *index, int update_recent) 501 int mail_index_open_or_create(MailIndex *index, int update_recent, int fast)
502 { 502 {
503 int failed, dir_unlocked; 503 int failed, dir_unlocked;
504 504
505 i_assert(!index->opened); 505 i_assert(!index->opened);
506 506
507 if (mail_index_open(index, update_recent)) 507 if (mail_index_open(index, update_recent, fast))
508 return TRUE; 508 return TRUE;
509 509
510 /* index wasn't found or it was broken. lock the directory and check 510 /* index wasn't found or it was broken. lock the directory and check
511 again, just to make sure we don't end up having two index files 511 again, just to make sure we don't end up having two index files
512 due to race condition with another process. */ 512 due to race condition with another process. */
513 if (!mail_index_lock_dir(index, MAIL_LOCK_EXCLUSIVE)) 513 if (!mail_index_lock_dir(index, MAIL_LOCK_EXCLUSIVE))
514 return FALSE; 514 return FALSE;
515 515
516 if (mail_index_open(index, update_recent)) { 516 if (mail_index_open(index, update_recent, fast)) {
517 dir_unlocked = FALSE; 517 dir_unlocked = FALSE;
518 failed = FALSE; 518 failed = FALSE;
519 } else { 519 } else {
520 failed = !mail_index_create(index, &dir_unlocked, 520 failed = !mail_index_create(index, &dir_unlocked,
521 update_recent); 521 update_recent);