trivial patch for misleading error message on failed directory creation. Notes: Wed Aug 31 15:04:40 EDT 2005 rsc If you run tar to try to extract a file inside a directory that cannot be created you used to get: % tar xf x.tar tar: can't create x/y: 'x/y' does not exist tar: can't create x/y/a: 'x/y/a' does not exist % I fixed the first error, which was tar's fault, so now you get: % tar xf x.tar tar: can't create x/y: permission denied tar: can't create x/y/a: 'x/y/a' does not exist % The second error is the kernel's fault: % syscall create x/y/a 0 0 syscall: return -1, error:'x/y/a' does not exist % Your fix did not make sense to me. It was second-guessing various operations instead of letting the real errors shine through. I will look at fixing the kernel message. Wed Aug 31 15:50:30 EDT 2005 rsc I fixed the kernel too. There is a new /sys/src/9/port/chan.c on sources. Reference: /n/sources/patch/sorry/tar-permission Date: Tue Aug 30 23:47:17 CES 2005 Signed-off-by: steve@quintile.net Reviewed-by: rsc --- /sys/src/cmd/tar.c Tue Aug 30 23:30:21 2005 +++ /sys/src/cmd/tar.c Tue Aug 30 23:30:16 2005 @@ -788,20 +788,23 @@ f = create(s, OREAD, DMDIR | 0777); if (f >= 0) close(f); + if (f < 0) + fprint(2, "%s: can't create %s: %r\n", argv0, s); return f; } -static void +static int mkpdirs(char *s) { - int done = 0; + int err = 0; char *p = s; - while (!done && (p = strchr(p + 1, '/')) != nil) { + while (!err && (p = strchr(p + 1, '/')) != nil) { *p = '\0'; - done = (access(s, AEXIST) < 0 && makedir(s) < 0); + err = (access(s, AEXIST) < 0 && makedir(s) < 0); *p = '/'; } + return err; } /* copy a file from the archive into the filesystem */ @@ -854,7 +857,8 @@ fd = create(fname, rw, mode); if (fd < 0) { - mkpdirs(fname); + if (mkpdirs(fname) != 0) + break; fd = create(fname, rw, mode); } if (fd < 0 &&