emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/native-comp 79b8b6c: * Prevent stale eln loading checking file t


From: Andrea Corallo
Subject: feature/native-comp 79b8b6c: * Prevent stale eln loading checking file timestamp before load (bug#46617)
Date: Fri, 26 Mar 2021 03:53:33 -0400 (EDT)

branch: feature/native-comp
commit 79b8b6ca45ad707d86244882430e275efd95cdb9
Author: Andrea Corallo <akrl@sdf.org>
Commit: Andrea Corallo <akrl@sdf.org>

    * Prevent stale eln loading checking file timestamp before load (bug#46617)
    
        * src/lread.c (maybe_swap_for_eln): Add file timestamp check.
        (openp): Update 'maybe_swap_for_eln' call sites.
---
 src/lread.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/lread.c b/src/lread.c
index 56717db..e8c257a 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1649,7 +1649,8 @@ directories, make sure the PREDICATE function returns 
`dir-ok' for them.  */)
    If found replace the content of FILENAME and FD. */
 
 static void
-maybe_swap_for_eln (bool no_native, Lisp_Object *filename, int *fd)
+maybe_swap_for_eln (bool no_native, Lisp_Object *filename, int *fd,
+                   struct timespec mtime)
 {
 #ifdef HAVE_NATIVE_COMP
   struct stat eln_st;
@@ -1686,13 +1687,19 @@ maybe_swap_for_eln (bool no_native, Lisp_Object 
*filename, int *fd)
            emacs_close (eln_fd);
          else
            {
-             *filename = eln_name;
-             emacs_close (*fd);
-             *fd = eln_fd;
-             /* Store the eln -> el relation.  */
-             Fputhash (Ffile_name_nondirectory (eln_name),
-                       src_name, Vcomp_eln_to_el_h);
-             return;
+             struct timespec eln_mtime = get_stat_mtime (&eln_st);
+             if (timespec_cmp (eln_mtime, mtime) >= 0)
+               {
+                 *filename = eln_name;
+                 emacs_close (*fd);
+                 *fd = eln_fd;
+                 /* Store the eln -> el relation.  */
+                 Fputhash (Ffile_name_nondirectory (eln_name),
+                           src_name, Vcomp_eln_to_el_h);
+                 return;
+               }
+             else
+               emacs_close (eln_fd);
            }
        }
     }
@@ -1940,7 +1947,8 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object 
suffixes,
                  }
                else
                  {
-                   maybe_swap_for_eln (no_native, &string, &fd);
+                   maybe_swap_for_eln (no_native, &string, &fd,
+                                       get_stat_mtime (&st));
                    /* We succeeded; return this descriptor and filename.  */
                    if (storeptr)
                      *storeptr = string;
@@ -1952,7 +1960,8 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object 
suffixes,
            /* No more suffixes.  Return the newest.  */
            if (0 <= save_fd && ! CONSP (XCDR (tail)))
              {
-               maybe_swap_for_eln (no_native, &save_string, &save_fd);
+               maybe_swap_for_eln (no_native, &save_string, &save_fd,
+                                   save_mtime);
                if (storeptr)
                  *storeptr = save_string;
                SAFE_FREE ();



reply via email to

[Prev in Thread] Current Thread [Next in Thread]