[dovecot-cvs]
dovecot/src/lib-index/maildir maildir-expunge.c,1.2,1.3
maildir-index.h,1.21,1.22 maildir-sync.c,1.52,1.53
maildir-update-flags.c,1.4,1.5
cras at procontrol.fi
cras at procontrol.fi
Sun Jun 15 06:20:54 EEST 2003
Update of /home/cvs/dovecot/src/lib-index/maildir
In directory danu:/tmp/cvs-serv11439/lib-index/maildir
Modified Files:
maildir-expunge.c maildir-index.h maildir-sync.c
maildir-update-flags.c
Log Message:
Dirty maildir flags support works now.
Index: maildir-expunge.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-expunge.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- maildir-expunge.c 29 May 2003 14:15:57 -0000 1.2
+++ maildir-expunge.c 15 Jun 2003 02:20:52 -0000 1.3
@@ -17,6 +17,12 @@
if (*fname == NULL)
return -1;
+ /* if we're in out-of-space condition, reset it since we'll probably
+ have enough space now. */
+ index->maildir_keep_new = FALSE;
+ if (index->next_dirty_flush != 0)
+ index->next_dirty_flush = ioloop_time;
+
if ((rec->index_flags & INDEX_MAIL_FLAG_MAILDIR_NEW) != 0) {
/* probably in new/ dir */
path = t_strconcat(index->mailbox_path, "/new/", *fname, NULL);
Index: maildir-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-index.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- maildir-index.h 18 May 2003 12:26:06 -0000 1.21
+++ maildir-index.h 15 Jun 2003 02:20:52 -0000 1.22
@@ -8,6 +8,9 @@
/* ":2,DFRST" - leave the 2 extra for other clients' additions */
#define MAILDIR_LOCATION_EXTRA_SPACE 10
+/* How often to try to flush dirty flags. */
+#define MAILDIR_DIRTY_FLUSH_TIMEOUT (60*5)
+
struct mail_index *
maildir_index_alloc(const char *maildir, const char *index_dir,
const char *control_dir);
@@ -35,6 +38,7 @@
int maildir_index_update_flags(struct mail_index *index,
struct mail_index_record *rec, unsigned int seq,
enum mail_flags flags, int external_change);
+int maildir_try_flush_dirty_flags(struct mail_index *index, int force);
struct istream *maildir_open_mail(struct mail_index *index,
struct mail_index_record *rec,
Index: maildir-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-sync.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- maildir-sync.c 4 Jun 2003 13:55:59 -0000 1.52
+++ maildir-sync.c 15 Jun 2003 02:20:52 -0000 1.53
@@ -1098,6 +1098,9 @@
struct stat st;
time_t new_mtime, cur_mtime;
+ if (!maildir_try_flush_dirty_flags(ctx->index, FALSE))
+ return FALSE;
+
if (index->fd != -1) {
/* FIXME: file_sync_stamp should be in index file's headers.
it should also contain maildir_cur_dirty. */
Index: maildir-update-flags.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-update-flags.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- maildir-update-flags.c 29 May 2003 21:08:53 -0000 1.4
+++ maildir-update-flags.c 15 Jun 2003 02:20:52 -0000 1.5
@@ -7,6 +7,66 @@
#include <stdio.h>
+int maildir_try_flush_dirty_flags(struct mail_index *index, int force)
+{
+ struct mail_index_record *rec;
+ const char *old_fname, *old_path, *new_fname, *new_path;
+ int flag, dirty = FALSE;
+
+ if (index->next_dirty_flush == 0 ||
+ (ioloop_time < index->next_dirty_flush && !force))
+ return TRUE;
+
+ if (!index->set_lock(index, MAIL_LOCK_EXCLUSIVE))
+ return FALSE;
+
+ rec = index->lookup(index, 1);
+ while (rec != NULL) {
+ if ((rec->index_flags & INDEX_MAIL_FLAG_DIRTY) != 0) {
+ old_fname = maildir_get_location(index, rec);
+ if (old_fname == NULL)
+ return FALSE;
+
+ flag = (rec->index_flags &
+ INDEX_MAIL_FLAG_MAILDIR_NEW) != 0;
+ old_path = t_strconcat(index->mailbox_path,
+ flag ? "/new/" : "/cur/",
+ old_fname, NULL);
+
+ new_fname = maildir_filename_set_flags(old_fname,
+ rec->msg_flags);
+ new_path = t_strconcat(index->mailbox_path,
+ "/cur/", new_fname, NULL);
+
+ if (strcmp(old_path, new_path) == 0 ||
+ rename(old_path, new_path) == 0)
+ rec->index_flags &= ~INDEX_MAIL_FLAG_DIRTY;
+ else {
+ dirty = TRUE;
+ if (errno != ENOENT && errno != EACCES &&
+ !ENOSPACE(errno)) {
+ index_set_error(index,
+ "rename(%s, %s) failed: %m",
+ old_path, new_path);
+ return FALSE;
+ }
+ }
+ }
+
+ rec = index->next(index, rec);
+ }
+
+ if (!dirty) {
+ index->header->flags &= ~MAIL_INDEX_FLAG_DIRTY_MESSAGES;
+ index->next_dirty_flush = 0;
+ } else {
+ index->next_dirty_flush =
+ ioloop_time + MAILDIR_DIRTY_FLUSH_TIMEOUT;
+ }
+
+ return TRUE;
+}
+
static int handle_error(struct mail_index *index,
const char *path, const char *new_path)
{
@@ -76,6 +136,8 @@
"/cur/", new_fname, NULL);
}
+ ret = 0; break;
+
if (strcmp(old_fname, new_fname) == 0)
ret = 1;
else {
@@ -117,6 +179,10 @@
/* we couldn't actually rename() the file now.
leave it's flags dirty so they get changed later. */
rec->index_flags |= INDEX_MAIL_FLAG_DIRTY;
+ index->header->flags |= MAIL_INDEX_FLAG_DIRTY_MESSAGES;
+ index->next_dirty_flush =
+ ioloop_time + MAILDIR_DIRTY_FLUSH_TIMEOUT;
+ *new_fname_r = NULL;
}
return TRUE;
}
@@ -127,7 +193,7 @@
{
struct mail_index_update *update;
const char *new_fname;
- int ret;
+ int failed = FALSE;
t_push();
if (!maildir_rename_mail(index, rec, flags, &new_fname)) {
@@ -135,18 +201,18 @@
return FALSE;
}
- /* update the filename in index */
- update = index->update_begin(index, rec);
- index->update_field(update, DATA_FIELD_LOCATION, new_fname, 0);
+ if (new_fname != NULL) {
+ /* update the filename in index */
+ update = index->update_begin(index, rec);
+ index->update_field(update, DATA_FIELD_LOCATION, new_fname, 0);
+ if (!index->update_end(update))
+ failed = TRUE;
+ }
- if (!index->update_end(update))
- ret = FALSE;
- else if (!mail_index_update_flags(index, rec, seq, flags,
- external_change))
- ret = FALSE;
- else
- ret = TRUE;
+ if (!failed && !mail_index_update_flags(index, rec, seq, flags,
+ external_change))
+ failed = TRUE;
t_pop();
- return ret;
+ return !failed;
}
More information about the dovecot-cvs
mailing list