[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 2f2afa0 2/2: Ensure 'call-process' interprets INFILE as a local p
From: |
Lars Ingebrigtsen |
Subject: |
master 2f2afa0 2/2: Ensure 'call-process' interprets INFILE as a local path |
Date: |
Sun, 4 Jul 2021 09:32:16 -0400 (EDT) |
branch: master
commit 2f2afa0b310bbce43a8703f5467b2638082abdd9
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
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' (bug#49283).
---
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 aabc393..675b78d 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -116,11 +116,13 @@ static CHILD_SETUP_TYPE child_setup (int, int, int, char
**, char **,
const char *);
/* 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 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION
DISPLAY &rest ARGS) *
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 c354f3a..b8c3e4e 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1755,7 +1755,7 @@ usage: (make-process &rest ARGS) */)
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 0890f25..4a25d13 100644
--- a/src/process.h
+++ b/src/process.h
@@ -264,7 +264,7 @@ enum
/* 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 51d8b5e..b8ec22d 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;