changeset 28341:0390c4848b27 v8.2.4696

patch 8.2.4696: delete() with "rf" argument does not report a failure Commit: https://github.com/vim/vim/commit/478700336d1c72e133b8ff6841e968c1bb1658ed Author: zeertzjq <zeertzjq@outlook.com> Date: Tue Apr 5 15:31:01 2022 +0100 patch 8.2.4696: delete() with "rf" argument does not report a failure Problem: delete() with "rf" argument does not report a failure. Solution: Return -1 if the directory could not be removed. (closes https://github.com/vim/vim/issues/10078)
author Bram Moolenaar <Bram@vim.org>
date Tue, 05 Apr 2022 16:45:03 +0200
parents e2084b13a5c3
children 3f09c6b2c21c
files src/fileio.c src/testdir/test_functions.vim src/version.c
diffstat 3 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5017,13 +5017,16 @@ delete_recursive(char_u *name)
 		vim_snprintf((char *)NameBuff, MAXPATHL, "%s/%s", exp,
 					    ((char_u **)ga.ga_data)[i]);
 		if (delete_recursive(NameBuff) != 0)
+		    // Remember the failure but continue deleting any further
+		    // entries.
 		    result = -1;
 	    }
 	    ga_clear_strings(&ga);
+	    if (mch_rmdir(exp) != 0)
+		result = -1;
 	}
 	else
 	    result = -1;
-	(void)mch_rmdir(exp);
 	vim_free(exp);
     }
     else
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -2242,6 +2242,15 @@ func Test_delete_rf()
   call assert_equal(0, delete('Xdir', 'rf'))
   call assert_false(filereadable('Xdir/foo.txt'))
   call assert_false(filereadable('Xdir/[a-1]/foo.txt'))
+
+  if has('unix')
+    call mkdir('Xdir/Xdir2', 'p')
+    silent !chmod 555 Xdir
+    call assert_equal(-1, delete('Xdir/Xdir2', 'rf'))
+    call assert_equal(-1, delete('Xdir', 'rf'))
+    silent !chmod 755 Xdir
+    call assert_equal(0, delete('Xdir', 'rf'))
+  endif
 endfunc
 
 func Test_call()
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4696,
+/**/
     4695,
 /**/
     4694,