0
0
mirror of https://github.com/vim/vim.git synced 2025-10-14 07:04:10 -04:00

patch 8.0.1708: mkdir with 'p' flag fails on existing directory

Problem:    Mkdir with 'p' flag fails on existing directory, which is
            different from the mkdir shell command.
Solution:   Don't fail if the directory already exists. (James McCoy,
            closes #2775)
This commit is contained in:
Bram Moolenaar
2018-04-14 13:51:55 +02:00
parent 98da6ecab9
commit 78a16b0f2a
4 changed files with 43 additions and 12 deletions

View File

@@ -8057,22 +8057,32 @@ f_mkdir(typval_T *argvars, typval_T *rettv)
dir = get_tv_string_buf(&argvars[0], buf);
if (*dir == NUL)
rettv->vval.v_number = FAIL;
else
{
if (*gettail(dir) == NUL)
/* remove trailing slashes */
*gettail_sep(dir) = NUL;
return;
if (argvars[1].v_type != VAR_UNKNOWN)
if (*gettail(dir) == NUL)
/* remove trailing slashes */
*gettail_sep(dir) = NUL;
if (argvars[1].v_type != VAR_UNKNOWN)
{
if (argvars[2].v_type != VAR_UNKNOWN)
{
if (argvars[2].v_type != VAR_UNKNOWN)
prot = (int)get_tv_number_chk(&argvars[2], NULL);
if (prot != -1 && STRCMP(get_tv_string(&argvars[1]), "p") == 0)
mkdir_recurse(dir, prot);
prot = (int)get_tv_number_chk(&argvars[2], NULL);
if (prot == -1)
return;
}
if (STRCMP(get_tv_string(&argvars[1]), "p") == 0)
{
if (mch_isdir(dir))
{
/* With the "p" flag it's OK if the dir already exists. */
rettv->vval.v_number = OK;
return;
}
mkdir_recurse(dir, prot);
}
rettv->vval.v_number = prot == -1 ? FAIL : vim_mkdir_emsg(dir, prot);
}
rettv->vval.v_number = vim_mkdir_emsg(dir, prot);
}
#endif