comparison src/fileio.c @ 7615:228ff048db20 v7.4.1107

commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 16 21:27:23 2016 +0100 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.
author Christian Brabandt <cb@256bit.org>
date Sat, 16 Jan 2016 21:30:05 +0100
parents 08e62c4fc17d
children befbed72da87
comparison
equal deleted inserted replaced
7614:427b35579737 7615:228ff048db20
7278 { 7278 {
7279 if (curbuf->b_no_eol_lnum != 0) /* only if there is a missing eol */ 7279 if (curbuf->b_no_eol_lnum != 0) /* only if there is a missing eol */
7280 curbuf->b_no_eol_lnum += offset; 7280 curbuf->b_no_eol_lnum += offset;
7281 } 7281 }
7282 7282
7283 #if defined(TEMPDIRNAMES) || defined(FEAT_EVAL) || defined(PROTO)
7284 /*
7285 * Delete "name" and everything in it, recursively.
7286 * return 0 for succes, -1 if some file was not deleted.
7287 */
7288 int
7289 delete_recursive(char_u *name)
7290 {
7291 int result = 0;
7292 char_u **files;
7293 int file_count;
7294 int i;
7295 char_u *exp;
7296
7297 if (mch_isdir(name))
7298 {
7299 vim_snprintf((char *)NameBuff, MAXPATHL, "%s/*", name);
7300 exp = vim_strsave(NameBuff);
7301 if (exp == NULL)
7302 return -1;
7303 if (gen_expand_wildcards(1, &exp, &file_count, &files,
7304 EW_DIR|EW_FILE|EW_SILENT) == OK)
7305 {
7306 for (i = 0; i < file_count; ++i)
7307 if (delete_recursive(files[i]) != 0)
7308 result = -1;
7309 FreeWild(file_count, files);
7310 }
7311 else
7312 result = -1;
7313 vim_free(exp);
7314 (void)mch_rmdir(name);
7315 }
7316 else
7317 result = mch_remove(name) == 0 ? 0 : -1;
7318
7319 return result;
7320 }
7321 #endif
7322
7283 #if defined(TEMPDIRNAMES) || defined(PROTO) 7323 #if defined(TEMPDIRNAMES) || defined(PROTO)
7284 static long temp_count = 0; /* Temp filename counter. */ 7324 static long temp_count = 0; /* Temp filename counter. */
7285 7325
7286 /* 7326 /*
7287 * Delete the temp directory and all files it contains. 7327 * Delete the temp directory and all files it contains.
7288 */ 7328 */
7289 void 7329 void
7290 vim_deltempdir() 7330 vim_deltempdir()
7291 { 7331 {
7292 char_u **files;
7293 int file_count;
7294 int i;
7295
7296 if (vim_tempdir != NULL) 7332 if (vim_tempdir != NULL)
7297 { 7333 {
7298 sprintf((char *)NameBuff, "%s*", vim_tempdir); 7334 /* remove the trailing path separator */
7299 if (gen_expand_wildcards(1, &NameBuff, &file_count, &files, 7335 gettail(vim_tempdir)[-1] = NUL;
7300 EW_DIR|EW_FILE|EW_SILENT) == OK) 7336 delete_recursive(vim_tempdir);
7301 {
7302 for (i = 0; i < file_count; ++i)
7303 mch_remove(files[i]);
7304 FreeWild(file_count, files);
7305 }
7306 gettail(NameBuff)[-1] = NUL;
7307 (void)mch_rmdir(NameBuff);
7308
7309 vim_free(vim_tempdir); 7337 vim_free(vim_tempdir);
7310 vim_tempdir = NULL; 7338 vim_tempdir = NULL;
7311 } 7339 }
7312 } 7340 }
7313 #endif 7341
7314
7315 #ifdef TEMPDIRNAMES
7316 /* 7342 /*
7317 * Directory "tempdir" was created. Expand this name to a full path and put 7343 * Directory "tempdir" was created. Expand this name to a full path and put
7318 * it in "vim_tempdir". This avoids that using ":cd" would confuse us. 7344 * it in "vim_tempdir". This avoids that using ":cd" would confuse us.
7319 * "tempdir" must be no longer than MAXPATHL. 7345 * "tempdir" must be no longer than MAXPATHL.
7320 */ 7346 */