ref: ca7b016256263cefe3884f1444ea79bbba889e45
parent: af1b48e0e0f95103e1919dfc385f37560eb661f2
author: phil9 <[email protected]>
date: Thu May 9 11:35:32 EDT 2024
improve rename/delete error handling silence command output and parse error message (more) properly
--- a/vdir.c
+++ b/vdir.c
@@ -226,9 +226,9 @@
int
doexec(char *cmd)
{
- int rc, n;
+ int rc;
Waitmsg *msg;
- char *f[3];
+ char *p;
rc = 0;
switch(rfork(RFPROC|RFFDG|RFREND)){
@@ -244,9 +244,9 @@
msg = wait();
if(msg != nil && msg->msg[0] != 0){
rc = -1;
- n = gettokens(msg->msg, f, 3, ":");
- if(n >= 3)
- werrstr(f[2]);
+ p = strchr(msg->msg, ':');
+ if(p != nil)
+ werrstr(p+2);
else
werrstr(msg->msg);
}
@@ -265,7 +265,7 @@
p = smprint("%s/%s", path, name);
qp = quotestrdup(p);
- snprint(cmd, sizeof cmd, "rm %s %s", rmode ? "-r" : "", qp);
+ snprint(cmd, sizeof cmd, "rm %s %s >/dev/null >[2=1]", rmode ? "-r" : "", qp);
if(doexec(cmd) < 0)
showerrstr("Cannot remove file/directory");
else
@@ -285,7 +285,7 @@
qfp = quotestrdup(fp);
qtp = quotestrdup(tp);
- snprint(cmd, sizeof cmd, "mv %s %s", qfp, qtp);
+ snprint(cmd, sizeof cmd, "mv %s %s >/dev/null >[2=1]", qfp, qtp);
if(doexec(cmd) < 0)
showerrstr("Cannot rename file/directory");
else