Download raw body.
patch: show an error when dired-do-copy fails due to permission issues
Hi tech@,
In Mg, when using dired-do-copy to copy a file to a location where you
lack write permissions, there is currently no error message displayed.
This occurs when a user creates a system configuration file in their
home directory and wants to copy it to /etc. The same applies for the
other way around.
Currently, the user is left wondering why a copy operation failed or
whether it succeeded. All other failure scenarios are already handled
via error messages and this addresses the missing two branches.
I took inspiration from the other error messages present in dired.c, but
I would prefer to include the file name in the error. What do you
prefer? I'll update my patch accordingly.
Furthermore, copy() always returns an integer greater than 0, so the
error handling in d_copy() was dead code.
Index: dired.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/dired.c,v
diff -u -p -r1.106 dired.c
--- dired.c 16 Oct 2026 04:05:51 -0000 1.106
+++ dired.c 12 Nov 2026 12:05:45 -0000
@@ -521,7 +521,7 @@ d_copy(int f, int n)
ewprintf("Cannot copy to same file: %s", frname);
return (TRUE);
}
- ret = (copy(frname, topath) >= 0) ? TRUE : FALSE;
+ ret = (copy(frname, topath) > 0) ? TRUE : FALSE;
if (ret != TRUE)
return (ret);
if ((bp = refreshbuffer(curbp)) == NULL)
Index: fileio.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/fileio.c,v
diff -u -p -r1.113 fileio.c
--- fileio.c 2 Mar 2026 19:38:17 -0000 1.113
+++ fileio.c 12 Nov 2026 12:05:45 -0000
@@ -386,8 +386,10 @@ copy(char *frname, char *toname)
struct stat orig;
ssize_t sr;
- if ((ifd = open(frname, O_RDONLY)) == -1)
+ if ((ifd = open(frname, O_RDONLY)) == -1) {
+ ewprintf("Cannot open file for reading : %s", strerror(errno));
return (FALSE);
+ }
if (fstat(ifd, &orig) == -1) {
dobeep();
ewprintf("fstat: %s", strerror(errno));
@@ -396,6 +398,7 @@ copy(char *frname, char *toname)
}
if ((ofd = open(toname, O_WRONLY|O_CREAT|O_TRUNC, fmode)) == -1) {
+ ewprintf("Cannot open file for writing : %s", strerror(errno));
close(ifd);
return (FALSE);
}
patch: show an error when dired-do-copy fails due to permission issues