On Saturday, 17 January 2015 at 16:55:42 UTC, Marc Schütz wrote:
On Saturday, 17 January 2015 at 14:37:00 UTC, Laeeth Isharc
wrote:
On Saturday, 17 January 2015 at 13:47:39 UTC, Marc Schütz
wrote:
Is it currently possible to get the path to a safe temporary
file, i.e. one that is guaranteed to be freshly created and
will not override another existing file?
There's `std.file.tempDir`, which doesn't create a unique
file. Then there's `std.stdio.tmpfile()`, which does, but it
returns a `File` object, and its `name` property is `null`.
Did I miss something? IMO this is very import functionality.
One use case is passing these names as command line arguments
to an external program that doesn't support stdin/stdout.
I agree that it would be useful.
This is what I used, although there may be a better option:
http://dlang.org/phobos/std_uuid.html
Nice idea, but it still allows for intentional collision
attacks :-(
The only really safe solution is one that generates (probably)
unique names, then opens the file with O_EXCL|O_CREAT (or
whatever other means the OS provides), and if it fails, retries
with a different name. `std.stdio.tmpfile()` already does that
(it uses `tmpfile(3)` under the hood), but doesn't allow access
to the name.
I don't follow why a collision attack is applicable in this case.
Your stage 1 of generating unique names: how is this different
from using a random uuid?