From 107514a6e21f2c434cdae0eca76fe0a60e287ac8 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Thu, 10 Sep 2020 07:35:29 +0200 Subject: [PATCH] * Fix rename file error when reloading the same file from an sys eln dir. * src/comp.c (Fnative_elisp_load): Don't rename files we don't have the permission for. --- src/comp.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/comp.c b/src/comp.c index 5880224ac77..4550833a6a2 100644 --- a/src/comp.c +++ b/src/comp.c @@ -4924,17 +4924,24 @@ DEFUN ("native-elisp-load", Fnative_elisp_load, Snative_elisp_load, 1, 2, 0, xsignal2 (Qnative_lisp_load_failed, build_string ("file does not exists"), filename); struct Lisp_Native_Comp_Unit *comp_u = allocate_native_comp_unit (); - if (!NILP (Fgethash (filename, all_loaded_comp_units_h, Qnil))) + + if (!NILP (Fgethash (filename, all_loaded_comp_units_h, Qnil)) + && !NILP (Ffile_writable_p (filename))) { /* If in this session there was ever a file loaded with this name rename before loading it to make sure we always get a new handle! */ Lisp_Object tmp_filename = - Fmake_temp_file_internal (filename, make_fixnum (0), - build_string (".eln"), Qnil); - Frename_file (filename, tmp_filename, Qnil); - comp_u->handle = dynlib_open (SSDATA (tmp_filename)); - Frename_file (tmp_filename, filename, Qnil); + Fmake_temp_file_internal (filename, Qnil, build_string (".eln.tmp"), + Qnil); + if (NILP (Ffile_writable_p (tmp_filename))) + comp_u->handle = dynlib_open (SSDATA (filename)); + else + { + Frename_file (filename, tmp_filename, Qt); + comp_u->handle = dynlib_open (SSDATA (tmp_filename)); + Frename_file (tmp_filename, filename, Qnil); + } } else comp_u->handle = dynlib_open (SSDATA (filename)); -- 2.39.5