From: Adam Borowski Date: Sun, 17 Dec 2017 12:36:21 +0000 (+0100) Subject: manually touch atime when reading a mbox file X-Git-Tag: mutt-1-10-rel~102 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=489a1c394c29e4b12b705b62da413f322406326f;p=mutt manually touch atime when reading a mbox file The only common use of atime left is local mail agents leaving a mark on mbox file after the mail has been read. And, since POSIX-2008, it is possible to use futimens() to alter atime even on filesystems mounted with noatime. There's no extra cost for doing this on when atime updates are enabled: the inode will be dirty already. --- diff --git a/configure.ac b/configure.ac index 8618ddc3..168d1dd9 100644 --- a/configure.ac +++ b/configure.ac @@ -448,6 +448,9 @@ AC_CHECK_FUNCS(ftruncate, , [AC_CHECK_LIB(x, chsize)]) dnl SCO has strftime() in libintl AC_CHECK_FUNCS(strftime, , [AC_CHECK_LIB(intl, strftime)]) +dnl Set the atime of files +AC_CHECK_FUNCS(futimens) + dnl AIX may not have fchdir() AC_CHECK_FUNCS(fchdir, , [mutt_cv_fchdir=no]) diff --git a/main.c b/main.c index ebe27985..dcfb02b8 100644 --- a/main.c +++ b/main.c @@ -392,6 +392,12 @@ static void show_version (void) #else "-HAVE_RESIZETERM " #endif + +#ifdef HAVE_FUTIMENS + "+HAVE_FUTIMENS " +#else + "-HAVE_FUTIMENS " +#endif ); puts ( diff --git a/mbox.c b/mbox.c index 57d58b70..37933273 100644 --- a/mbox.c +++ b/mbox.c @@ -436,6 +436,7 @@ static int mbox_open_mailbox (CONTEXT *ctx) rc = mmdf_parse_mailbox (ctx); else rc = -1; + mutt_touch_atime (fileno (ctx->fp)); mbox_unlock_mailbox (ctx); mutt_unblock_signals (); @@ -1257,6 +1258,8 @@ int mutt_reopen_mailbox (CONTEXT *ctx, int *index_hint) return (-1); } + mutt_touch_atime (fileno (ctx->fp)); + /* now try to recover the old flags */ index_hint_set = (index_hint == NULL); diff --git a/muttlib.c b/muttlib.c index eaf8429d..d491650d 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1942,6 +1942,16 @@ void mutt_set_mtime (const char* from, const char* to) } } +/* set atime to current time, just as read() would do on !noatime. + * Silently ignored if unsupported. */ +void mutt_touch_atime (int f) +{ +#ifdef HAVE_FUTIMENS + struct timespec times[2]={{0,UTIME_NOW},{0,UTIME_OMIT}}; + futimens(f, times); +#endif +} + const char *mutt_make_version (void) { static char vstring[STRING]; diff --git a/protos.h b/protos.h index 63d11c62..0b37fc1e 100644 --- a/protos.h +++ b/protos.h @@ -122,6 +122,7 @@ time_t mutt_local_tz (time_t); time_t mutt_mktime (struct tm *, int); time_t mutt_parse_date (const char *, HEADER *); int is_from (const char *, char *, size_t, time_t *); +void mutt_touch_atime (int); const char *mutt_attach_fmt ( char *dest,