Currently, the "term_start()" function will give an error when
a non-existent directory is passed to its "cwd" option.  The call will not
fail, however, when the directory exists but is not accessible by the
current user.  It would be nice to be able to recover from this error.

This patch uses "mch_access()" to check for both the existence and the 
accessibility of the directory.

A test, which currently fails, is included in the patch. This seems to
work on Ubuntu 18.04, but I haven't tested the change on other systems.

Thanks,
Jason Franklin

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
>From a3df55acca74264672635736c431004ce20d2795 Mon Sep 17 00:00:00 2001
From: Jason Franklin <[email protected]>
Date: Mon, 15 Oct 2018 14:37:04 -0400
Subject: [PATCH 1/2] Write a failing test

---
 src/testdir/test_terminal.vim | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index b82dae13e..be65c982f 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -478,6 +478,25 @@ func Test_terminal_cwd()
   call delete('Xdir', 'rf')
 endfunc
 
+func Test_terminal_cwd_failure()
+
+  " Case 1: Directory does not exist.
+  call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:')
+
+  call mkdir('Xdir', '', '0600')
+
+  " Return early if the directory permissions were not set properly.
+  if getfperm('Xdir')[2] == 'x'
+    call delete('Xdir', 'rf')
+    return
+  endif
+
+  " Case 2: Directory is not accessible.
+  call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:')
+
+  call delete('Xdir', 'rf')
+endfunc
+
 func Test_terminal_servername()
   if !has('clientserver')
     return
-- 
2.17.1


>From 5dc4b18f719f8802678822f36b9deb1ef44df7c5 Mon Sep 17 00:00:00 2001
From: Jason Franklin <[email protected]>
Date: Mon, 15 Oct 2018 14:37:49 -0400
Subject: [PATCH 2/2] Check for "x" bit on term_start() "cwd" value

---
 src/channel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/channel.c b/src/channel.c
index aa0a0d38c..7a538637f 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -4916,7 +4916,7 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
 		if (!(supported2 & JO2_CWD))
 		    break;
 		opt->jo_cwd = get_tv_string_buf_chk(item, opt->jo_cwd_buf);
-		if (opt->jo_cwd == NULL || !mch_isdir(opt->jo_cwd))
+		if (opt->jo_cwd == NULL || mch_access((char *)opt->jo_cwd, X_OK) != 0)
 		{
 		    EMSG2(_(e_invargval), "cwd");
 		    return FAIL;
-- 
2.17.1

Raspunde prin e-mail lui