Download raw body.
patch: show an error when dired-do-copy fails due to permission issues
patch: show an error when dired-do-copy fails due to permission issues
patch: show an error when dired-do-copy fails due to permission issues
Hello,
"Jan Fooken" <dev@janvhs.com> wrote:
> 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've committed your diff with just couple of nits fixed on top.
explanations inline.
> 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.
my guess is that it was not done to save some horizontal space for the
actual error (since mg doesn't have a *messages* buffer where the copy
of what was displayed in the echo area can be seen)
I wouldn't mind to display the file name though.
> Furthermore, copy() always returns an integer greater than 0, so the
> error handling in d_copy() was dead code.
seems that this was like that since the first import :))
i've also took the chance to de-french-ify the error messages (i.e.
remove the spaces before the colon in a couple of files), the majority
of the codebase was using "foo: bar" instead of "foo : bar".
> 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);
since it can just return only TRUE or FALSE i've turned this into:
}
- ret = (copy(frname, topath) >= 0) ? TRUE : FALSE;
- if (ret != TRUE)
- return (ret);
+ if (copy(frname, topath) == FALSE)
+ return (FALSE);
if ((bp = refreshbuffer(curbp)) == NULL)
return (FALSE);
> 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) {
i guess here we were missing a dobeep(); added before committing
> + 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) {
ditto
> + 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
patch: show an error when dired-do-copy fails due to permission issues
patch: show an error when dired-do-copy fails due to permission issues