OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
9 | 9 |
10 #include <dirent.h> // NOLINT | 10 #include <dirent.h> // NOLINT |
11 #include <errno.h> // NOLINT | 11 #include <errno.h> // NOLINT |
12 #include <string.h> // NOLINT | 12 #include <string.h> // NOLINT |
13 #include <sys/param.h> // NOLINT | 13 #include <sys/param.h> // NOLINT |
14 #include <sys/stat.h> // NOLINT | 14 #include <sys/stat.h> // NOLINT |
15 #include <unistd.h> // NOLINT | 15 #include <unistd.h> // NOLINT |
16 | 16 |
17 #include "bin/file.h" | 17 #include "bin/file.h" |
18 #include "bin/platform.h" | 18 #include "bin/platform.h" |
19 | 19 |
20 | 20 |
21 namespace dart { | 21 namespace dart { |
22 namespace bin { | 22 namespace bin { |
23 | 23 |
24 class PathBuffer { | 24 PathBuffer::PathBuffer() : length_(0) { |
25 public: | 25 data_ = new char[PATH_MAX + 1]; |
26 PathBuffer() : length(0) { | 26 } |
27 data = new char[PATH_MAX + 1]; | 27 |
| 28 char* PathBuffer::AsString() const { |
| 29 return reinterpret_cast<char*>(data_); |
| 30 } |
| 31 |
| 32 bool PathBuffer::Add(const char* name) { |
| 33 char* data = AsString(); |
| 34 int written = snprintf(data + length_, |
| 35 PATH_MAX - length_, |
| 36 "%s", |
| 37 name); |
| 38 data[PATH_MAX] = '\0'; |
| 39 if (written <= PATH_MAX - length_ && |
| 40 written >= 0 && |
| 41 static_cast<size_t>(written) == strnlen(name, PATH_MAX + 1)) { |
| 42 length_ += written; |
| 43 return true; |
| 44 } else { |
| 45 errno = ENAMETOOLONG; |
| 46 return false; |
28 } | 47 } |
| 48 } |
29 | 49 |
30 ~PathBuffer() { | 50 void PathBuffer::Reset(int new_length) { |
31 delete[] data; | 51 length_ = new_length; |
32 } | 52 AsString()[length_] = '\0'; |
33 | 53 } |
34 char* data; | |
35 int length; | |
36 | |
37 bool Add(const char* name) { | |
38 int written = snprintf(data + length, | |
39 PATH_MAX - length, | |
40 "%s", | |
41 name); | |
42 data[PATH_MAX] = '\0'; | |
43 if (written <= PATH_MAX - length && | |
44 written >= 0 && | |
45 static_cast<size_t>(written) == strlen(name)) { | |
46 length += written; | |
47 return true; | |
48 } else { | |
49 errno = ENAMETOOLONG; | |
50 return false; | |
51 } | |
52 } | |
53 | |
54 void Reset(int new_length) { | |
55 length = new_length; | |
56 data[length] = '\0'; | |
57 } | |
58 }; | |
59 | 54 |
60 | 55 |
61 // A linked list of symbolic links, with their unique file system identifiers. | 56 // A linked list of symbolic links, with their unique file system identifiers. |
62 // These are scanned to detect loops while doing a recursive directory listing. | 57 // These are scanned to detect loops while doing a recursive directory listing. |
63 struct LinkList { | 58 struct LinkList { |
64 dev_t dev; | 59 dev_t dev; |
65 ino_t ino; | 60 ino_t ino; |
66 LinkList* next; | 61 LinkList* next; |
67 }; | 62 }; |
68 | 63 |
69 | 64 |
70 // Forward declarations. | 65 ListType DirectoryListingEntry::Next(DirectoryListing* listing) { |
71 static bool ListRecursively(PathBuffer* path, | 66 if (done_) { |
72 bool recursive, | 67 return kListDone; |
73 bool follow_links, | 68 } |
74 LinkList* seen, | |
75 DirectoryListing* listing); | |
76 static bool DeleteRecursively(PathBuffer* path); | |
77 | 69 |
| 70 if (lister_ == 0) { |
| 71 if (!listing->path_buffer().Add(File::PathSeparator())) { |
| 72 done_ = true; |
| 73 return kListError; |
| 74 } |
| 75 path_length_ = listing->path_buffer().length(); |
| 76 do { |
| 77 lister_ = reinterpret_cast<intptr_t>( |
| 78 opendir(listing->path_buffer().AsString())); |
| 79 } while (lister_ == 0 && errno == EINTR); |
78 | 80 |
79 static void PostError(DirectoryListing *listing, | 81 if (lister_ == 0) { |
80 const char* dir_name) { | 82 done_ = true; |
81 listing->HandleError(dir_name); | 83 return kListError; |
82 } | 84 } |
83 | |
84 | |
85 static bool HandleDir(char* dir_name, | |
86 PathBuffer* path, | |
87 bool recursive, | |
88 bool follow_links, | |
89 LinkList* seen, | |
90 DirectoryListing *listing) { | |
91 if (strcmp(dir_name, ".") == 0) return true; | |
92 if (strcmp(dir_name, "..") == 0) return true; | |
93 if (!path->Add(dir_name)) { | |
94 PostError(listing, path->data); | |
95 return false; | |
96 } | 85 } |
97 return listing->HandleDirectory(path->data) && | 86 // Reset. |
98 (!recursive || | 87 listing->path_buffer().Reset(path_length_); |
99 ListRecursively(path, recursive, follow_links, seen, listing)); | 88 ResetLink(); |
100 } | |
101 | |
102 | |
103 static bool HandleFile(char* file_name, | |
104 PathBuffer* path, | |
105 DirectoryListing *listing) { | |
106 if (!path->Add(file_name)) { | |
107 PostError(listing, path->data); | |
108 return false; | |
109 } | |
110 return listing->HandleFile(path->data); | |
111 } | |
112 | |
113 | |
114 static bool HandleLink(char* link_name, | |
115 PathBuffer* path, | |
116 DirectoryListing *listing) { | |
117 if (!path->Add(link_name)) { | |
118 PostError(listing, path->data); | |
119 return false; | |
120 } | |
121 return listing->HandleLink(path->data); | |
122 } | |
123 | |
124 | |
125 static bool ListRecursively(PathBuffer* path, | |
126 bool recursive, | |
127 bool follow_links, | |
128 LinkList* seen, | |
129 DirectoryListing *listing) { | |
130 if (!path->Add(File::PathSeparator())) { | |
131 PostError(listing, path->data); | |
132 return false; | |
133 } | |
134 DIR* dir_pointer; | |
135 do { | |
136 dir_pointer = opendir(path->data); | |
137 } while (dir_pointer == NULL && errno == EINTR); | |
138 if (dir_pointer == NULL) { | |
139 PostError(listing, path->data); | |
140 return false; | |
141 } | |
142 | 89 |
143 // Iterate the directory and post the directories and files to the | 90 // Iterate the directory and post the directories and files to the |
144 // ports. | 91 // ports. |
145 int path_length = path->length; | |
146 int status = 0; | 92 int status = 0; |
147 bool success = true; | |
148 dirent entry; | 93 dirent entry; |
149 dirent* result; | 94 dirent* result; |
150 while ((status = TEMP_FAILURE_RETRY(readdir_r(dir_pointer, | 95 if ((status = TEMP_FAILURE_RETRY(readdir_r(reinterpret_cast<DIR*>(lister_), |
151 &entry, | 96 &entry, |
152 &result))) == 0 && | 97 &result))) == 0 && |
153 result != NULL) { | 98 result != NULL) { |
| 99 if (!listing->path_buffer().Add(entry.d_name)) { |
| 100 done_ = true; |
| 101 return kListError; |
| 102 } |
154 switch (entry.d_type) { | 103 switch (entry.d_type) { |
155 case DT_DIR: | 104 case DT_DIR: |
156 success = HandleDir(entry.d_name, | 105 if (strcmp(entry.d_name, ".") == 0) return Next(listing); |
157 path, | 106 if (strcmp(entry.d_name, "..") == 0) return Next(listing); |
158 recursive, | 107 return kListDirectory; |
159 follow_links, | |
160 seen, | |
161 listing) && success; | |
162 break; | |
163 case DT_REG: | 108 case DT_REG: |
164 success = HandleFile(entry.d_name, | 109 return kListFile; |
165 path, | |
166 listing) && success; | |
167 break; | |
168 case DT_LNK: | 110 case DT_LNK: |
169 if (!follow_links) { | 111 if (!listing->follow_links()) { |
170 success = HandleLink(entry.d_name, | 112 return kListLink; |
171 path, | |
172 listing) && success; | |
173 break; | |
174 } | 113 } |
175 // Else fall through to next case. | 114 // Else fall through to next case. |
176 // Fall through. | 115 // Fall through. |
177 case DT_UNKNOWN: { | 116 case DT_UNKNOWN: { |
178 // On some file systems the entry type is not determined by | 117 // On some file systems the entry type is not determined by |
179 // readdir_r. For those and for links we use stat to determine | 118 // readdir_r. For those and for links we use stat to determine |
180 // the actual entry type. Notice that stat returns the type of | 119 // the actual entry type. Notice that stat returns the type of |
181 // the file pointed to. | 120 // the file pointed to. |
182 struct stat entry_info; | 121 struct stat entry_info; |
183 if (!path->Add(entry.d_name)) { | 122 int stat_success; |
184 success = false; | 123 stat_success = TEMP_FAILURE_RETRY( |
185 break; | 124 lstat(listing->path_buffer().AsString(), &entry_info)); |
| 125 if (stat_success == -1) { |
| 126 return kListError; |
186 } | 127 } |
187 int stat_success; | 128 if (listing->follow_links() && S_ISLNK(entry_info.st_mode)) { |
188 stat_success = TEMP_FAILURE_RETRY(lstat(path->data, &entry_info)); | |
189 if (stat_success == -1) { | |
190 success = false; | |
191 PostError(listing, path->data); | |
192 break; | |
193 } | |
194 if (follow_links && S_ISLNK(entry_info.st_mode)) { | |
195 // Check to see if we are in a loop created by a symbolic link. | 129 // Check to see if we are in a loop created by a symbolic link. |
| 130 LinkList* previous = reinterpret_cast<LinkList*>(link_); |
196 LinkList current_link = { entry_info.st_dev, | 131 LinkList current_link = { entry_info.st_dev, |
197 entry_info.st_ino, | 132 entry_info.st_ino, |
198 seen }; | 133 previous }; |
199 LinkList* previous = seen; | |
200 bool looping_link = false; | |
201 while (previous != NULL) { | 134 while (previous != NULL) { |
202 if (previous->dev == current_link.dev && | 135 if (previous->dev == current_link.dev && |
203 previous->ino == current_link.ino) { | 136 previous->ino == current_link.ino) { |
204 // Report the looping link as a link, rather than following it. | 137 // Report the looping link as a link, rather than following it. |
205 path->Reset(path_length); | 138 return kListLink; |
206 success = HandleLink(entry.d_name, | |
207 path, | |
208 listing) && success; | |
209 looping_link = true; | |
210 break; | |
211 } | 139 } |
212 previous = previous->next; | 140 previous = previous->next; |
213 } | 141 } |
214 if (looping_link) break; | 142 stat_success = TEMP_FAILURE_RETRY( |
215 stat_success = TEMP_FAILURE_RETRY(stat(path->data, &entry_info)); | 143 stat(listing->path_buffer().AsString(), &entry_info)); |
216 if (stat_success == -1) { | 144 if (stat_success == -1) { |
217 // Report a broken link as a link, even if follow_links is true. | 145 // Report a broken link as a link, even if follow_links is true. |
218 path->Reset(path_length); | 146 return kListLink; |
219 success = HandleLink(entry.d_name, | |
220 path, | |
221 listing) && success; | |
222 break; | |
223 } | 147 } |
224 if (S_ISDIR(entry_info.st_mode)) { | 148 if (S_ISDIR(entry_info.st_mode)) { |
225 // Recurse into the subdirectory with current_link added to the | 149 // Recurse into the subdirectory with current_link added to the |
226 // linked list of seen file system links. | 150 // linked list of seen file system links. |
227 path->Reset(path_length); | 151 link_ = new LinkList(current_link); |
228 success = HandleDir(entry.d_name, | 152 if (strcmp(entry.d_name, ".") == 0) return Next(listing); |
229 path, | 153 if (strcmp(entry.d_name, "..") == 0) return Next(listing); |
230 recursive, | 154 return kListDirectory; |
231 follow_links, | |
232 ¤t_link, | |
233 listing) && success; | |
234 break; | |
235 } | 155 } |
236 } | 156 } |
237 path->Reset(path_length); | |
238 if (S_ISDIR(entry_info.st_mode)) { | 157 if (S_ISDIR(entry_info.st_mode)) { |
239 success = HandleDir(entry.d_name, | 158 if (strcmp(entry.d_name, ".") == 0) return Next(listing); |
240 path, | 159 if (strcmp(entry.d_name, "..") == 0) return Next(listing); |
241 recursive, | 160 return kListDirectory; |
242 follow_links, | |
243 seen, | |
244 listing) && success; | |
245 } else if (S_ISREG(entry_info.st_mode)) { | 161 } else if (S_ISREG(entry_info.st_mode)) { |
246 success = HandleFile(entry.d_name, | 162 return kListFile; |
247 path, | |
248 listing) && success; | |
249 } else if (S_ISLNK(entry_info.st_mode)) { | 163 } else if (S_ISLNK(entry_info.st_mode)) { |
250 success = HandleLink(entry.d_name, | 164 return kListLink; |
251 path, | |
252 listing) && success; | |
253 } | 165 } |
254 break; | |
255 } | 166 } |
| 167 |
256 default: | 168 default: |
257 break; | 169 break; |
258 } | 170 } |
259 path->Reset(path_length); | |
260 } | 171 } |
| 172 done_ = true; |
261 | 173 |
262 if (status != 0) { | 174 if (status != 0) { |
263 errno = status; | 175 errno = status; |
264 success = false; | 176 return kListError; |
265 PostError(listing, path->data); | |
266 } | 177 } |
267 | 178 |
268 if (closedir(dir_pointer) == -1) { | 179 if (closedir(reinterpret_cast<DIR*>(lister_)) == -1) { |
269 success = false; | 180 return kListError; |
270 PostError(listing, path->data); | |
271 } | 181 } |
272 | 182 |
273 return success; | 183 return kListDone; |
274 } | 184 } |
275 | 185 |
276 | 186 |
| 187 static bool DeleteRecursively(PathBuffer* path); |
| 188 |
| 189 |
277 static bool DeleteFile(char* file_name, | 190 static bool DeleteFile(char* file_name, |
278 PathBuffer* path) { | 191 PathBuffer* path) { |
279 return path->Add(file_name) && unlink(path->data) == 0; | 192 return path->Add(file_name) && unlink(path->AsString()) == 0; |
280 } | 193 } |
281 | 194 |
282 | 195 |
283 static bool DeleteDir(char* dir_name, | 196 static bool DeleteDir(char* dir_name, |
284 PathBuffer* path) { | 197 PathBuffer* path) { |
285 if (strcmp(dir_name, ".") == 0) return true; | 198 if (strcmp(dir_name, ".") == 0) return true; |
286 if (strcmp(dir_name, "..") == 0) return true; | 199 if (strcmp(dir_name, "..") == 0) return true; |
287 return path->Add(dir_name) && DeleteRecursively(path); | 200 return path->Add(dir_name) && DeleteRecursively(path); |
288 } | 201 } |
289 | 202 |
290 | 203 |
291 static bool DeleteRecursively(PathBuffer* path) { | 204 static bool DeleteRecursively(PathBuffer* path) { |
292 // Do not recurse into links for deletion. Instead delete the link. | 205 // Do not recurse into links for deletion. Instead delete the link. |
293 // If it's a file, delete it. | 206 // If it's a file, delete it. |
294 struct stat st; | 207 struct stat st; |
295 if (TEMP_FAILURE_RETRY(lstat(path->data, &st)) == -1) { | 208 if (TEMP_FAILURE_RETRY(lstat(path->AsString(), &st)) == -1) { |
296 return false; | 209 return false; |
297 } else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { | 210 } else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { |
298 return (unlink(path->data) == 0); | 211 return (unlink(path->AsString()) == 0); |
299 } | 212 } |
300 | 213 |
301 if (!path->Add(File::PathSeparator())) return false; | 214 if (!path->Add(File::PathSeparator())) return false; |
302 | 215 |
303 // Not a link. Attempt to open as a directory and recurse into the | 216 // Not a link. Attempt to open as a directory and recurse into the |
304 // directory. | 217 // directory. |
305 DIR* dir_pointer; | 218 DIR* dir_pointer; |
306 do { | 219 do { |
307 dir_pointer = opendir(path->data); | 220 dir_pointer = opendir(path->AsString()); |
308 } while (dir_pointer == NULL && errno == EINTR); | 221 } while (dir_pointer == NULL && errno == EINTR); |
309 | 222 |
310 if (dir_pointer == NULL) { | 223 if (dir_pointer == NULL) { |
311 return false; | 224 return false; |
312 } | 225 } |
313 | 226 |
314 // Iterate the directory and delete all files and directories. | 227 // Iterate the directory and delete all files and directories. |
315 int path_length = path->length; | 228 int path_length = path->length(); |
316 int read = 0; | 229 int read = 0; |
317 bool success = true; | 230 bool success = true; |
318 dirent entry; | 231 dirent entry; |
319 dirent* result; | 232 dirent* result; |
320 while ((read = TEMP_FAILURE_RETRY(readdir_r(dir_pointer, | 233 while ((read = TEMP_FAILURE_RETRY(readdir_r(dir_pointer, |
321 &entry, | 234 &entry, |
322 &result))) == 0 && | 235 &result))) == 0 && |
323 result != NULL && | 236 result != NULL && |
324 success) { | 237 success) { |
325 switch (entry.d_type) { | 238 switch (entry.d_type) { |
326 case DT_DIR: | 239 case DT_DIR: |
327 success = success && DeleteDir(entry.d_name, path); | 240 success = success && DeleteDir(entry.d_name, path); |
328 break; | 241 break; |
329 case DT_REG: | 242 case DT_REG: |
330 case DT_LNK: | 243 case DT_LNK: |
331 // Treat all links as files. This will delete the link which | 244 // Treat all links as files. This will delete the link which |
332 // is what we want no matter if the link target is a file or a | 245 // is what we want no matter if the link target is a file or a |
333 // directory. | 246 // directory. |
334 success = success && DeleteFile(entry.d_name, path); | 247 success = success && DeleteFile(entry.d_name, path); |
335 break; | 248 break; |
336 case DT_UNKNOWN: { | 249 case DT_UNKNOWN: { |
337 // On some file systems the entry type is not determined by | 250 // On some file systems the entry type is not determined by |
338 // readdir_r. For those we use lstat to determine the entry | 251 // readdir_r. For those we use lstat to determine the entry |
339 // type. | 252 // type. |
340 struct stat entry_info; | 253 struct stat entry_info; |
341 if (!path->Add(entry.d_name)) { | 254 if (!path->Add(entry.d_name)) { |
342 success = false; | 255 success = false; |
343 break; | 256 break; |
344 } | 257 } |
345 int lstat_success = TEMP_FAILURE_RETRY(lstat(path->data, &entry_info)); | 258 int lstat_success = TEMP_FAILURE_RETRY( |
| 259 lstat(path->AsString(), &entry_info)); |
346 if (lstat_success == -1) { | 260 if (lstat_success == -1) { |
347 success = false; | 261 success = false; |
348 break; | 262 break; |
349 } | 263 } |
350 path->Reset(path_length); | 264 path->Reset(path_length); |
351 if (S_ISDIR(entry_info.st_mode)) { | 265 if (S_ISDIR(entry_info.st_mode)) { |
352 success = success && DeleteDir(entry.d_name, path); | 266 success = success && DeleteDir(entry.d_name, path); |
353 } else if (S_ISREG(entry_info.st_mode) || S_ISLNK(entry_info.st_mode)) { | 267 } else if (S_ISREG(entry_info.st_mode) || S_ISLNK(entry_info.st_mode)) { |
354 // Treat links as files. This will delete the link which is | 268 // Treat links as files. This will delete the link which is |
355 // what we want no matter if the link target is a file or a | 269 // what we want no matter if the link target is a file or a |
356 // directory. | 270 // directory. |
357 success = success && DeleteFile(entry.d_name, path); | 271 success = success && DeleteFile(entry.d_name, path); |
358 } | 272 } |
359 break; | 273 break; |
360 } | 274 } |
361 default: | 275 default: |
362 break; | 276 break; |
363 } | 277 } |
364 path->Reset(path_length); | 278 path->Reset(path_length); |
365 } | 279 } |
366 | 280 |
367 if ((read != 0) || | 281 if ((read != 0) || |
368 (closedir(dir_pointer) == -1) || | 282 (closedir(dir_pointer) == -1) || |
369 (remove(path->data) == -1)) { | 283 (remove(path->AsString()) == -1)) { |
370 return false; | 284 return false; |
371 } | 285 } |
372 return success; | 286 return success; |
373 } | 287 } |
374 | 288 |
375 | 289 |
376 bool Directory::List(const char* dir_name, | |
377 bool recursive, | |
378 bool follow_links, | |
379 DirectoryListing *listing) { | |
380 PathBuffer path; | |
381 if (!path.Add(dir_name)) { | |
382 PostError(listing, dir_name); | |
383 return false; | |
384 } | |
385 return ListRecursively(&path, recursive, follow_links, NULL, listing); | |
386 } | |
387 | |
388 | |
389 Directory::ExistsResult Directory::Exists(const char* dir_name) { | 290 Directory::ExistsResult Directory::Exists(const char* dir_name) { |
390 struct stat entry_info; | 291 struct stat entry_info; |
391 int success = TEMP_FAILURE_RETRY(stat(dir_name, &entry_info)); | 292 int success = TEMP_FAILURE_RETRY(stat(dir_name, &entry_info)); |
392 if (success == 0) { | 293 if (success == 0) { |
393 if (S_ISDIR(entry_info.st_mode)) { | 294 if (S_ISDIR(entry_info.st_mode)) { |
394 return EXISTS; | 295 return EXISTS; |
395 } else { | 296 } else { |
396 return DOES_NOT_EXIST; | 297 return DOES_NOT_EXIST; |
397 } | 298 } |
398 } else { | 299 } else { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 } | 339 } |
439 | 340 |
440 | 341 |
441 char* Directory::CreateTemp(const char* const_template) { | 342 char* Directory::CreateTemp(const char* const_template) { |
442 // Returns a new, unused directory name, modifying the contents of | 343 // Returns a new, unused directory name, modifying the contents of |
443 // dir_template. Creates the directory with the permissions specified | 344 // dir_template. Creates the directory with the permissions specified |
444 // by the process umask. | 345 // by the process umask. |
445 // The return value must be freed by the caller. | 346 // The return value must be freed by the caller. |
446 PathBuffer path; | 347 PathBuffer path; |
447 path.Add(const_template); | 348 path.Add(const_template); |
448 if (path.length == 0) { | 349 if (path.length() == 0) { |
449 path.Add("/tmp/temp_dir1_"); | 350 path.Add("/tmp/temp_dir1_"); |
450 } else if ((path.data)[path.length - 1] == '/') { | 351 } else if ((path.AsString())[path.length() - 1] == '/') { |
451 path.Add("temp_dir_"); | 352 path.Add("temp_dir_"); |
452 } | 353 } |
453 if (!path.Add("XXXXXX")) { | 354 if (!path.Add("XXXXXX")) { |
454 // Pattern has overflowed. | 355 // Pattern has overflowed. |
455 return NULL; | 356 return NULL; |
456 } | 357 } |
457 char* result; | 358 char* result; |
458 do { | 359 do { |
459 result = mkdtemp(path.data); | 360 result = mkdtemp(path.AsString()); |
460 } while (result == NULL && errno == EINTR); | 361 } while (result == NULL && errno == EINTR); |
461 if (result == NULL) { | 362 if (result == NULL) { |
462 return NULL; | 363 return NULL; |
463 } | 364 } |
464 int length = strlen(path.data); | 365 int length = strlen(path.AsString()); |
465 result = static_cast<char*>(malloc(length + 1)); | 366 result = static_cast<char*>(malloc(length + 1)); |
466 strncpy(result, path.data, length); | 367 strncpy(result, path.AsString(), length); |
467 result[length] = '\0'; | 368 result[length] = '\0'; |
468 return result; | 369 return result; |
469 } | 370 } |
470 | 371 |
471 | 372 |
472 bool Directory::Delete(const char* dir_name, bool recursive) { | 373 bool Directory::Delete(const char* dir_name, bool recursive) { |
473 if (!recursive) { | 374 if (!recursive) { |
474 if (File::GetType(dir_name, false) == File::kIsLink && | 375 if (File::GetType(dir_name, false) == File::kIsLink && |
475 File::GetType(dir_name, true) == File::kIsDirectory) { | 376 File::GetType(dir_name, true) == File::kIsDirectory) { |
476 return (TEMP_FAILURE_RETRY(unlink(dir_name)) == 0); | 377 return (TEMP_FAILURE_RETRY(unlink(dir_name)) == 0); |
(...skipping 12 matching lines...) Expand all Loading... |
489 bool Directory::Rename(const char* path, const char* new_path) { | 390 bool Directory::Rename(const char* path, const char* new_path) { |
490 ExistsResult exists = Exists(path); | 391 ExistsResult exists = Exists(path); |
491 if (exists != EXISTS) return false; | 392 if (exists != EXISTS) return false; |
492 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); | 393 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); |
493 } | 394 } |
494 | 395 |
495 } // namespace bin | 396 } // namespace bin |
496 } // namespace dart | 397 } // namespace dart |
497 | 398 |
498 #endif // defined(TARGET_OS_MACOS) | 399 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |