Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions std/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -4398,7 +4398,7 @@ enum SpanMode
import std.algorithm.iteration : map;
import std.path : buildPath, relativePath;

auto root = tempDir.buildPath("root");
auto root = deleteme ~ "root";
scope(exit) root.rmdirRecurse;
root.mkdir;

Expand Down Expand Up @@ -5105,8 +5105,15 @@ string tempDir() @trusted
///
@safe unittest
{
import std.ascii : letters;
import std.conv : to;
import std.path : buildPath;
auto myFile = tempDir.buildPath("my_tmp_file");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not auto myFile = deleteme ~ "my_tmp_file";?

Seems like this is more complicated than it needs to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is the public example for tempDir - wouldn't make sense to not use it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto myFile = tempDir.buildPath(deleteme);?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleteme = "/tmp/<randomid>.<pid>

import std.random : randomSample;
import std.utf : byCodeUnit;

// random id with 20 letters
auto id = letters.byCodeUnit.randomSample(20).to!string;
auto myFile = tempDir.buildPath(id ~ "my_tmp_file");
scope(exit) myFile.remove;

myFile.write("hello");
Expand Down