Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] zf_ln complains about the wrong argument

On Sun, 2021-08-22 at 16:45 +0300, Marlon Richert wrote:
> When the second argument to zf_ln is an empty string, zf_ln mistakenly
> reports that the first argument is a non-existing file or dir:
> % zmodload zsh/files
> % touch foo
> % zf_ln foo ''
> zf_ln: foo: no such file or directory

Is this good enough to detect cases like this?  An extra stat in the
error case should be neither here nor there.

Also seems a good idea to turn a null string into a couple of quotes.  I
thought of modifying the error message handler but this has too many
knock on effects.


diff --git a/Src/Modules/files.c b/Src/Modules/files.c
index a1d6f6bf2..d4ec93624 100644
--- a/Src/Modules/files.c
+++ b/Src/Modules/files.c
@@ -346,7 +346,16 @@ domove(char *nam, MoveFunc movefn, char *p, char *q, int flags)
     if(movefn(pbuf, qbuf)) {
-	zwarnnam(nam, "%s: %e", p, errno);
+	int ferrno = errno;
+	char *errfile = p;
+	if (ferrno == ENOENT && !lstat(pbuf, &st)) {
+	    /* p *does* exist, so error is in q */
+	    errfile = q;
+	}
+	if (*errfile)
+	    zwarnnam(nam, "%s: %e", errfile, ferrno);
+	else
+	    zwarnnam(nam, "`': %e", ferrno);
 	return 1;

Messages sorted by: Reverse Date, Date, Thread, Author