From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 04 08:52:25 2023 Received: (at submit) by debbugs.gnu.org; 4 Oct 2023 12:52:25 +0000 Received: from localhost ([127.0.0.1]:41796 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qo1MV-0005Hf-3H for submit@debbugs.gnu.org; Wed, 04 Oct 2023 08:52:25 -0400 Received: from lists.gnu.org ([2001:470:142::17]:35494) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qo09i-00030X-I7 for submit@debbugs.gnu.org; Wed, 04 Oct 2023 07:35:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qo09L-0006jm-8l for bug-gnu-emacs@gnu.org; Wed, 04 Oct 2023 07:34:43 -0400 Received: from n169-114.mail.139.com ([120.232.169.114]) by eggs.gnu.org with smtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qo09I-0006VE-97 for bug-gnu-emacs@gnu.org; Wed, 04 Oct 2023 07:34:43 -0400 X-RM-TagInfo: emlType=0 X-RM-SPAM: X-RM-SPAM-FLAG: 00000000 Received: from dev01 (unknown[120.244.220.4]) by rmsmtp-lg-appmail-44-12058 (RichMail) with SMTP id 2f1a651d4b91e39-2f5e6; Wed, 04 Oct 2023 19:25:12 +0800 (CST) X-RM-TRANSID: 2f1a651d4b91e39-2f5e6 From: Nan JunJie To: bug-gnu-emacs@gnu.org Subject: 30.0.50; file-relative-name not correct if default-directory with symbolic link Date: Wed, 04 Oct 2023 19:25:01 +0800 Message-ID: <87fs2q4oky.fsf@139.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=120.232.169.114; envelope-from=nanjunjie@139.com; helo=n169-114.mail.139.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 04 Oct 2023 08:52:17 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) 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 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)) --=20 2.40.1 --=20 https://nanjj.srht.site =E2=88=A7 =E2=88=A7=EF=B8=B5 =E3=83=9F^=C5=8D^=E3=83=9F=E7=81=AC)=EF=BD=9E https://nanjj.github.io From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 04 12:49:54 2023 Received: (at 66340) by debbugs.gnu.org; 4 Oct 2023 16:49:54 +0000 Received: from localhost ([127.0.0.1]:45202 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qo54M-0005rc-Bx for submit@debbugs.gnu.org; Wed, 04 Oct 2023 12:49:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41028) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qo54J-0005rI-Bk for 66340@debbugs.gnu.org; Wed, 04 Oct 2023 12:49:52 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qo53s-0007QN-6S; Wed, 04 Oct 2023 12:49:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=6H2pLTC5BSTo2a/2gzm8a2AyQq++CnxExi9AUXCQTus=; b=m0n+0WkLNOcy /mojHVNS8FruXW+MX1Jg9dPspZ0cpqPr5RPQujobBmXpcw1n1N+brADh70z0zzyETumXZYvH0DAis XR7xmSdwLhMVuAh3/FsJQR+T8qP2/toYAR/mCcY/lvVi24d31qH/VgiOaG+Uf++dPSjAcUpjuV/K3 I6gA8hoRnjNvzY1ZiMJ80/lgk+Ry+lJRmHQg6jxaXl0O95HM6otlYuJrs5dwmnmNWL4KcyIWuYqkN mEFFov+58u1qgAIBSj95F2HtBoS6F0jrzQ6zVm9slLhO32NNLUgHweKOKjpWTPdGbguVfOk4SI1bu LiTSPkFSmV718yd2Q31n/g==; Date: Wed, 04 Oct 2023 19:49:28 +0300 Message-Id: <83bkde5o4n.fsf@gnu.org> From: Eli Zaretskii To: Nan JunJie In-Reply-To: <87fs2q4oky.fsf@139.com> (message from Nan JunJie on Wed, 04 Oct 2023 19:25:01 +0800) Subject: Re: bug#66340: 30.0.50; file-relative-name not correct if default-directory with symbolic link References: <87fs2q4oky.fsf@139.com> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 66340 Cc: 66340@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Nan JunJie > 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.