unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 49283@debbugs.gnu.org, Lars Ingebrigtsen <larsi@gnus.org>,
	Michael Albinus <michael.albinus@gmx.de>
Subject: bug#49283: [PATCH] 27.2; `(call-process "program" null-device ...)' fails over TRAMP from local MS Windows
Date: Fri, 2 Jul 2021 11:47:12 -0700	[thread overview]
Message-ID: <CANh=_JG_t+DfNsQM1XNNL-ehLmTZp6Ysu56tDwbTm_nL4fx73Q@mail.gmail.com> (raw)
In-Reply-To: <83k0m9jk5e.fsf@gnu.org>

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

On Thu, Jul 1, 2021 at 11:37 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Jim Porter <jporterbugs@gmail.com>
> > Date: Thu, 1 Jul 2021 12:45:42 -0700
> > Cc: Michael Albinus <michael.albinus@gmx.de>, Lars Ingebrigtsen <larsi@gnus.org>, 49283@debbugs.gnu.org
> >
> > I'd considered that when writing my initial patch to `call-process',
> > but I wasn't sure what the most-correct way to avoid that would be. It
> > seems we want an encoded path before returning from
> > `encode_current_directory' in order to check that our result is
> > actually accessible. But then that encoded dir gets passed in to
> > `expand-file-name'. If INFILE is an un-encoded absolute path, wouldn't
> > `expand-file-name' be un-encoded as well?
>
> expand-file-name is not a problem, it can deal with encoded file
> names.  The problem is the calls to remove_slash_colon and
> report_file_error: they should receive file names in their internal
> representation.

Right, I was just worried that if I relied on
`encode_current_directory' returning an encoded path,
`expand-file-name' might sometimes return an encoded path (e.g. if
INFILE is a simple relative path like "foo") and sometimes an
unencoded path (e.g. if INFILE is an absolute path). I might be wrong
though, since I didn't look closely at the implementation...

> How about adding a 'bool' argument to encode_current_directory, so
> that the caller could control whether or not it encodes the directory
> file name?  Then you could in this case tell encode_current_directory
> not to encode the directory file name.

Ok, I did that (and renamed it to `get_current_directory' since it
doesn't always encode anymore). How does the attached patch look?

[-- Attachment #2: 0001-Ensure-call-process-interprets-infile-as-a-local-pat.patch --]
[-- Type: application/octet-stream, Size: 5127 bytes --]

From ab6e47952944e94063a4db6442ee3549dc46bfb7 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Fri, 2 Jul 2021 11:41:41 -0700
Subject: [PATCH] Ensure 'call-process' interprets INFILE as a local path

* src/callproc.c (get_current_directory): Rename from
'encode_current_directory' and add boolean ENCODE flag.
(Fcall_process): Interpret INFILE relative to the working directory
from which PROGRAM is run, not 'default-directory'.
(call_process): Use 'get_current_directory'.
* src/process.c (Fmake_process): Use 'get_current_directory'.
* src/process.h (get_current_directory): Rename decl from
'encode_current_directory'.
* src/sysdep.c (sys_subshell): Use 'get_current_directory'.
---
 src/callproc.c | 25 +++++++++++++++----------
 src/process.c  |  2 +-
 src/process.h  |  2 +-
 src/sysdep.c   |  2 +-
 4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/src/callproc.c b/src/callproc.c
index aabc39313b..675b78daf3 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -116,11 +116,13 @@ #define _P_NOWAIT 1	/* from process.h */
 				     const char *);
 \f
 /* Return the current buffer's working directory, or the home
-   directory if it's unreachable, as a string suitable for a system call.
-   Signal an error if the result would not be an accessible directory.  */
+   directory if it's unreachable.  If ENCODE is true, return as a string
+   suitable for a system call; otherwise, return a string in its
+   internal representation.  Signal an error if the result would not be
+   an accessible directory.  */
 
 Lisp_Object
