Skip to content

Commit

Permalink
core: switching os::tmpdir() to always return a directory, by default…
Browse files Browse the repository at this point in the history
…ing to Windows dir on windows, as per .NET
  • Loading branch information
Daniel Patterson authored and brson committed Aug 21, 2012
1 parent 9bb2963 commit 8b8e0c2
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/libcore/os.rs
Expand Up @@ -465,16 +465,16 @@ fn homedir() -> option<Path> {
}

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

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

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

#[cfg(windows)]
fn lookup() -> option<Path> {
option::or(getenv_nonempty(~"TMP"),
option::or(getenv_nonempty(~"TEMP"),
getenv_nonempty(~"USERPROFILE")))
fn lookup() -> Path {
option::get_default(
option::or(getenv_nonempty(~"TMP"),
option::or(getenv_nonempty(~"TEMP"),
option::or(getenv_nonempty(~"USERPROFILE"),
getenv_nonempty(~"WINDIR")))),
~"C:\\Windows")
}
}
/// Recursively walk a directory structure
Expand Down Expand Up @@ -970,7 +973,7 @@ mod tests {

#[test]
fn tmpdir() {
option::iter(os::tmpdir(), |s| assert !str::is_empty(s));
assert !str::is_empty(os::tmpdir());
}

// Issue #712
Expand Down

0 comments on commit 8b8e0c2

Please sign in to comment.