unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: spucci <slpnabble@blackberry-hill.com>
Cc: 8035@debbugs.gnu.org
Subject: bug#8035: Processing of .. in a file path after going thru symlink
Date: Thu, 26 Aug 2021 18:29:54 +0200	[thread overview]
Message-ID: <877dg8yxrx.fsf@gnus.org> (raw)
In-Reply-To: <30918394.post@talk.nabble.com> (spucci's message of "Sun, 13 Feb 2011 19:05:40 -0800 (PST)")

spucci <slpnabble@blackberry-hill.com> writes:

> When emacs attempts to find a file with "../" as a path component, it
> appears to be "smart" about it and simply remove the previous directory path
> (e.g., "foo/bar/../x" gets converted to "foo/x").  But if bar is a symlink,
> then it doesn't properly find the file.  So in compiler output, which
> references such files, the next-error function fails to find the file with
> the given name. 
>
> mkdir dest 
> mkdir dest/subdir 
> mkdir src 
> ln -s ../dest/subdir src/subdir 
> echo "#error This is an error" > dest/foo.c 
>
> Now M-x compile, and give it cc -c src/subdir/../foo.c 
>
> *compilation* buffer has: 
> cc -c src/subdir/../foo.c 
> src/subdir/../foo.c:1:2: error: #error This is an error 
>
> and do a next-error: Emacs complains it can't find the file. 

This is an even more foundational problem:

(file-exists-p "/tmp/comp/src/subdir/../foo.c")
=> nil
(file-truename "/tmp/comp/src/subdir/../foo.c")
=> "/tmp/comp/dest/foo.c"
(file-exists-p (file-truename "/tmp/comp/src/subdir/../foo.c"))
=> t

And this is because:

static Lisp_Object
check_file_access (Lisp_Object file, Lisp_Object operation, int amode)
{
  file = Fexpand_file_name (file, Qnil);

I'm guessing it's calling expand-file-name here to resolve "~"?  It's
also a micro-optimisation, I guess -- collapsing "parent/.." textually
without checking the file system is very cheap.

But...  this does mean that `file-exists-p' and friends are unreliable
in the presence of symlinks, which is pretty depressing.  I think that
`expand-file-name' call in check_file_access should be changed to
something that just does the "~" expansion.

Any opinions?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





  parent reply	other threads:[~2021-08-26 16:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-14  3:05 bug#8035: Processing of .. in a file path after going thru symlink spucci
2011-02-19 21:37 ` Glenn Morris
2011-02-20  2:35   ` Steve Pucci
2011-02-20  2:41     ` Steve Pucci
2021-08-26 16:29 ` Lars Ingebrigtsen [this message]
2021-08-26 16:44   ` Eli Zaretskii
2021-08-26 17:03     ` Lars Ingebrigtsen
2021-08-26 17:08       ` Eli Zaretskii
2021-08-26 17:24         ` Lars Ingebrigtsen
2021-08-26 17:30           ` Eli Zaretskii
2021-08-26 16:53   ` Andreas Schwab
2021-08-26 17:04     ` Lars Ingebrigtsen
2021-08-26 17:19       ` Andreas Schwab
2021-08-26 17:30 ` Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=877dg8yxrx.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=8035@debbugs.gnu.org \
    --cc=slpnabble@blackberry-hill.com \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).