vim-patch:8.2.4696: delete() with "rf" argument does not report a failure (#18002)

Problem:    delete() with "rf" argument does not report a failure.
Solution:   Return -1 if the directory could not be removed. (closes vim/vim#10078)
478700336d
This commit is contained in:
zeertzjq 2022-04-06 05:12:49 +08:00 committed by GitHub
parent f86f74c12f
commit 128bedc0d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -5408,15 +5408,18 @@ int delete_recursive(const char *name)
for (int i = 0; i < ga.ga_len; i++) {
vim_snprintf((char *)NameBuff, MAXPATHL, "%s/%s", exp, ((char_u **)ga.ga_data)[i]);
if (delete_recursive((const char *)NameBuff) != 0) {
// Remember the failure but continue deleting any further
// entries.
result = -1;
}
}
ga_clear_strings(&ga);
if (os_rmdir(exp) != 0) {
result = -1;
}
} else {
result = -1;
}
// Note: "name" value may be changed in delete_recursive(). Must use the saved value.
result = os_rmdir(exp) == 0 ? 0 : -1;
xfree(exp);
} else {
// Delete symlink only.

View File

@ -1662,6 +1662,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()