Subject: Re: bug#78306: [PATCH] Skip the non-exists path when loading a file on Windows

From: Michael Albinus <[email-masked]>
Date: Thu, 08 May 2025 09:38:15 +0200

Eli Zaretskii <[email-masked]> writes:

Hi,

> 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?

I don't know whether the snippet above is also relevant for remote
files. If yes, adding a call of file-accessible-directory-p might
influence performance.

Best regards, Michael.