diff options
author | Kaushal Modi <kaushal.modi@gmail.com> | 2019-06-10 13:59:51 -0400 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-06-10 19:59:51 +0200 |
commit | 2334680b3d6ee025b8c2560d591811cbda3eb7cf (patch) | |
tree | 13f008622bceec44cadf8c38cf790906dde9d507 /lib/pure | |
parent | 94177f7357c3f67ea77b8fcf8ba1dbc0eb3f0423 (diff) | |
download | Nim-2334680b3d6ee025b8c2560d591811cbda3eb7cf.tar.gz |
Use TMPDIR env var if available to get the temp dir name (#11443) [bugfix]
Additionally, use normalizePathEnd to suffix the dir name with "/" or "\" as appropriate for the current OS. Fixes https://github.com/nim-lang/Nim/issues/11439.
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/os.nim | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index aa58fea73..79a24662d 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -798,13 +798,16 @@ proc getTempDir*(): string {.rtl, extern: "nos$1", ## * `expandTilde proc <#expandTilde,string>`_ ## * `getCurrentDir proc <#getCurrentDir>`_ ## * `setCurrentDir proc <#setCurrentDir,string>`_ - const tempDirDefault = "/tmp/" + const tempDirDefault = "/tmp" + result = tempDirDefault when defined(tempDir): const tempDir {.strdefine.}: string = tempDirDefault - return tempDir - elif defined(windows): return string(getEnv("TEMP")) & "\\" - elif defined(android): return getHomeDir() - else: return tempDirDefault + result = tempDir + elif defined(windows): result = string(getEnv("TEMP")) + elif defined(android): result = getHomeDir() + else: + if existsEnv("TMPDIR"): result = string(getEnv("TMPDIR")) + normalizePathEnd(result, trailingSep=true) proc expandTilde*(path: string): string {. tags: [ReadEnvEffect, ReadIOEffect].} = |