From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#28156: Emacs quietly munges symlink contents Date: Sun, 20 Aug 2017 03:28:04 -0700 Organization: UCLA Computer Science Department Message-ID: <68b2e6ef-bf0b-ebcf-c577-d296952d593f@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2AB0D6EE10F96C31D6D9FEDB" X-Trace: blaine.gmane.org 1503224959 20351 195.159.176.226 (20 Aug 2017 10:29:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 20 Aug 2017 10:29:19 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Cc: Michael Albinus To: 28156@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Aug 20 12:29:15 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1djNTg-0004c7-PK for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 Aug 2017 12:29:08 +0200 Original-Received: from localhost ([::1]:38429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djNTl-0007Pz-K5 for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 Aug 2017 06:29:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djNTd-0007OR-Fj for bug-gnu-emacs@gnu.org; Sun, 20 Aug 2017 06:29:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djNTa-0007MC-6c for bug-gnu-emacs@gnu.org; Sun, 20 Aug 2017 06:29:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37420) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1djNTa-0007M8-2d for bug-gnu-emacs@gnu.org; Sun, 20 Aug 2017 06:29:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1djNTZ-0007LB-TE for bug-gnu-emacs@gnu.org; Sun, 20 Aug 2017 06:29:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Aug 2017 10:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 28156 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Emacs bug reports and feature requests Original-Received: via spool by submit@debbugs.gnu.org id=B.150322490328165 (code B ref -1); Sun, 20 Aug 2017 10:29:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Aug 2017 10:28:23 +0000 Original-Received: from localhost ([127.0.0.1]:46101 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1djNSw-0007KD-Ps for submit@debbugs.gnu.org; Sun, 20 Aug 2017 06:28:23 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56291) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1djNSu-0007Jz-0S for submit@debbugs.gnu.org; Sun, 20 Aug 2017 06:28:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djNSn-0007Bj-9k for submit@debbugs.gnu.org; Sun, 20 Aug 2017 06:28:14 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:59714) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djNSn-0007Bb-5x for submit@debbugs.gnu.org; Sun, 20 Aug 2017 06:28:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djNSl-00074W-Gv for bug-gnu-emacs@gnu.org; Sun, 20 Aug 2017 06:28:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djNSi-0007Au-8W for bug-gnu-emacs@gnu.org; Sun, 20 Aug 2017 06:28:11 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:48874) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djNSh-0007AZ-T7 for bug-gnu-emacs@gnu.org; Sun, 20 Aug 2017 06:28:08 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 794411608A4; Sun, 20 Aug 2017 03:28:06 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id M9LfqvXmH0wX; Sun, 20 Aug 2017 03:28:05 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 5A39116088A; Sun, 20 Aug 2017 03:28:05 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id wot3QFsHQiju; Sun, 20 Aug 2017 03:28:05 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.153.184.153]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 30E09160882; Sun, 20 Aug 2017 03:28:05 -0700 (PDT) Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:135931 Archived-At: This is a multi-part message in MIME format. --------------2AB0D6EE10F96C31D6D9FEDB Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Tags: patch The attached patch fixes some Emacs behavior that disagrees with the=20 documentation. Although the user manual says that make-symbolic-link "do= es not expand the argument TARGET", Emacs expands leading "~" in the target.= Also,=20 file-symlink-p quietly munges symlink contents if they appear to be a Tra= mp file=20 name. This behavior makes it impossible to write Emacs code that deals wi= th=20 arbitrary local symbolic links, and Emacs mishandles copying of some syml= inks=20 for this reason. At the operating system level, symlink targets are merel= y=20 strings, and are not file names that are interpreted (any interpretation = occurs=20 later, only when the symlinks are followed), and Emacs should be consiste= nt with=20 that. It strikes me that a similar change probably needs to be made to Tramp, s= o that=20 remote symlinks also can be arbitrary strings too. However, that's outsid= e my=20 expertise so this patch affects only local symlink contents. --------------2AB0D6EE10F96C31D6D9FEDB Content-Type: text/x-patch; name="0001-Do-not-munge-contents-of-local-symbolic-links.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-Do-not-munge-contents-of-local-symbolic-links.patch" =46rom faf68f4979509cd61b5f666479b66ec5b37594d6 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 20 Aug 2017 03:13:52 -0700 Subject: [PATCH] Do not munge contents of local symbolic links This lets Emacs deal with arbitrary local symlinks without mishandling their contents. For example, (progn (shell-command "ln -fs '~' 'x'") (rename-file "x" "/tmp/x")) now consistently creates a symbolic link from '/tmp/x' to '~'. Formerly, it did that only if the working directory was on the same filesystem as /tmp; otherwise, it expanded the '~' to the user's home directory. * etc/NEWS: Document the change. * src/fileio.c (Fmake_symbolic_link): Do not expand leading "~" in the target, and look for special constructs only in the new link name, not the target. (emacs_readlinkat): Do not preprend "/:" to the link target if it starts with "/" and contains ":" before NUL. * test/lisp/net/tramp-tests.el (tramp-test21-file-links): Adjust to new behavior. * test/src/fileio-tests.el (try-link): Rename from try-char, and accept a string instead of a char. All uses changed. (fileio-tests--symlink-failure): Also test leading ~, and "/:", to test the new behavior. --- etc/NEWS | 8 ++++++++ src/fileio.c | 18 ------------------ test/lisp/net/tramp-tests.el | 9 ++++++--- test/src/fileio-tests.el | 21 ++++++++++----------- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 7774d75..104ee04 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1204,6 +1204,14 @@ instead of to utf-8. Before this change, Emacs wo= uld sometimes mishandle file names containing these control characters. =20 +++ +** 'file-attributes', 'file-symlink-p' and 'make-symbolic-link' no +longer quietly mutate the target of a local symbolic link. In +particular, 'file-attributes' and 'file-symlink-p' no longer prepend +"/:" to some targets of local symbolic links, and 'make-symbolic-link' +no longer expands '~' at the start of a link target. This change lets +Emacs access and copy arbitrary local symbolic links. + ++++ ** Module functions are now implemented slightly differently; in particular, the function 'internal--module-call' has been removed. Code that depends on undocumented internals of the module system might diff --git a/src/fileio.c b/src/fileio.c index f954ac1..ce243c3 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2423,21 +2423,8 @@ This happens for interactive use with M-x. */) Lisp_Object encoded_target, encoded_linkname; =20 CHECK_STRING (target); - /* If the link target has a ~, we must expand it to get - a truly valid file name. Otherwise, do not expand; - we want to permit links to relative file names. */ - if (SREF (target, 0) =3D=3D '~') - target =3D Fexpand_file_name (target, Qnil); - linkname =3D expand_cp_target (target, linkname); =20 - /* If the file name has special constructs in it, - call the corresponding file handler. */ - handler =3D Ffind_file_name_handler (target, Qmake_symbolic_link); - if (!NILP (handler)) - return call4 (handler, Qmake_symbolic_link, target, - linkname, ok_if_already_exists); - /* If the new link name has special constructs in it, call the corresponding file handler. */ handler =3D Ffind_file_name_handler (linkname, Qmake_symbolic_link); @@ -2635,11 +2622,6 @@ emacs_readlinkat (int fd, char const *filename) return Qnil; =20 val =3D build_unibyte_string (buf); - if (buf[0] =3D=3D '/' && strchr (buf, ':')) - { - AUTO_STRING (slash_colon, "/:"); - val =3D concat2 (slash_colon, val); - } if (buf !=3D readlink_buf) xfree (buf); val =3D DECODE_FILE (val); diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 9dc276b..0740996 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -2538,13 +2538,16 @@ tramp--test-backtrace (should-error (make-symbolic-link tmp-name1 tmp-name2)) (make-symbolic-link tmp-name1 tmp-name2 'ok-if-already-exists) (should (file-symlink-p tmp-name2)) - ;; `tmp-name3' is a local file name. - (should-error (make-symbolic-link tmp-name1 tmp-name3))) + ;; `tmp-name3' is a local file name, so its target is not + ;; interpreted. + (make-symbolic-link tmp-name1 tmp-name3) + (should (equal tmp-name1 (file-symlink-p tmp-name3)))) =20 ;; Cleanup. (ignore-errors (delete-file tmp-name1) - (delete-file tmp-name2))) + (delete-file tmp-name2) + (delete-file tmp-name3))) =20 ;; Check `add-name-to-file'. (unwind-protect diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el index 2ef1b55..5103d2f 100644 --- a/test/src/fileio-tests.el +++ b/test/src/fileio-tests.el @@ -19,14 +19,13 @@ =20 (require 'ert) =20 -(defun try-char (char link) - (let ((target (string char))) - (make-symbolic-link target link) - (let* ((read-link (file-symlink-p link)) - (failure (unless (string-equal target read-link) - (list 'string-equal target read-link)))) - (delete-file link) - failure))) +(defun try-link (target link) + (make-symbolic-link target link) + (let* ((read-link (file-symlink-p link)) + (failure (unless (string-equal target read-link) + (list 'string-equal target read-link)))) + (delete-file link) + failure)) =20 (defun fileio-tests--symlink-failure () (let* ((dir (make-temp-file "fileio" t)) @@ -36,9 +35,9 @@ fileio-tests--symlink-failure (char 0)) (while (and (not failure) (< char 127)) (setq char (1+ char)) - (unless (=3D char ?~) - (setq failure (try-char char link)))) - failure) + (setq failure (try-link (string char) link))) + (or failure + (try-link "/:" link))) (delete-directory dir t)))) =20 (ert-deftest fileio-tests--odd-symlink-chars () --=20 2.7.4 --------------2AB0D6EE10F96C31D6D9FEDB--