[Toybox] [PATCH] mktemp: add -t and fix behavior.

enh enh at google.com
Wed Nov 28 17:50:45 PST 2018


On Wed, Nov 28, 2018 at 5:19 PM Rob Landley <rob at landley.net> wrote:
>
> On 11/28/18 6:15 PM, enh via Toybox wrote:
> > The new tests pass on the host (coreutils 8.28) and with toybox after
> > this patch is applied.
> ...
> > -  if (!template) template = "tmp.XXXXXX";
> > +  if (!template) {
> > +    toys.optflags |= FLAG_t;
> > +    template = "tmp.XXXXXXXXXX";
> > +  }
> >
> > -  if (!TT.p) TT.p = getenv("TMPDIR");
> > +  if (!TT.p || (toys.optflags & FLAG_t)) TT.p = getenv("TMPDIR");
>
> What happens if you specify -p and -t together?

see the final test :-)

(if we were starting again in the 1970s, i'd say "obviously they
should be mutually exclusive", but i assume _someone_ is relying on
the current behavior, so...)

> >    if (!TT.p || !*TT.p) TT.p = "/tmp";
> >
> > -  template = strchr(template, '/') ? xstrdup(template)
> > -             : xmprintf("%s/%s", TT.p, template);
> > +  // TODO: coreutils cleans paths, so -p /t/// would result in /t/xxx...
> > +  template = (strchr(template, '/') || !(toys.optflags & (FLAG_p|FLAG_t)))
> > +      ? xstrdup(template) : xmprintf("%s/%s", TT.p, template);
>
> I used to have xrealpath() but then I had to make xabspath to implement all the
> readlink options (the libc one didn't _quite_ let me get in there and specify
> the behavior, so I had to reinvent the wheel), and I just use that now.
>
> >      if (toys.optflags & FLAG_q) toys.exitval = 1;
> >      else perror_exit("Failed to create %s %s/%s",
> > -                     d_flag ? "directory" : "file", TT.p, template);
>
> > +        toys.optflags & FLAG_d ? "directory" : "file", TT.p, template);
>
> Sigh. I should do a FLAG(d) macro...

yeah, you mentioned that before. if i didn't say so at the time then
yes, i agree that's a great idea.

> Rob



More information about the Toybox mailing list