all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 26911@debbugs.gnu.org, mattiase@acm.org, michael.albinus@gmx.de,
	yegortimoshenko@gmail.com
Subject: bug#26911: 25.2; eshell "cd .." doesn't work correctly with TRAMP
Date: Fri, 28 Aug 2020 22:52:28 -0700	[thread overview]
Message-ID: <47047d69-91aa-fd0d-1510-64ba7c246970@cs.ucla.edu> (raw)
In-Reply-To: <83r1rryrk0.fsf@gnu.org>

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

On 8/28/20 3:48 AM, Eli Zaretskii wrote:
> That period after the colon following the drive letter shouldn't be
> there.  As you may imagine, many Emacs commands are now broken because
> of this.  This must be fixed ASAP.

I installed the attached patch to revert the recent expand-file-changes in the 
DOS_NT case, which should fix the problem you mentioned.

This part of fileio.c is hard to follow because of the #ifdef DOS_NT and #ifdef 
WINDOWSNT and #ifdef MSDOS and whatnot. How about if we move the 
MS-Windows-specific code to a different source file instead of having that 
forest of ifdefs in fileio.c? As things stand, it's hard to maintain the 
mainline GNU code, because the way everything's arranged the Microsoft-specific 
stuff significantly obfuscates everything else.

[-- Attachment #2: 0001-Revert-recent-expand-file-name-changes-if-DOS_NT.patch --]
[-- Type: text/x-patch, Size: 4573 bytes --]

From 7d5807277ff614a337c7e4530bb8d0e0188c189b Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Fri, 28 Aug 2020 22:37:29 -0700
Subject: [PATCH] Revert recent expand-file-name changes if DOS_NT

* src/fileio.c (Fexpand_file_name): Restore pre-August-26
behavior, if DOS_NT.  This should fix the recently-introduced
expand-file-name bugs on DOS_NT (Bug#26911).
---
 src/fileio.c | 66 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 57 insertions(+), 9 deletions(-)

diff --git a/src/fileio.c b/src/fileio.c
index 66010b6878..c91af36fdf 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1372,6 +1372,14 @@ DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
 
   length = newdirlim - newdir;
 
+#ifdef DOS_NT
+  /* Ignore any slash at the end of newdir, unless newdir is
+     just "/" or "//".  */
+  while (length > 1 && IS_DIRECTORY_SEP (newdir[length - 1])
+	 && ! (length == 2 && IS_DIRECTORY_SEP (newdir[0])))
+    length--;
+#endif
+
   /* Now concatenate the directory and name to new space in the stack frame.  */
   tlen = length + file_name_as_directory_slop + (nmlim - nm) + 1;
   eassert (tlen >= file_name_as_directory_slop + 1);
@@ -1388,22 +1396,40 @@ DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
 
   if (newdir)
     {
-      if (!collapse_newdir)
+#ifndef DOS_NT
+      bool treat_as_absolute = !collapse_newdir;
+#else
+      bool treat_as_absolute = !nm[0] || IS_DIRECTORY_SEP (nm[0]);
+#endif
+      if (treat_as_absolute)
 	{
-	  /* With ~ or ~user, leave NEWDIR as-is to avoid transforming
-	     it from a symlink (or a regular file!) into a directory.  */
-	  memcpy (target, newdir, length);
-	  nbytes = length;
+#ifdef DOS_NT
+	  /* If newdir is effectively "C:/", then the drive letter will have
+	     been stripped and newdir will be "/".  Concatenating with an
+	     absolute directory in nm produces "//", which will then be
+	     incorrectly treated as a network share.  Ignore newdir in
+	     this case (keeping the drive letter).  */
+	  if (!(drive && nm[0] && IS_DIRECTORY_SEP (newdir[0])
+		&& newdir[1] == '\0'))
+#endif
+	    {
+	      /* With ~ or ~user, leave NEWDIR as-is to avoid transforming
+		 it from a symlink (or a regular file!) into a directory.  */
+	      memcpy (target, newdir, length);
+	      nbytes = length;
+	    }
 	}
       else
 	nbytes = file_name_as_directory (target, newdir, length, multibyte);
 
+#ifndef DOS_NT
       /* If TARGET ends in a directory separator, omit leading
 	 directory separators from NM so that concatenating a TARGET "/"
 	 to an NM "/foo" does not result in the incorrect "//foo".  */
       if (nbytes && IS_DIRECTORY_SEP (target[nbytes - 1]))
 	while (IS_DIRECTORY_SEP (nm[0]))
 	  nm++;
+#endif
     }
 
   memcpy (target + nbytes, nm, nmlim - nm + 1);
@@ -1420,6 +1446,7 @@ DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
 	  {
 	    *o++ = *p++;
 	  }
+#ifndef DOS_NT
 	else if (p[1] == '.' && IS_DIRECTORY_SEP (p[2]))
 	  {
 	    /* Replace "/./" with "/".  */
@@ -1432,6 +1459,18 @@ DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
 	    *o++ = *p;
 	    p += 2;
 	  }
+#else
+	else if (p[1] == '.'
+		 && (IS_DIRECTORY_SEP (p[2])
+		     || p[2] == 0))
+	  {
+	    /* If "/." is the entire filename, keep the "/".  Otherwise,
+	       just delete the whole "/.".  */
+	    if (o == target && p[2] == '\0')
+	      *o++ = *p;
+	    p += 2;
+	  }
+#endif
 	else if (p[1] == '.' && p[2] == '.'
 		 /* `/../' is the "superroot" on certain file systems.
 		    Turned off on DOS_NT systems because they have no
@@ -1445,9 +1484,7 @@ DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
 #endif
 		 && (IS_DIRECTORY_SEP (p[3]) || p[3] == 0))
 	  {
-#ifdef WINDOWSNT
-	    char *prev_o = o;
-#endif
+#ifndef DOS_NT
 	    while (o != target)
 	      {
 		o--;
@@ -1459,11 +1496,22 @@ DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
 		    break;
 		  }
 	      }
-#ifdef WINDOWSNT
+#else
+# ifdef WINDOWSNT
+	    char *prev_o = o;
+# endif
+	    while (o != target && (--o, !IS_DIRECTORY_SEP (*o)))
+	      continue;
+# ifdef WINDOWSNT
 	    /* Don't go below server level in UNC filenames.  */
 	    if (o == target + 1 && IS_DIRECTORY_SEP (*o)
 		&& IS_DIRECTORY_SEP (*target))
 	      o = prev_o;
+	    else
+# endif
+	    /* Keep initial / only if this is the whole name.  */
+	    if (o == target && IS_ANY_SEP (*o) && p[3] == 0)
+	      ++o;
 #endif
 	    p += 3;
 	  }
-- 
2.17.1


  reply	other threads:[~2020-08-29  5:52 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-13 16:15 bug#26911: 25.2; eshell "cd .." doesn't work correctly with TRAMP Yegor Timoshenko
2017-05-13 18:25 ` Michael Albinus
2017-05-13 18:30   ` Yegor Timoshenko
2017-05-15 15:53     ` Michael Albinus
2020-08-26 20:39 ` Paul Eggert
2020-08-27 11:46   ` Michael Albinus
2020-08-27 18:31 ` Mattias Engdegård
2020-08-27 18:38   ` Eli Zaretskii
2020-08-27 18:54     ` Stephen Berman
2020-08-27 21:53   ` Paul Eggert
2020-08-28  6:39     ` Eli Zaretskii
2020-08-28  7:01       ` Eli Zaretskii
2020-08-28 10:48         ` Eli Zaretskii
2020-08-29  5:52           ` Paul Eggert [this message]
2020-08-29  6:31             ` Eli Zaretskii
2020-08-29 16:46               ` Paul Eggert
2020-08-29 16:59                 ` Michael Albinus
2020-08-29 18:29                   ` Eli Zaretskii
2020-08-29 19:12                     ` Michael Albinus
2020-08-29 19:31                       ` Eli Zaretskii
2020-08-30  9:46                         ` Michael Albinus
2020-08-30 14:14                           ` Eli Zaretskii
2020-08-29 18:26                 ` Eli Zaretskii
2020-08-29 20:42                   ` Paul Eggert
2020-08-30 14:09                     ` Eli Zaretskii
2020-08-30 21:39                       ` Paul Eggert
2020-08-31 14:58                         ` Eli Zaretskii
2020-08-31 18:15                           ` Paul Eggert
2020-08-31 18:56                             ` Eli Zaretskii
2020-08-31 23:36                               ` Paul Eggert
2020-09-01  2:33                                 ` Eli Zaretskii
2020-09-03 17:27                           ` Eli Zaretskii
2020-09-03 17:42                             ` Michael Albinus
2020-09-04 11:55                             ` Michael Albinus
2020-09-04 12:25                               ` Eli Zaretskii
2020-09-04 13:53                                 ` Michael Albinus
2020-09-04 14:40                                   ` Eli Zaretskii
2020-09-04 15:20                                     ` Eli Zaretskii
2020-09-04 15:59                                       ` Michael Albinus
2020-09-04 17:42                                         ` Eli Zaretskii
2020-09-05  8:34                                           ` Michael Albinus
2020-09-05 11:18                                             ` Eli Zaretskii
2020-09-05 11:32                                               ` Eli Zaretskii
2020-09-05 15:57                                               ` Michael Albinus
2020-09-05 16:33                                                 ` Eli Zaretskii
2020-09-05 17:08                                                   ` Eli Zaretskii
2020-09-05 17:36                                                   ` Michael Albinus
2020-09-05 17:56                                                     ` Eli Zaretskii
2020-09-04 16:09                                     ` Michael Albinus

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=47047d69-91aa-fd0d-1510-64ba7c246970@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=26911@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=mattiase@acm.org \
    --cc=michael.albinus@gmx.de \
    --cc=yegortimoshenko@gmail.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 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.