nshlib/nsh_fscmds.c:Add whether or not to pass in empty arguments when rm -r

When rm -r is passed with no address specified, it will automatically recursively unlink all files under the root path ('/') until unlinking to the mounted folder causes the unlink to fail. In this change, rm -r without a specified path will prompt for missing arguments
This commit is contained in:
chenrun1 2023-03-23 16:16:10 +08:00 committed by Xiang Xiao
parent 3a28933ca8
commit cf54069487

View File

@ -1911,13 +1911,19 @@ static int unlink_recursive(FAR char *path)
int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
{
UNUSED(argc);
bool recursive = (strcmp(argv[1], "-r") == 0);
FAR char *fullpath = nsh_getfullpath(vtbl, recursive ? argv[2] : argv[1]);
FAR char *fullpath;
char buf[PATH_MAX];
int ret = ERROR;
if (recursive && argc == 2)
{
nsh_error(vtbl, g_fmtargrequired, argv[0]);
return ret;
}
fullpath = nsh_getfullpath(vtbl, recursive ? argv[2] : argv[1]);
if (fullpath != NULL)
{
if (recursive)