From: Andrea Corallo Date: Fri, 26 Mar 2021 07:06:09 +0000 (+0100) Subject: * Prevent stale eln loading checking file timestamp before load (bug#46617) X-Git-Tag: emacs-28.0.90~2727^2~51 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=79b8b6ca45ad707d86244882430e275efd95cdb9;p=emacs.git * 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. --- diff --git a/src/lread.c b/src/lread.c index 56717dba810..e8c257a13cc 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 ();