summary refs log tree commit diff stats
path: root/lib
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
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')
-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].} =
'/akkartik/mu/blame/038new_text.cc?h=main&id=8752e6b09e302c88702ab6e7a965daa624ba5213'>^
b0bf5321 ^
78c50205 ^
b0bf5321 ^
78c50205 ^
b0bf5321 ^
78c50205 ^
b0bf5321 ^




78c50205 ^
b0bf5321 ^


7fd01071 ^
2efceef6 ^
ad2604e8 ^





b0bf5321 ^

6c96a437 ^
b0bf5321 ^


ad2604e8 ^

b0bf5321 ^
ad2604e8 ^
b0bf5321 ^
9a81d746 ^
b0bf5321 ^






7c9def3c ^

b0bf5321 ^


43b866d1 ^
78c50205 ^
b0bf5321 ^
78c50205 ^
b0bf5321 ^



7c9def3c ^

b0bf5321 ^




7c9def3c ^

b0bf5321 ^


d9630e06 ^

7c9def3c ^

d9630e06 ^



78c50205 ^
d9630e06 ^

b0bf5321 ^

ad2604e8 ^
b0bf5321 ^
192d59d3 ^
7c9def3c ^
b0bf5321 ^
ad2604e8 ^

b0bf5321 ^














78c50205 ^
b0bf5321 ^
7fd01071 ^
b0bf5321 ^


6c96a437 ^
b0bf5321 ^



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139