-encode_current_directory (void)
+get_current_directory (bool encode)
 {
   Lisp_Object curdir = BVAR (current_buffer, directory);
   Lisp_Object dir = Funhandled_file_name_directory (curdir);
@@ -131,12 +133,12 @@ encode_current_directory (void)
     dir = build_string ("~");
 
   dir = expand_and_dir_to_file (dir);
-  dir = ENCODE_FILE (remove_slash_colon (dir));
+  Lisp_Object encoded_dir = ENCODE_FILE (remove_slash_colon (dir));
 
-  if (! file_accessible_directory_p (dir))
+  if (! file_accessible_directory_p (encoded_dir))
     report_file_error ("Setting current directory", curdir);
 
-  return dir;
+  return encode ? encoded_dir : dir;
 }
 
 /* If P is reapable, record it as a deleted process and kill it.
@@ -225,8 +227,9 @@ DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0,
 The remaining arguments are optional.
 
 The program's input comes from file INFILE (nil means `null-device').
-If you want to make the input come from an Emacs buffer, use
-`call-process-region' instead.
+If INFILE is a relative path, it will be looked for relative to the
+directory where the process is run (see below).  If you want to make the
+input come from an Emacs buffer, use `call-process-region' instead.
 
 Third argument DESTINATION specifies how to handle program's output.
 If DESTINATION is a buffer, or t that stands for the current buffer,
@@ -270,7 +273,9 @@ DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0,
 
   if (nargs >= 2 && ! NILP (args[1]))
     {
-      infile = Fexpand_file_name (args[1], BVAR (current_buffer, directory));
+      /* Expand infile relative to the current buffer's current
+	 directory, or its unhandled equivalent ("~").  */
+      infile = Fexpand_file_name (args[1], get_current_directory (false));
       CHECK_STRING (infile);
     }
   else
@@ -439,7 +444,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
      buffer's current directory, or its unhandled equivalent.  We
      can't just have the child check for an error when it does the
      chdir, since it's in a vfork.  */
-  current_dir = encode_current_directory ();
+  current_dir = get_current_directory (true);
 
   if (STRINGP (error_file))
     {
diff --git a/src/process.c b/src/process.c
index c354f3a90d..b8c3e4ecfb 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1755,7 +1755,7 @@ DEFUN ("make-process", Fmake_process, Smake_process, 0, MANY, 0,
      buffer's current directory, or its unhandled equivalent.  We
      can't just have the child check for an error when it does the
      chdir, since it's in a vfork.  */
-  current_dir = encode_current_directory ();
+  current_dir = get_current_directory (true);
 
   name = Fplist_get (contact, QCname);
   CHECK_STRING (name);
diff --git a/src/process.h b/src/process.h
index 0890f253a4..4a25d13d26 100644
--- a/src/process.h
+++ b/src/process.h
@@ -264,7 +264,7 @@ pset_gnutls_cred_type (struct Lisp_Process *p, Lisp_Object val)
 
 /* Defined in callproc.c.  */
 
-extern Lisp_Object encode_current_directory (void);
+extern Lisp_Object get_current_directory (bool);
 extern void record_kill_process (struct Lisp_Process *, Lisp_Object);
 
 /* Defined in sysdep.c.  */
diff --git a/src/sysdep.c b/src/sysdep.c
index 51d8b5eeed..b8ec22d9dd 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -657,7 +657,7 @@ sys_subshell (void)
 #endif
   pid_t pid;
   struct save_signal saved_handlers[5];
-  char *str = SSDATA (encode_current_directory ());
+  char *str = SSDATA (get_current_directory (true));
 
 #ifdef DOS_NT
   pid = 0;
-- 
2.25.1


  reply	other threads:[~2021-07-02 18:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-30  5:14 bug#49283: [PATCH] 27.2; `(call-process "program" null-device ...)' fails over TRAMP from local MS Windows Jim Porter
2021-06-30  7:24 ` Michael Albinus
2021-06-30 17:16   ` Jim Porter
2021-07-01 11:07     ` Lars Ingebrigtsen
2021-07-01 12:26       ` Michael Albinus
2021-07-01 12:34         ` Lars Ingebrigtsen
2021-07-01 13:12         ` Eli Zaretskii
2021-07-01 19:45           ` Jim Porter
2021-07-02  6:37             ` Eli Zaretskii
2021-07-02 18:47               ` Jim Porter [this message]
2021-07-03  7:02                 ` Eli Zaretskii
2021-07-04 13:32                 ` 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='CANh=_JG_t+DfNsQM1XNNL-ehLmTZp6Ysu56tDwbTm_nL4fx73Q@mail.gmail.com' \
    --to=jporterbugs@gmail.com \
    --cc=49283@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.org \
    --cc=michael.albinus@gmx.de \
    /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).