summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorKaushal Modi <kaushal.modi@gmail.com>2019-06-10 13:59:51 -0400
committerAndreas Rumpf <rumpf_a@web.de>2019-06-10 19:59:51 +0200
commit2334680b3d6ee025b8c2560d591811cbda3eb7cf (patch)
tree13f008622bceec44cadf8c38cf790906dde9d507 /lib/pure
parent94177f7357c3f67ea77b8fcf8ba1dbc0eb3f0423 (diff)
downloadNim-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.nim13
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].} =
fdd413578bb9e315f34a53369f111ed'>^
e60868a78 ^
3e87ef35f ^




b790159bb ^
7e3ebc1bc ^









3e87ef35f ^
7e3ebc1bc ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61