mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 06:00:35 +03:00
Fix Issue 17488 - Add trailing slash to POSIX tempDir() to match Windows behaviour
This commit is contained in:
parent
e1d6e6f116
commit
02f4f148cf
1 changed files with 25 additions and 3 deletions
28
std/file.d
28
std/file.d
|
@ -5275,9 +5275,20 @@ slurp(Types...)(string filename, scope const(char)[] format)
|
|||
assert(slurp!(int)(deleteme, "%d") == [10, 20]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns the path to a directory for temporary files.
|
||||
On POSIX platforms, it searches through the following list of directories
|
||||
and returns the first one which is found to exist:
|
||||
$(OL
|
||||
$(LI The directory given by the `TMPDIR` environment variable.)
|
||||
$(LI The directory given by the `TEMP` environment variable.)
|
||||
$(LI The directory given by the `TMP` environment variable.)
|
||||
$(LI `/tmp/`)
|
||||
$(LI `/var/tmp/`)
|
||||
$(LI `/usr/tmp/`)
|
||||
)
|
||||
|
||||
On all platforms, `tempDir` returns the current working directory on failure.
|
||||
|
||||
The return value of the function is cached, so the procedures described
|
||||
below will only be performed the first time the function is called. All
|
||||
|
@ -5321,13 +5332,14 @@ string tempDir() @trusted
|
|||
}
|
||||
else version (Posix)
|
||||
{
|
||||
import std.path : dirSeparator;
|
||||
import std.process : environment;
|
||||
// This function looks through the list of alternative directories
|
||||
// and returns the first one which exists and is a directory.
|
||||
static string findExistingDir(T...)(lazy T alternatives)
|
||||
{
|
||||
foreach (dir; alternatives)
|
||||
if (!dir.empty && exists(dir)) return dir;
|
||||
if (!dir.empty && exists(dir)) return dir ~ dirSeparator;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -5340,7 +5352,10 @@ string tempDir() @trusted
|
|||
}
|
||||
else static assert(false, "Unsupported platform");
|
||||
|
||||
if (cache is null) cache = getcwd();
|
||||
if (cache is null)
|
||||
{
|
||||
cache = getcwd() ~ dirSeparator;
|
||||
}
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
@ -5363,6 +5378,13 @@ string tempDir() @trusted
|
|||
assert(myFile.readText == "hello");
|
||||
}
|
||||
|
||||
@safe unittest
|
||||
{
|
||||
import std.algorithm.searching : endsWith;
|
||||
import std.path : dirSeparator;
|
||||
assert(tempDir.endsWith(dirSeparator));
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the available disk space based on a given path.
|
||||
On Windows, `path` must be a directory; on POSIX systems, it can be a file or directory.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue