logo

utils-std

Collection of commonly available Unix tools
commit: 0f783204c9b25363b3a39b0528de6423c9dd1256
parent 8ceab6d229305c00c7c2564eeeb5368b674b7964
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 28 Mar 2024 17:53:14 +0100

cmd/rm: Pass correct argv to do_unlinkat accumulated path

Diffstat:

Mcmd/rm.c2+-
Mtest-cmd/rm.t25+++++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/cmd/rm.c b/cmd/rm.c @@ -249,7 +249,7 @@ main(int argc, char *argv[]) for(int i = 0; i < argc; i++) { - int ret = do_unlinkat(AT_FDCWD, argv[i], argv[0]); + int ret = do_unlinkat(AT_FDCWD, argv[i], argv[i]); if(ret != 0) err = 1; } diff --git a/test-cmd/rm.t b/test-cmd/rm.t @@ -135,3 +135,28 @@ Don't follow symlinks $ rm foo $ test -e bar $ test ! -e foo + +Correct path when multiple files are given + $ touch path_v_foo path_v_bar + $ rm -v path_v_foo path_v_enoent path_v_bar + rm: Removed: path_v_foo + rm: Failed getting status for 'path_v_enoent': No such file or directory + rm: Removed: path_v_bar + [1] + $ test ! -e path_v_foo + $ test ! -e path_v_bar + $ mkdir -p dir_v_foo/ dir_v_bar/ dir_v_dir/foo.d + $ touch dir_v_foo/bar dir_v_foo/baz dir_v_bar/foo + $ rm -rv dir_v_foo dir_v_foo/baz dir_v_bar/foo dir_v_bar dir_v_dir/foo.d dir_v_dir + rm: Removed: dir_v_foo/ba[zr] (re) + rm: Removed: dir_v_foo/ba[zr] (re) + rm: Removed: dir_v_foo + rm: Failed getting status for 'dir_v_foo/baz': No such file or directory + rm: Removed: dir_v_bar/foo + rm: Removed: dir_v_bar + rm: Removed: dir_v_dir/foo.d + rm: Removed: dir_v_dir + [1] + $ test ! -e dir_v_foo + $ test ! -e dir_v_bar + $ test ! -e dir_v_dir