Skip to content

Commit 8b8e0c2

Browse files
Daniel Pattersonbrson
Daniel Patterson
authored andcommitted
core: switching os::tmpdir() to always return a directory, by defaulting to Windows dir on windows, as per .NET
1 parent 9bb2963 commit 8b8e0c2

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/libcore/os.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -465,16 +465,16 @@ fn homedir() -> option<Path> {
465465
}
466466

467467
/**
468-
* Returns the path to a temporary directory, if known.
468+
* Returns the path to a temporary directory.
469469
*
470470
* On Unix, returns the value of the 'TMPDIR' environment variable if it is
471471
* set and non-empty and '/tmp' otherwise.
472472
*
473473
* On Windows, returns the value of, in order, the 'TMP', 'TEMP',
474-
* 'USERPROFILE' environment variable if any are set and not the empty
475-
* string. Otherwise, tmpdir returns option::none.
474+
* 'USERPROFILE' environment variable if any are set and not the empty
475+
* string. Otherwise, tmpdir returns the path to the Windows directory.
476476
*/
477-
fn tmpdir() -> option<Path> {
477+
fn tmpdir() -> Path {
478478
return lookup();
479479

480480
fn getenv_nonempty(v: Path) -> option<Path> {
@@ -490,15 +490,18 @@ fn tmpdir() -> option<Path> {
490490
}
491491

492492
#[cfg(unix)]
493-
fn lookup() -> option<Path> {
494-
option::or(getenv_nonempty(~"TMPDIR"), some(~"/tmp"))
493+
fn lookup() -> Path {
494+
option::get_default(getenv_nonempty(~"TMPDIR"), ~"/tmp")
495495
}
496496

497497
#[cfg(windows)]
498-
fn lookup() -> option<Path> {
499-
option::or(getenv_nonempty(~"TMP"),
500-
option::or(getenv_nonempty(~"TEMP"),
501-
getenv_nonempty(~"USERPROFILE")))
498+
fn lookup() -> Path {
499+
option::get_default(
500+
option::or(getenv_nonempty(~"TMP"),
501+
option::or(getenv_nonempty(~"TEMP"),
502+
option::or(getenv_nonempty(~"USERPROFILE"),
503+
getenv_nonempty(~"WINDIR")))),
504+
~"C:\\Windows")
502505
}
503506
}
504507
/// Recursively walk a directory structure
@@ -970,7 +973,7 @@ mod tests {
970973

971974
#[test]
972975
fn tmpdir() {
973-
option::iter(os::tmpdir(), |s| assert !str::is_empty(s));
976+
assert !str::is_empty(os::tmpdir());
974977
}
975978

976979
// Issue #712

0 commit comments

Comments
 (0)