maildir-uidlist.c revision 85452efe6f9edd85e2ce45bfc4f198e9cb9b82bd
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (C) 2003 Timo Sirainen */
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainen/* NFS: How many times to retry reading dovecot-uidlist file if ESTALE
8aa049fd90cd03a66ec43018554bf3ba06815a10Timo Sirainen error occurs in the middle of reading it */
8aa049fd90cd03a66ec43018554bf3ba06815a10Timo Sirainen#define UIDLIST_ESTALE_RETRY_COUNT NFS_ESTALE_RETRY_COUNT
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainen/* how many seconds to wait before overriding uidlist.lock */
477082109e06b912d868a2c05674f44cb880875bTimo SirainenARRAY_DEFINE_TYPE(maildir_uidlist_rec_p, struct maildir_uidlist_rec *);
f9258697fe2573b087d09645dfade044dfb27052Aki Tuomi unsigned int version;
f9258697fe2573b087d09645dfade044dfb27052Aki Tuomi unsigned int uid_validity, next_uid, prev_read_uid, last_seen_uid;
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainen struct maildir_uidlist_rec *const *next, *const *end;
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainenstatic int maildir_uidlist_lock_timeout(struct maildir_uidlist *uidlist,
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainen path = t_strconcat(mbox->control_dir, "/" MAILDIR_UIDLIST_NAME, NULL);
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainen old_mask = umask(0777 & ~mbox->mail_create_mode);
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainen fd = file_dotlock_open(&uidlist->dotlock_settings, path,
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainen mail_storage_set_error(&mbox->storage->storage,
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainen mail_storage_set_critical(&mbox->storage->storage,
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainen if (fchown(fd, (uid_t)-1, mbox->mail_create_gid) < 0) {
4209bd278ff41fe352e8b993d849a061152829c8Timo Sirainen mail_storage_set_critical(&mbox->storage->storage,
4209bd278ff41fe352e8b993d849a061152829c8Timo Sirainen /* our view of uidlist must be up-to-date if we plan on changing it */
4209bd278ff41fe352e8b993d849a061152829c8Timo Sirainenint maildir_uidlist_lock(struct maildir_uidlist *uidlist)
4209bd278ff41fe352e8b993d849a061152829c8Timo Sirainen return maildir_uidlist_lock_timeout(uidlist, FALSE);
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainenint maildir_uidlist_try_lock(struct maildir_uidlist *uidlist)
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainen return maildir_uidlist_lock_timeout(uidlist, TRUE);
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainenint maildir_uidlist_lock_touch(struct maildir_uidlist *uidlist)
3008b30900f4de3e76f1a6d289444eb694f3d17cTimo Sirainenbool maildir_uidlist_is_locked(struct maildir_uidlist *uidlist)
const char *db_path;
return uidlist;
const char *line)
line++;
const char *line;
ret = 0;
ret = 0;
ret = 0;
ret = 0;
if (ret == 0) {
} else if (ret > 0) {
if (ret <= 0) {
return ret;
bool retry;
int ret;
if (!retry) {
if (ret >= 0)
return ret;
static const struct maildir_uidlist_rec *
unsigned int *idx_r)
return NULL;
return NULL;
unsigned int idx;
return NULL;
return NULL;
return NULL;
return FALSE;
return FALSE;
recent_count++;
return recent_count;
const char *temp_path)
const char *filename;
int ret = 0;
if (ret < 0)
int ret;
DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD) <= 0) {
return ret;
bool nonsynced)
unsigned int i, count;
if (nonsynced) {
for (i = 0; i < count; i++)
for (i = 0; i < count; i++)
int ret;
return ret;
const char *filename,
const char *filename)
const char *filename,
MAILDIR_UIDLIST_REC_FLAG_MOVED)) == 0) {
const char *filename)
const char *filename)
unsigned int first_new_pos)
MAILDIR_UIDLIST_REC_FLAG_RECENT) != 0) {
unsigned int count;
t_push();
t_pop();
if (ret == 0)
if (!unlocked)
return ret;
const char *filename,
struct maildir_uidlist_iter_ctx *
unsigned int count;
return ctx;
idx++;
idx--;
const char **filename_r)