maildir-rebuild.c revision 88e275325fdb8b81581298a706c102edd140f428
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen i_assert(index->lock_type != MAIL_LOCK_SHARED);
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen if (!mail_index_set_lock(index, MAIL_LOCK_EXCLUSIVE))
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen /* reset the header */
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen index->mmap_used_length = index->header->used_file_size;
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen /* update indexid, which also means that our state has completely
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen if (msync(index->mmap_base, sizeof(MailIndexHeader), MS_SYNC) < 0)
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen /* reset data file */
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen /* rebuild cur/ directory */
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen cur_dir = t_strconcat(index->dir, "/cur", NULL);
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen if (!maildir_index_build_dir(index, cur_dir, NULL))
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen /* also see if there's new mail */
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen new_dir = t_strconcat(index->dir, "/new", NULL);
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen if (!maildir_index_build_dir(index, new_dir, cur_dir))
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen /* update sync stamp */
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen return index_file_set_syscall_error(index, cur_dir, "stat()");
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen /* rebuild is complete - remove the flag */