all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "DE BACKER Jurgen (EXT)" via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: "67930@debbugs.gnu.org" <67930@debbugs.gnu.org>
Subject: bug#67930: 29.1; emacs 29.1 follows symlinks when a grep result is selected
Date: Thu, 4 Jan 2024 11:10:56 +0000	[thread overview]
Message-ID: <AS2PR08MB100530C3FE4A965638B72314A95672@AS2PR08MB10053.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <8334vtdvi6.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 5120 bytes --]

> -----Original Message-----
> From: Eli Zaretskii <eliz@gnu.org>
> Sent: Saturday, December 23, 2023 12:11 PM
> To: DE BACKER Jurgen (EXT) <jurgen.de-backer.ext@eurocontrol.int>
> Cc: 67930@debbugs.gnu.org
> Subject: Re: bug#67930: 29.1; emacs 29.1 follows symlinks when a grep result
> is selected
>
> > From: "DE BACKER Jurgen (EXT)" <jurgen.de-backer.ext@eurocontrol.int>
> > CC: "67930@debbugs.gnu.org" <67930@debbugs.gnu.org>
> > Date: Fri, 22 Dec 2023 16:20:42 +0000
> >
> > > From: Eli Zaretskii <eliz@gnu.org>
> > > Sent: Wednesday, December 20, 2023 7:47 PM
> > > To: DE BACKER Jurgen (EXT) <jurgen.de-backer.ext@eurocontrol.int>
> > > Cc: 67930@debbugs.gnu.org
> > > Subject: Re: bug#67930: 29.1; emacs 29.1 follows symlinks when a
> > > grep result is selected
> > >
> > > Thanks, but I don't think this is a matter of user preferences.  We
> > > replaced expand-file-name there by file-truename because in some
> > > cases the former doesn't work: it expands to a file that doesn't
> > > exist.  See bug#8035, where such cases are presented.  We cannot ask
> > > the user to set or reset this option each time they need to work with
> these or those file names.
> > >
> > > So I don't think the fix you propose is the right one.  I think we
> > > need to use expand-file-name where it works, and file-truename where
> > > expand-file- name doesn't work.  Or maybe just try expand-file-name
> > > first, and if that produces a file name that fails file-exists-p, try file-
> truename.
> > >
> > > Would you like to propose and test a patch along these lines?
> >
> > Hi Eli,
> >
> > Please find attached a patch that does this: first we  try to expand
> > the file name with expand-file-name and if this fails, retry with file-
> truename.
>
> Thanks.  I have a couple of minor comments:
>
> > # In emacs 29.1, when clicking on a file link in the *grep* results
> > buffer, # symlinks are resolved to the actual filename(s). In some cases this
> is not preferable.
> > #
> > # This patch -1 will first use the previous behaviour (using expand-file-
> name) to resolve a (relative) filename
> > #            -2 if this fails (i.e. the result is not an existing file), we try with the
> new behaviour
> > #                which uses function file-truename.
> > #
> > # In emacs 29.1 expand-file-name was replaced by file-truename to solve
> bug #8035,
> > #   because in specific cases expand-file-name returned a wrong/non
> existing file.
> > # Unlike expand-file-name, file-truename follows symlinks.
>
> Could you please reformat this log message using our style?  The details can
> be found in the file CONTRIBUTE in the Emacs Git repository.
>
> > --- lisp/progmodes/compile.el.orig  2023-02-11 12:06:09.000000000 +0000
> > +++ lisp/progmodes/compile.el       2023-12-21 17:22:34.000688000 +0000
> > @@ -3108,7 +3108,7 @@
> >          (spec-dir (if directory
> >                        (expand-file-name directory)
> >                      default-directory))
> > -        buffer thisdir fmts name)
> > +        buffer thisdir fmts expandedname name)
> >      (if (and filename
> >               (file-name-absolute-p filename))
> >          ;; The file name is absolute.  Use its explicit directory as
> > @@ -3122,8 +3122,10 @@
> >              fmts formats)
> >        ;; For each directory, try each format string.
> >        (while (and fmts (null buffer))
> > -        (setq name (file-truename
> > -                    (file-name-concat thisdir (format (car fmts) filename)))
> > +        (setq expandedname (expand-file-name (format (car fmts) filename)
> thisdir)
> > +              name (if (file-exists-p expandedname) ;; See bug #8035 expand-
> file-name fails in specific cases
> > +                       expandedname
> > +                     (file-truename (file-name-concat thisdir (format
> > + (car fmts) filename))))
> >                buffer (and (file-exists-p name)
> >                            (find-file-noselect name))
> >                fmts (cdr fmts)))
>
> Your changes repeat the same pattern several times, so I think it would be
> better to factor out this code into a separate function, and then call that
> function in those places.  Would you like to rewrite the patch along these
> lines?
>
> Thanks again for working on this.

Hi,

Please find attached an updated patch which addresses your remarks.

All the best,
Jurgen
____

This message and any files transmitted with it are legally privileged and intended for the sole use of the individual(s) or entity to whom they are addressed. If you are not the intended recipient, please notify the sender by reply and delete the message and any attachments from your system. Any unauthorised use or disclosure of the content of this message is strictly prohibited and may be unlawful.

Nothing in this e-mail message amounts to a contractual or legal commitment on the part of EUROCONTROL, unless it is confirmed by appropriately signed hard copy.

Any views expressed in this message are those of the sender.

[-- Attachment #2: emacs-29.1_expand_file_names.patch --]
[-- Type: application/octet-stream, Size: 3040 bytes --]

Avoid resolving symlinks when selecting files in the *grep* buffer

When clicking on a file link in the *grep* results buffer, symlinks are
resolved to the actual filename(s).  In some cases this is not preferable.
This patch will first use the previous behavior (using expand-file-name)
to resolve a filename and if this fails (the result is not an existing file),
we try with the new behavior which uses function file-truename.
(In emacs 29.1 expand-file-name was replaced by file-truename to solve bug #8035;
in specific cases expand-file-name returned a wrong/non existing file.
Unlike expand-file-name, file-truename follows symlinks.)
* lisp/progmodes/compile.el: first try expand-file-name and if it fails try file-truename

--- lisp/progmodes/compile.el.orig	2023-02-11 12:06:09.000000000 +0000
+++ lisp/progmodes/compile.el	2023-12-21 17:22:34.000688000 +0000
@@ -3101,7 +3101,16 @@
       (cancel-timer next-error-highlight-timer))
   (remove-hook 'pre-command-hook
 	       #'compilation-goto-locus-delete-o))
-\f
+
+(defun safe-expand-file-name (directory filename)
+  "Expand the specified filename using expand-file-name.  If this fails,
+retry with file-truename (see bug #8035)
+Unlike expand-file-name, file-truename follows symlinks which we try to avoid if possible."
+  (let* ((expandedname (expand-file-name filename directory)))
+    (if (file-exists-p expandedname)
+        expandedname
+      (file-truename (file-name-concat directory filename)))))
+
 (defun compilation-find-file-1 (marker filename directory &optional formats)
   (or formats (setq formats '("%s")))
   (let ((dirs compilation-search-path)
@@ -3122,8 +3131,7 @@
             fmts formats)
       ;; For each directory, try each format string.
       (while (and fmts (null buffer))
-        (setq name (file-truename
-                    (file-name-concat thisdir (format (car fmts) filename)))
+        (setq name (safe-expand-file-name thisdir (format (car fmts) filename))
               buffer (and (file-exists-p name)
                           (find-file-noselect name))
               fmts (cdr fmts)))
@@ -3145,8 +3153,7 @@
         (setq thisdir (car dirs)
               fmts formats)
         (while (and fmts (null buffer))
-          (setq name (file-truename
-                      (file-name-concat thisdir (format (car fmts) filename)))
+          (setq name (safe-expand-file-name thisdir (format (car fmts) filename))
                 buffer (and (file-exists-p name)
                             (find-file-noselect name))
                 fmts (cdr fmts)))
@@ -3206,8 +3213,7 @@
               (ding) (sit-for 2))
              ((and (file-directory-p name)
                    (not (file-exists-p
-                         (setq name (file-truename
-                                     (file-name-concat name filename))))))
+                         (setq name (safe-expand-file-name name filename)))))
               (message "No `%s' in directory %s" filename origname)
               (ding) (sit-for 2))
              (t

  reply	other threads:[~2024-01-04 11:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-20 13:54 bug#67930: 29.1; emacs 29.1 follows symlinks when a grep result is selected Jurgen De Backer via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-20 18:46 ` Eli Zaretskii
2023-12-22 16:20   ` DE BACKER Jurgen (EXT) via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-23 11:10     ` Eli Zaretskii
2024-01-04 11:10       ` DE BACKER Jurgen (EXT) via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-01-06 10:35         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AS2PR08MB100530C3FE4A965638B72314A95672@AS2PR08MB10053.eurprd08.prod.outlook.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=67930@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=jurgen.de-backer.ext@eurocontrol.int \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.