summaryrefslogtreecommitdiffstats
path: root/mh.c
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2018-06-14 16:17:56 +0800
committerKevin McCarthy <kevin@8t8.us>2018-06-18 13:05:15 +0800
commit120f63a9bea469e9980cf0270a1bb54841051015 (patch)
tree6f79cf91c8b53750d7daee1708bcfc929539e077 /mh.c
parent7ec17b81882bcc58fd7f73bef8ef4b74439eb3f8 (diff)
Convert context and buffy to use nanosecond timestamps.
The inotify interface has an unfortunate side effect of making Mutt react too quickly to new mail. Sometimes, the mail is only half-delivered when the mailbox is checked. Because Mutt is using the stat mtime - seconds resolution - this means it won't realize there are more messages delivered during the same second. Nanosecond resolution fields were standardized in POSIX.1-2008, so check for and use those if they are available.
Diffstat (limited to 'mh.c')
-rw-r--r--mh.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/mh.c b/mh.c
index 4d616e0a..a48dd832 100644
--- a/mh.c
+++ b/mh.c
@@ -80,7 +80,7 @@ struct mh_sequences
struct mh_data
{
- time_t mtime_cur;
+ struct timespec mtime_cur;
mode_t mh_umask;
};
@@ -244,7 +244,7 @@ static int mh_sequences_changed(BUFFY *b)
if ((snprintf(path, sizeof(path), "%s/.mh_sequences", b->path) < sizeof(path)) &&
(stat(path, &sb) == 0))
- return (sb.st_mtime > b->last_visited);
+ return (mutt_stat_timespec_compare (&sb, MUTT_STAT_MTIME, &b->last_visited) > 0);
return -1;
}
@@ -260,7 +260,7 @@ static int mh_already_notified(BUFFY *b, int msgno)
if ((snprintf(path, sizeof(path), "%s/%d", b->path, msgno) < sizeof(path)) &&
(stat(path, &sb) == 0))
- return (sb.st_mtime <= b->last_visited);
+ return (mutt_stat_timespec_compare (&sb, MUTT_STAT_MTIME, &b->last_visited) <= 0);
return -1;
}
@@ -727,20 +727,20 @@ static void maildir_update_mtime (CONTEXT * ctx)
{
snprintf (buf, sizeof (buf), "%s/%s", ctx->path, "cur");
if (stat (buf, &st) == 0)
- data->mtime_cur = st.st_mtime;
+ mutt_get_stat_timespec (&data->mtime_cur, &st, MUTT_STAT_MTIME);
snprintf (buf, sizeof (buf), "%s/%s", ctx->path, "new");
}
else
{
snprintf (buf, sizeof (buf), "%s/.mh_sequences", ctx->path);
if (stat (buf, &st) == 0)
- data->mtime_cur = st.st_mtime;
+ mutt_get_stat_timespec (&data->mtime_cur, &st, MUTT_STAT_MTIME);
strfcpy (buf, ctx->path, sizeof (buf));
}
if (stat (buf, &st) == 0)
- ctx->mtime = st.st_mtime;
+ mutt_get_stat_timespec (&ctx->mtime, &st, MUTT_STAT_MTIME);
}
/*
@@ -2115,17 +2115,17 @@ static int maildir_check_mailbox (CONTEXT * ctx, int *index_hint)
return -1;
/* determine which subdirectories need to be scanned */
- if (st_new.st_mtime > ctx->mtime)
+ if (mutt_stat_timespec_compare (&st_new, MUTT_STAT_MTIME, &ctx->mtime) > 0)
changed = 1;
- if (st_cur.st_mtime > data->mtime_cur)
+ if (mutt_stat_timespec_compare (&st_cur, MUTT_STAT_MTIME, &data->mtime_cur) > 0)
changed |= 2;
if (!changed)
return 0; /* nothing to do */
/* update the modification times on the mailbox */
- data->mtime_cur = st_cur.st_mtime;
- ctx->mtime = st_new.st_mtime;
+ mutt_get_stat_timespec (&data->mtime_cur, &st_cur, MUTT_STAT_MTIME);
+ mutt_get_stat_timespec (&ctx->mtime, &st_new, MUTT_STAT_MTIME);
/* do a fast scan of just the filenames in
* the subdirectories that have changed.
@@ -2280,14 +2280,15 @@ static int mh_check_mailbox (CONTEXT * ctx, int *index_hint)
if (i == -1 && stat (buf, &st_cur) == -1)
modified = 1;
- if (st.st_mtime > ctx->mtime || st_cur.st_mtime > data->mtime_cur)
+ if ((mutt_stat_timespec_compare (&st, MUTT_STAT_MTIME, &ctx->mtime) > 0) ||
+ (mutt_stat_timespec_compare (&st_cur, MUTT_STAT_MTIME, &data->mtime_cur) > 0))
modified = 1;
if (!modified)
return 0;
- data->mtime_cur = st_cur.st_mtime;
- ctx->mtime = st.st_mtime;
+ mutt_get_stat_timespec (&data->mtime_cur, &st_cur, MUTT_STAT_MTIME);
+ mutt_get_stat_timespec (&ctx->mtime, &st, MUTT_STAT_MTIME);
memset (&mhs, 0, sizeof (mhs));