bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: temp file suffixes: mktemp DWIM


From: Eric Blake
Subject: Re: temp file suffixes: mktemp DWIM
Date: Mon, 2 Nov 2009 23:06:21 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Jim Meyering <jim <at> meyering.net> writes:

> > the default template is tmp.XXXXXXXXXX, do we want to continue to guarantee
> > that we generate a file such as tmp.abcdef1234,
> 
> Why change?

Good point.  As part of my gnulib work, I guess that means I'll have to 
regenerate the coreutils patch to gen_tempname that lets us continue replacing 
an arbitrary number of X (as long as it is at least 3), rather than the 
gnulib/glibc approach of exactly 6.

> > I imagine it would make more sense to give mktemp(1) some do-what-I-mean 
smarts.
> > That is, I envision:
> >
> > mktemp foo-XXXXXX.txt
> >
> > calling mk[o]stemps("foo-XXXXXX.txt",4,0), automatically figuring out that 
the
> > final run of XXXXXX in the template implies a suffix of length 4, to create 
a
> > file such as "foo-abcdef.txt".
> >
> > Maybe it's even worth an option in case a user wants an explicit X in the
> > suffix, as in:
> >
> > mktemp --suffix-len=1 foo-XXXXXXX
> 
> Here's another way to do it:
> 
>     mktemp --suffix=X foo-XXXXXX

Nice idea.  Putting it all together, how about the following semantics:

mktemp a => error, no run of X
mktemp aXX => error, run of X is too short
mktemp XXX => generates 3-character name (if possible)
mktemp aXXX.b => generates 6-character name (if possible)
mktemp --suffix=.b aXXX => longer spelling of the above line
mktemp aXXX --suffix=.b => likewise, if not POSIXLY_CORRECT
mktemp aXXXbXXX => generates aXXXb123 (only the last run changed)
mktemp --suffix=X aXXX => only way to generate a123X instead of a1234
mktemp --suffix=.txt file => error, no run of X
mktemp --suffix=.txt aXXXb => error, explicit --suffix requires trailing X

The changes from the existing behavior:

Addition of a --suffix option (does it warrant a short option?  Probably not 
until it has had more field testing).  Explicit use of this argument requires 
trailing X in the template.

Addition of DWIM magic if --suffix is not present.  Currently, mktemp aXXX.b 
errors out, stating that there are too few X's in the template.  The new 
behavior recognizes any run of X, not just at the tail, and this goes a long 
way to meet user expectations:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=548316

-- 
Eric Blake






reply via email to

[Prev in Thread] Current Thread [Next in Thread]