Bug: Erroneous "Cannot create directory" in "mkdir('foo/bar/', 'p')"

173 views
Skip to first unread message

David Barnett

unread,
Aug 20, 2013, 9:13:05 PM8/20/13
to vim...@googlegroups.com
Ensure ./foo doesn't exist, and do
:call mkdir('foo/bar/', 'p')

Vim gives you an error:
E739: Cannot create directory: foo/bar/
but the directory was created just fine.

Dropping the trailing slash works without error:
:call mkdir('foo/bar', 'p')

David

David Barnett

unread,
Aug 20, 2013, 9:16:52 PM8/20/13
to vim...@googlegroups.com
Oh, and this happens even with
:call mkdir('foo/', 'p')

Seems like all that matters is the trailing slash and the 'p' flag, nothing special about the path.

David

LCD 47

unread,
Aug 21, 2013, 6:56:31 AM8/21/13
to vim...@googlegroups.com, Bram Moolenaar
Please try the patch below. It kills the trailing slash, which
seems pretty awkward for a fix.

/lcd


diff -r ae6c19fb32e1 src/eval.c
--- a/src/eval.c Wed Aug 14 17:45:29 2013 +0200
+++ b/src/eval.c Wed Aug 21 13:49:19 2013 +0300
@@ -14284,6 +14284,7 @@
typval_T *rettv;
{
char_u *dir;
+ char_u *p;
char_u buf[NUMBUFLEN];
int prot = 0755;

@@ -14292,6 +14293,13 @@
return;

dir = get_tv_string_buf(&argvars[0], buf);
+ p = gettail(dir);
+ if (!*p)
+ {
+ p = gettail_sep(dir);
+ *p = 0;
+ }
+
if (argvars[1].v_type != VAR_UNKNOWN)
{
if (argvars[2].v_type != VAR_UNKNOWN)
@@ -14299,7 +14307,7 @@
if (prot != -1 && STRCMP(get_tv_string(&argvars[1]), "p") == 0)
mkdir_recurse(dir, prot);
}
- rettv->vval.v_number = prot != -1 ? vim_mkdir_emsg(dir, prot) : 0;
+ rettv->vval.v_number = prot != -1 ? vim_mkdir_emsg(dir, prot) : FAIL;
}
#endif

Marius Gedminas

unread,
Aug 21, 2013, 11:24:26 AM8/21/13
to vim...@googlegroups.com, Bram Moolenaar
On Wed, Aug 21, 2013 at 01:56:31PM +0300, LCD 47 wrote:
> On 20 August 2013, David Barnett <davie...@gmail.com> wrote:
> > Ensure ./foo doesn't exist, and do
> > :call mkdir('foo/bar/', 'p')
> >
> > Vim gives you an error:
> > E739: Cannot create directory: foo/bar/
> > but the directory was created just fine.
> >
> > Dropping the trailing slash works without error:
> > :call mkdir('foo/bar', 'p')
>
> Please try the patch below. It kills the trailing slash, which
> seems pretty awkward for a fix.


> diff -r ae6c19fb32e1 src/eval.c
> --- a/src/eval.c Wed Aug 14 17:45:29 2013 +0200
> +++ b/src/eval.c Wed Aug 21 13:49:19 2013 +0300
> @@ -14284,6 +14284,7 @@
> typval_T *rettv;
> {
> char_u *dir;
> + char_u *p;
> char_u buf[NUMBUFLEN];
> int prot = 0755;
>
> @@ -14292,6 +14293,13 @@
> return;
>
> dir = get_tv_string_buf(&argvars[0], buf);
> + p = gettail(dir);
> + if (!*p)
> + {
> + p = gettail_sep(dir);
> + *p = 0;
> + }
> +

What about :call mkdir('foo/bar//', 'p')?

> if (argvars[1].v_type != VAR_UNKNOWN)
> {
> if (argvars[2].v_type != VAR_UNKNOWN)
> @@ -14299,7 +14307,7 @@
> if (prot != -1 && STRCMP(get_tv_string(&argvars[1]), "p") == 0)
> mkdir_recurse(dir, prot);
> }
> - rettv->vval.v_number = prot != -1 ? vim_mkdir_emsg(dir, prot) : 0;
> + rettv->vval.v_number = prot != -1 ? vim_mkdir_emsg(dir, prot) : FAIL;
> }
> #endif

Marius Gedminas
--
Hacking graphics in X is like finding sqrt(pi) with roman numerals.
-- man xdaliclock
signature.asc

LCD 47

unread,
Aug 21, 2013, 11:41:37 AM8/21/13
to vim...@googlegroups.com
[...]

It should work just as well. Have you actually tried the patch?

/lcd

Marius Gedminas

unread,
Aug 22, 2013, 1:29:31 AM8/22/13
to vim...@googlegroups.com
No, I just wondered if you thought about that case.

Marius Gedminas
--
Never assume the reader has read the subject line.
signature.asc

David Barnett

unread,
Aug 22, 2013, 1:32:54 AM8/22/13
to vim...@googlegroups.com
Yep, your patch fixes the symptom, both for 'foo/' and 'foo//'. Better your workaround in vim than my workaround in vimscript!

(BTW, the indentation in the patch looked a little screwy.)

David



--
--
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 a topic in the Google Groups "vim_dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_dev/rFT67RzKMfU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

LCD 47

unread,
Aug 22, 2013, 4:20:54 AM8/22/13
to vim...@googlegroups.com
On 21 August 2013, David Barnett <davie...@gmail.com> wrote:
> Yep, your patch fixes the symptom, both for 'foo/' and 'foo//'. Better
> your workaround in vim than my workaround in vimscript!
>
> (BTW, the indentation in the patch looked a little screwy.)

The code uses tabs. Perhaps you should check the indentation of the
final code, rather than the patch? :)

/lcd

Bram Moolenaar

unread,
Aug 22, 2013, 6:07:30 AM8/22/13
to LCD 47, vim...@googlegroups.com

lcd wrote:

> On 20 August 2013, David Barnett <davie...@gmail.com> wrote:
> > Ensure ./foo doesn't exist, and do
> > :call mkdir('foo/bar/', 'p')
> >
> > Vim gives you an error:
> > E739: Cannot create directory: foo/bar/
> > but the directory was created just fine.
> >
> > Dropping the trailing slash works without error:
> > :call mkdir('foo/bar', 'p')
>
> Please try the patch below. It kills the trailing slash, which
> seems pretty awkward for a fix.

Thanks. With the "p" argument it can be done without modifying the
string, but without it we do have to remove the slash.

--
hundred-and-one symptoms of being an internet addict:
96. On Super Bowl Sunday, you followed the score by going to the
Yahoo main page instead of turning on the TV.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages