]> Cypherpunks repositories - gostls13.git/commit
io/ioutil: change TempFile prefix to a pattern
authorTom Limoncelli <tal@whatexit.org>
Sun, 8 Apr 2018 20:05:04 +0000 (16:05 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 12 Apr 2018 20:00:25 +0000 (20:00 +0000)
commit191efbc419d7e5dec842c20841f6f716da4b561d
treefc840d07b3c973c5aaf92b1afc779abd83084b9b
parent9be1921042b6b81b7f16fa8640ddc5868af6d31e
io/ioutil: change TempFile prefix to a pattern

Users of TempFile need to be able to supply the suffix, especially
when using operating systems that give semantic meaning to the
filename extension such as Windows.  Renaming the file to include
an extension after the fact is insufficient as it could lead to
race conditions.

If the string given to TempFile includes a "*", the random string
replaces the "*". For example "myname.*.bat" will result in a random
filename such as "myname.123456.bat".  If no "*' is included the
old behavior is retained, and the random digits are appended to the
end.

If multiple "*" are included, the final one is replaced, thus
permitting a pathological programmer to create filenames such as
"foo*.123456.bat" but not "foo.123456.*.bat"

Fixes #4896

Change-Id: Iae7f0980b4de6d7d31b87c8c3c3d40767b283c1f
Reviewed-on: https://go-review.googlesource.com/105675
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/io/ioutil/example_test.go
src/io/ioutil/tempfile.go
src/io/ioutil/tempfile_test.go