GNU bug report logs - #78306
[PATCH] Skip the non-exists path when loading a file on Windows

Previous Next

Package: emacs;

Reported by: Lin Sun <sunlin7 <at> hotmail.com>

Date: Thu, 8 May 2025 00:25:02 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: Lin Sun <sunlin7 <at> hotmail.com>
Cc: 78306 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: bug#78306: [PATCH] Skip the non-exists path when loading a file on Windows
Date: Thu, 08 May 2025 08:44:35 +0300
> From: Lin Sun <sunlin7 <at> hotmail.com>
> Date: Thu, 8 May 2025 00:19:24 +0000
> 
> Emacs will searching file with a suffix even the dir is not exists.
> For example, (add-to-list 'load-path "/path-not-exists"), then (require 'debug) will lead searching the
> debug.dll/debug.elc/debug.el under the "/path-not-exists" on windows.
> 
> This patch will distinguish the non-exists-dir to skip the unnecessary file operations. 

Thanks, but I'm against this change.  faccessat is a general-purpose
function, so changing the errno it returns on Windows will affect a
lot of places in Emacs, with consequences we cannot predict.

If you want to skip directories that don't exist, or exist as files
that are non-directories, IMO the right way is to modify the loop in
openp such that in the following snippet:

  FOR_EACH_TAIL_SAFE (path)
   {
    ptrdiff_t baselen, prefixlen;

    if (EQ (path, just_use_str))
      filename = str;
    else
      filename = Fexpand_file_name (str, XCAR (path));
    if (!complete_filename_p (filename))
      /* If there are non-absolute elts in PATH (eg ".").  */
      /* Of course, this could conceivably lose if luser sets
	 default-directory to be something non-absolute...  */
      {
	filename = Fexpand_file_name (filename, BVAR (current_buffer, directory));
	if (!complete_filename_p (filename))
	  /* Give up on this path element!  */
	  continue;
      }

we verify that 'XCAR (path)' (and possibly also the current buffer's
default-directory') is an accessible directory, e.g. by using
file-accessible-directory-p.  This might benefit Posix platforms as
well, but we should benchmark the results before we decide.  (We
should also consider how likely it is that load-path will include
non-directories or directories that don't exist.)

Btw, did you benchmark the result of your proposed patch, and if so,
what is the speedup from this change?




This bug report was last modified 23 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.