unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#66340: 30.0.50; file-relative-name not correct if default-directory with symbolic link
@ 2023-10-04 11:25 Nan JunJie
  2023-10-04 16:49 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: Nan JunJie @ 2023-10-04 11:25 UTC (permalink / raw)
  To: 66340


for example, say I have below symbolic link:

/home/nanjj/tmp/nanjj.github.io ->
/home/nanjj/src/githu.com/nanjj/nanjj.github.io

I run (file-relative-name "/tmp") under /home/nanjj/tmp/nanjj.github.io,
it should output "../../../../../../../tmp" instead of
"../../../../tmp".

One possible fix listed as below:

From 21936e7aca04db7ab00f98d0265afa900d27177e Mon Sep 17 00:00:00 2001
From: Nan Jun Jie <nanjunjie@139.com>
Date: Wed, 4 Oct 2023 19:10:04 +0800
Subject: [PATCH] Fixed file-relative-name issue

if default-directory has symbolic link in the path, the
file-relative-name result is not correct.
---
 lisp/files.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index ddae097f1d1..124710dde48 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -5545,8 +5545,9 @@ file-relative-name
 on a DOS/Windows machine, it returns FILENAME in expanded form."
   (save-match-data
     (setq directory
-	  (file-name-as-directory (expand-file-name (or directory
-							default-directory))))
+          (file-truename
+	   (file-name-as-directory (expand-file-name (or directory
+							 default-directory)))))
     (setq filename (expand-file-name filename))
     (let ((fremote (file-remote-p filename))
 	  (dremote (file-remote-p directory))
-- 
2.40.1



-- 
https://nanjj.srht.site
 ∧ ∧︵
ミ^ō^ミ灬)~
https://nanjj.github.io






^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#66340: 30.0.50; file-relative-name not correct if default-directory with symbolic link
  2023-10-04 11:25 bug#66340: 30.0.50; file-relative-name not correct if default-directory with symbolic link Nan JunJie
@ 2023-10-04 16:49 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2023-10-04 16:49 UTC (permalink / raw)
  To: Nan JunJie; +Cc: 66340

> From: Nan JunJie <nanjunjie@139.com>
> Date: Wed, 04 Oct 2023 19:25:01 +0800
> 
> 
> for example, say I have below symbolic link:
> 
> /home/nanjj/tmp/nanjj.github.io ->
> /home/nanjj/src/githu.com/nanjj/nanjj.github.io
> 
> I run (file-relative-name "/tmp") under /home/nanjj/tmp/nanjj.github.io,
> it should output "../../../../../../../tmp" instead of
> "../../../../tmp".
> 
> One possible fix listed as below:

Thanks, but that fix cannot be right.  file-relative-name is a
purely-syntactic function, which analyzes the argument file name
without ever hitting the disk.  So calling file-truename from it is
not TRT.

I think your expectations from file-relative-name are simply
incorrect: if an application needs to resolve symlinks, it should do
that itself, like this:

  (file-relative-name "/tmp" (file-truename default-directory))

IOW, I don't think there's a bug in file-relative-name in this case.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-04 16:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-04 11:25 bug#66340: 30.0.50; file-relative-name not correct if default-directory with symbolic link Nan JunJie
2023-10-04 16:49 ` Eli Zaretskii

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).