diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-01-16 21:27:23 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-01-16 21:27:23 +0100 |
commit | da440d21a6b94d7f525fa7be9b1417c78dd9aa4c (patch) | |
tree | 646615551e8f62b82cfca1a1ef70fb2e3341d8b0 /src/fileio.c | |
parent | 286eacd3f6631e985089176fb1dff1bcf1a1d6b5 (diff) | |
download | vim-git-da440d21a6b94d7f525fa7be9b1417c78dd9aa4c.tar.gz |
patch 7.4.1107v7.4.1107
Problem: Vim can create a directory but not delete it.
Solution: Add an argument to delete() to make it possible to delete a
directory, also recursively.
Diffstat (limited to 'src/fileio.c')
-rw-r--r-- | src/fileio.c | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/src/fileio.c b/src/fileio.c index 75a38764c..6dbdea21e 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -7280,39 +7280,65 @@ write_lnum_adjust(offset) curbuf->b_no_eol_lnum += offset; } -#if defined(TEMPDIRNAMES) || defined(PROTO) -static long temp_count = 0; /* Temp filename counter. */ - +#if defined(TEMPDIRNAMES) || defined(FEAT_EVAL) || defined(PROTO) /* - * Delete the temp directory and all files it contains. + * Delete "name" and everything in it, recursively. + * return 0 for succes, -1 if some file was not deleted. */ - void -vim_deltempdir() + int +delete_recursive(char_u *name) { + int result = 0; char_u **files; int file_count; int i; + char_u *exp; - if (vim_tempdir != NULL) + if (mch_isdir(name)) { - sprintf((char *)NameBuff, "%s*", vim_tempdir); - if (gen_expand_wildcards(1, &NameBuff, &file_count, &files, + vim_snprintf((char *)NameBuff, MAXPATHL, "%s/*", name); + exp = vim_strsave(NameBuff); + if (exp == NULL) + return -1; + if (gen_expand_wildcards(1, &exp, &file_count, &files, EW_DIR|EW_FILE|EW_SILENT) == OK) { for (i = 0; i < file_count; ++i) - mch_remove(files[i]); + if (delete_recursive(files[i]) != 0) + result = -1; FreeWild(file_count, files); } - gettail(NameBuff)[-1] = NUL; - (void)mch_rmdir(NameBuff); + else + result = -1; + vim_free(exp); + (void)mch_rmdir(name); + } + else + result = mch_remove(name) == 0 ? 0 : -1; + return result; +} +#endif + +#if defined(TEMPDIRNAMES) || defined(PROTO) +static long temp_count = 0; /* Temp filename counter. */ + +/* + * Delete the temp directory and all files it contains. + */ + void +vim_deltempdir() +{ + if (vim_tempdir != NULL) + { + /* remove the trailing path separator */ + gettail(vim_tempdir)[-1] = NUL; + delete_recursive(vim_tempdir); vim_free(vim_tempdir); vim_tempdir = NULL; } } -#endif -#ifdef TEMPDIRNAMES /* * Directory "tempdir" was created. Expand this name to a full path and put * it in "vim_tempdir". This avoids that using ":cd" would confuse us. |