annotate dmd/FileName.d @ 4:d706d958e4e8

Step 2 of restoring GC functionality.
author korDen
date Mon, 26 Oct 2009 16:28:19 +0300
parents 7427ded8caf7
children 63623152e82a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.FileName;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.String;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.File;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
8 import core.memory;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
9
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
10 import core.stdc.stdlib : alloca;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import core.stdc.string : memcpy, strlen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import core.stdc.ctype : isspace;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import std.contracts : assumeUnique;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import std.string : cmp, icmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import std.file : mkdirRecurse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import core.sys.windows.windows;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 class FileName : String
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 this(string str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 super(str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 this(string path, string name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 super(combine(path, name));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 hash_t hashCode()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 // We need a different hashCode because it must be case-insensitive
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 size_t len = str.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 hash_t hash = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 ubyte* s = cast(ubyte*)str.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 for (;;)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 switch (len)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 return hash;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 case 1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 hash *= 37;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 hash += *(cast(ubyte*)s) | 0x20;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 return hash;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 case 2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 hash *= 37;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 hash += *(cast(ushort*)s) | 0x2020;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 return hash;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 case 3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 hash *= 37;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 hash += (*cast(ushort*)s) << 8 +
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 ((cast(ubyte*)s)[2]) | 0x202020;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 hash *= 37;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 hash += (*cast(int*)s) | 0x20202020;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 s += 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 len -= 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 // darwin HFS is case insensitive, though...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 return super.hashCode();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 bool opEquals(Object obj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 return opCmp(obj) == 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 static int equals(string name1, string name2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 return compare(name1, name2) == 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 int opCmp(Object obj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 return compare(str, (cast(FileName)obj).str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 static int compare(string name1, string name2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 return icmp(name1, name2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 return cmp(name1, name2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 static bool absolute(string name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 return (*name == '\\') ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 (*name == '/') ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 (*name && name[1] == ':');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 } else version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 return (*name == '/');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 static assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 /********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 * Return filename extension (read-only).
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 * Points past '.' of extension.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 * If there isn't one, return NULL.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 static string ext(string str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 foreach_reverse (i, c; str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 case '.':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 return str[i+1..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 case ':':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 } default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 string ext()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 return ext(str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 /********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 * Return filename with extension removed.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 static string removeExt(string str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 string e = ext(str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 if (e !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 size_t len = (e.ptr - str.ptr - 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 return str[0..len];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 return str;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 /********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 * Return filename name excluding path (read-only).
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 static string name(string str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 foreach_reverse(i, c; str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 return str[i+1..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 return str[i+1..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 case ':':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 /* The ':' is a drive letter only if it is the second
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 * character or the last character,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 * otherwise it is an ADS (Alternate Data Stream) separator.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 * Consider ADS separators as part of the file name.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 if (i == 1 || i == str.length - 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 return str[i+1..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 return str;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 string name()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 return name(str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 * Return path portion of str.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 * Path will does not include trailing path separator.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 static string path(string str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 auto n = name(str).ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 if (n > str.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 auto p = n - 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 if (*p == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 n--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 } else version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 if (*p == '\\' || *p == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 n--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 static assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 size_t pathlen = n - str.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 return str[0..pathlen];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 * Replace filename portion of path.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 static string replaceName(string path, string name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 if (absolute(name))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 return name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 string n = FileName.name(path);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 if (n is path)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 return name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 size_t pathlen = n.ptr - path.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 size_t namelen = name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
249 char* f = cast(char*)GC.malloc(pathlen + 1 + namelen + 1);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 memcpy(f, path.ptr, pathlen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 if (path[pathlen - 1] != '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 f[pathlen] = '/';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 pathlen++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 } else version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 if (path[pathlen - 1] != '\\' &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 path[pathlen - 1] != '/' &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 path[pathlen - 1] != ':')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 f[pathlen] = '\\';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 pathlen++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 static assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 memcpy(f + pathlen, name.ptr, namelen + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 return assumeUnique(f[0..pathlen+namelen]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 static string combine(string path, string name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 size_t pathlen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 size_t namelen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 if (path.length == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 return name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 pathlen = path.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 namelen = name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
284 char* f = cast(char*)GC.malloc(pathlen + 1 + namelen + 1);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 memcpy(f, path.ptr, pathlen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 if (path[pathlen - 1] != '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 f[pathlen] = '/';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 pathlen++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 } else version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 if (path[pathlen - 1] != '\\' &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 path[pathlen - 1] != '/' &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 path[pathlen - 1] != ':')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 f[pathlen] = '\\';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 pathlen++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 static assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 memcpy(f + pathlen, name.ptr, namelen + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 return assumeUnique(f[0..pathlen+namelen]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 static string[] splitPath(const(char)[] spath)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 char c = 0; // unnecessary initializer is for VC /W4
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 string[] array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 if (spath !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 const(char)* p = spath.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 int len = spath.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 char instring = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 while (len > 0 && isspace(*p)) { // skip leading whitespace
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 --len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 buf.reserve(len + 1); // guess size of path
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 for (; len; p++, len--)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 instring ^= 1; // toggle inside/outside of string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 version (MACINTOSH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 case ',':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 case ';':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 case ':':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 break; // note that ; cannot appear as part
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 // of a path, quotes won't protect it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 case 0x1A: // ^Z means end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 //case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 continue; // ignore carriage returns
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 case '~':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 buf.writestring(getenv("HOME"));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 version (disabled) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 case ' ':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 case '\t': // tabs in filenames?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 if (!instring) // if not in string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 break; // treat as end of path
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 buf.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 if (buf.offset) // if path is not empty
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 //buf.writeByte(0); // to asciiz
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 array ~= buf.extractString();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 } while (len > 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 return array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 static FileName defaultExt(string name, string ext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 string e = FileName.ext(name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 if (e !is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 // if already has an extension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 return new FileName(name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 size_t len = name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 size_t extlen = ext.length;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
399 char* s = cast(char*)GC.malloc(len + 1 + extlen + 1);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 memcpy(s, name.ptr, len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 s[len] = '.';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 memcpy(s + len + 1, ext.ptr, extlen + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 return new FileName(assumeUnique(s[0..len+1+extlen]));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 static FileName forceExt(string name, string ext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 string e = FileName.ext(name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 if (e !is null) // if already has an extension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 size_t len = e.ptr - name.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 size_t extlen = ext.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
415 char* s = cast(char*)GC.malloc(len + extlen + 1);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 memcpy(s, name.ptr, len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 memcpy(s + len, ext.ptr, extlen + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 return new FileName(assumeUnique(s[0..len+extlen]));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 return defaultExt(name, ext); // doesn't have one
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 /******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 * Return true if extensions match.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 bool equalsExt(string ext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 string e = FileName.ext();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 if (e.length == 0 && ext.length == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 if (e.length == 0 || ext.length == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 return cmp(e,ext) == 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 } else version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 return icmp(e,ext) == 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 static assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 * Copy file from this to to.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 void CopyTo(FileName to)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 scope File file = new File(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 version (_WIN32) {
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
455 file.touchtime = GC.malloc(WIN32_FIND_DATA.sizeof); // keep same file time
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 } else version (POSIX) {
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
457 file.touchtime = GC.malloc(stat.sizeof); // keep same file time
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 static assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 file.readv();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 file.name = to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 file.writev();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 * Search Path for file.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 * cwd if true, search current directory before searching path
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 static string searchPath(Array path, string name, bool cwd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 if (absolute(name)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 return exists(name) ? name : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 if (cwd) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 if (exists(name)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 return name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 if (path !is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 foreach (i; 0..path.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 String p = cast(String)path.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 string n = combine(p.str, name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 if (exists(n))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 return n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 static int exists(string name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 stat st;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 if (stat(name, &st) < 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 if (S_ISDIR(st.st_mode))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 return 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 } else version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 HANDLE h = CreateFileA(toStringz(name), GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, HANDLE.init); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 if (h == INVALID_HANDLE_VALUE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 CloseHandle(h);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 DWORD dw = GetFileAttributesA(name.ptr); /// CARE!
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 if (dw == -1L) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 } else if (dw & FILE_ATTRIBUTE_DIRECTORY) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 return 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 static assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 static void ensurePathExists(string path)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 try {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 mkdirRecurse(path);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 } catch {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 }