add support for '-f' option to shell rm built-in command

This commit is contained in:
Axel Kohlmeyer
2022-03-17 15:17:44 -04:00
parent 8ffacb55ca
commit 57cf2a735a
2 changed files with 12 additions and 4 deletions

View File

@ -21,7 +21,8 @@ Syntax
*mv* args = old new
old = old filename
new = new filename or destination folder
*rm* args = file1 file2 ...
*rm* args = [-f] file1 file2 ...
-f = turn off warnings (optional)
file1,file2 = one or more filenames to delete
*rmdir* args = dir1 dir2 ...
dir1,dir2 = one or more directories to delete

View File

@ -1218,10 +1218,17 @@ void Input::shell()
} else if (strcmp(arg[0],"rm") == 0) {
if (narg < 2) error->all(FLERR,"Illegal shell rm command");
if (me == 0) {
for (int i = 1; i < narg; i++) {
int i = 1;
bool warn = true;
if (strcmp(arg[i], "-f") == 0) {
warn = false;
++i;
}
for (;i < narg; i++) {
if (platform::unlink(arg[i]) < 0)
error->warning(FLERR, "Shell command 'rm {}' failed with error '{}'",
arg[i], utils::getsyserror());
if (warn)
error->warning(FLERR, "Shell command 'rm {}' failed with error '{}'",
arg[i], utils::getsyserror());
}
}
} else if (strcmp(arg[0],"rmdir") == 0) {