patch 7.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.
diff --git a/src/fileio.c b/src/fileio.c
index 75a3876..6dbdea2 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -7280,6 +7280,46 @@
curbuf->b_no_eol_lnum += offset;
}
+#if defined(TEMPDIRNAMES) || defined(FEAT_EVAL) || defined(PROTO)
+/*
+ * Delete "name" and everything in it, recursively.
+ * return 0 for succes, -1 if some file was not deleted.
+ */
+ int
+delete_recursive(char_u *name)
+{
+ int result = 0;
+ char_u **files;
+ int file_count;
+ int i;
+ char_u *exp;
+
+ if (mch_isdir(name))
+ {
+ 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)
+ if (delete_recursive(files[i]) != 0)
+ result = -1;
+ FreeWild(file_count, files);
+ }
+ 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. */
@@ -7289,30 +7329,16 @@
void
vim_deltempdir()
{
- char_u **files;
- int file_count;
- int i;
-
if (vim_tempdir != NULL)
{
- sprintf((char *)NameBuff, "%s*", vim_tempdir);
- if (gen_expand_wildcards(1, &NameBuff, &file_count, &files,
- EW_DIR|EW_FILE|EW_SILENT) == OK)
- {
- for (i = 0; i < file_count; ++i)
- mch_remove(files[i]);
- FreeWild(file_count, files);
- }
- gettail(NameBuff)[-1] = NUL;
- (void)mch_rmdir(NameBuff);
-
+ /* 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.