]> granicus.if.org Git - mutt/commitdiff
manually touch atime when reading a mbox file
authorAdam Borowski <kilobyte@angband.pl>
Sun, 17 Dec 2017 12:36:21 +0000 (13:36 +0100)
committerKevin McCarthy <kevin@8t8.us>
Sun, 17 Dec 2017 22:31:29 +0000 (14:31 -0800)
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.

configure.ac
main.c
mbox.c
muttlib.c
protos.h

index 8618ddc32ecb9c0296f80c16c55c22cc9a8b0344..168d1dd98559718a348fda9ef86138f33b9d6990 100644 (file)
@@ -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 ebe27985b819cafad941b94b19f958494fcac530..dcfb02b8bf7221be70371c0ea237c6b867d742b3 100644 (file)
--- 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 57d58b70bfdbd732caee2626f6a3c637f809041d..379332732fdebda0a1f7248a760abb6f3943154e 100644 (file)
--- 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);
index eaf8429de0ffd5b269add7ab173889fcae363426..d491650d9b80116fb5eb226f8d01322ddbda8518 100644 (file)
--- 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];
index 63d11c626e5e31fb7b6dd448ec5308e1b8e913dd..0b37fc1e6e922574df225c04f4dc526baa228ea6 100644 (file)
--- 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,