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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
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/dartutils.h" |
17 #include "bin/file.h" | 18 #include "bin/file.h" |
18 #include "bin/platform.h" | 19 #include "bin/platform.h" |
19 | |
20 #include "platform/signal_blocker.h" | 20 #include "platform/signal_blocker.h" |
21 | 21 |
22 | |
23 namespace dart { | 22 namespace dart { |
24 namespace bin { | 23 namespace bin { |
25 | 24 |
| 25 PathBuffer::PathBuffer() : length_(0) { |
| 26 data_ = calloc(PATH_MAX + 1, sizeof(char)); // NOLINT |
| 27 } |
26 | 28 |
27 PathBuffer::PathBuffer() : length_(0) { | 29 |
28 data_ = calloc(PATH_MAX + 1, sizeof(char)); // NOLINT | 30 PathBuffer::~PathBuffer() { |
| 31 free(data_); |
29 } | 32 } |
30 | 33 |
| 34 |
31 bool PathBuffer::AddW(const wchar_t* name) { | 35 bool PathBuffer::AddW(const wchar_t* name) { |
32 UNREACHABLE(); | 36 UNREACHABLE(); |
33 return false; | 37 return false; |
34 } | 38 } |
35 | 39 |
| 40 |
36 char* PathBuffer::AsString() const { | 41 char* PathBuffer::AsString() const { |
37 return reinterpret_cast<char*>(data_); | 42 return reinterpret_cast<char*>(data_); |
38 } | 43 } |
39 | 44 |
| 45 |
40 wchar_t* PathBuffer::AsStringW() const { | 46 wchar_t* PathBuffer::AsStringW() const { |
41 UNREACHABLE(); | 47 UNREACHABLE(); |
42 return NULL; | 48 return NULL; |
43 } | 49 } |
44 | 50 |
| 51 |
| 52 const char* PathBuffer::AsScopedString() const { |
| 53 return DartUtils::ScopedCopyCString(AsString()); |
| 54 } |
| 55 |
| 56 |
45 bool PathBuffer::Add(const char* name) { | 57 bool PathBuffer::Add(const char* name) { |
46 char* data = AsString(); | 58 char* data = AsString(); |
47 int written = snprintf(data + length_, | 59 int written = snprintf(data + length_, |
48 PATH_MAX - length_, | 60 PATH_MAX - length_, |
49 "%s", | 61 "%s", |
50 name); | 62 name); |
51 data[PATH_MAX] = '\0'; | 63 data[PATH_MAX] = '\0'; |
52 if (written <= PATH_MAX - length_ && | 64 if ((written <= PATH_MAX - length_) && |
53 written >= 0 && | 65 (written >= 0) && |
54 static_cast<size_t>(written) == strnlen(name, PATH_MAX + 1)) { | 66 (static_cast<size_t>(written) == strnlen(name, PATH_MAX + 1))) { |
55 length_ += written; | 67 length_ += written; |
56 return true; | 68 return true; |
57 } else { | 69 } else { |
58 errno = ENAMETOOLONG; | 70 errno = ENAMETOOLONG; |
59 return false; | 71 return false; |
60 } | 72 } |
61 } | 73 } |
62 | 74 |
63 void PathBuffer::Reset(int new_length) { | 75 |
| 76 void PathBuffer::Reset(intptr_t new_length) { |
64 length_ = new_length; | 77 length_ = new_length; |
65 AsString()[length_] = '\0'; | 78 AsString()[length_] = '\0'; |
66 } | 79 } |
67 | 80 |
68 | 81 |
69 // A linked list of symbolic links, with their unique file system identifiers. | 82 // A linked list of symbolic links, with their unique file system identifiers. |
70 // These are scanned to detect loops while doing a recursive directory listing. | 83 // These are scanned to detect loops while doing a recursive directory listing. |
71 struct LinkList { | 84 struct LinkList { |
72 dev_t dev; | 85 dev_t dev; |
73 ino_t ino; | 86 ino_t ino; |
74 LinkList* next; | 87 LinkList* next; |
75 }; | 88 }; |
76 | 89 |
77 | 90 |
78 ListType DirectoryListingEntry::Next(DirectoryListing* listing) { | 91 ListType DirectoryListingEntry::Next(DirectoryListing* listing) { |
79 if (done_) { | 92 if (done_) { |
80 return kListDone; | 93 return kListDone; |
81 } | 94 } |
82 | 95 |
83 if (lister_ == 0) { | 96 if (lister_ == 0) { |
84 do { | 97 do { |
85 lister_ = reinterpret_cast<intptr_t>( | 98 lister_ = reinterpret_cast<intptr_t>( |
86 opendir(listing->path_buffer().AsString())); | 99 opendir(listing->path_buffer().AsString())); |
87 } while (lister_ == 0 && errno == EINTR); | 100 } while ((lister_ == 0) && (errno == EINTR)); |
88 | 101 |
89 if (lister_ == 0) { | 102 if (lister_ == 0) { |
90 done_ = true; | 103 done_ = true; |
91 return kListError; | 104 return kListError; |
92 } | 105 } |
93 if (parent_ != NULL) { | 106 if (parent_ != NULL) { |
94 if (!listing->path_buffer().Add(File::PathSeparator())) { | 107 if (!listing->path_buffer().Add(File::PathSeparator())) { |
95 return kListError; | 108 return kListError; |
96 } | 109 } |
97 } | 110 } |
98 path_length_ = listing->path_buffer().length(); | 111 path_length_ = listing->path_buffer().length(); |
99 } | 112 } |
100 // Reset. | 113 // Reset. |
101 listing->path_buffer().Reset(path_length_); | 114 listing->path_buffer().Reset(path_length_); |
102 ResetLink(); | 115 ResetLink(); |
103 | 116 |
104 // Iterate the directory and post the directories and files to the | 117 // Iterate the directory and post the directories and files to the |
105 // ports. | 118 // ports. |
106 int status = 0; | 119 int status = 0; |
107 dirent entry; | 120 dirent entry; |
108 dirent* result; | 121 dirent* result; |
109 if ((status = NO_RETRY_EXPECTED(readdir_r(reinterpret_cast<DIR*>(lister_), | 122 status = NO_RETRY_EXPECTED(readdir_r( |
110 &entry, | 123 reinterpret_cast<DIR*>(lister_), &entry, &result)); |
111 &result))) == 0 && | 124 if ((status == 0) && (result != NULL)) { |
112 result != NULL) { | |
113 if (!listing->path_buffer().Add(entry.d_name)) { | 125 if (!listing->path_buffer().Add(entry.d_name)) { |
114 done_ = true; | 126 done_ = true; |
115 return kListError; | 127 return kListError; |
116 } | 128 } |
117 switch (entry.d_type) { | 129 switch (entry.d_type) { |
118 case DT_DIR: | 130 case DT_DIR: |
119 if (strcmp(entry.d_name, ".") == 0) return Next(listing); | 131 if ((strcmp(entry.d_name, ".") == 0) || |
120 if (strcmp(entry.d_name, "..") == 0) return Next(listing); | 132 (strcmp(entry.d_name, "..") == 0)) { |
| 133 return Next(listing); |
| 134 } |
121 return kListDirectory; | 135 return kListDirectory; |
122 case DT_REG: | 136 case DT_REG: |
123 return kListFile; | 137 return kListFile; |
124 case DT_LNK: | 138 case DT_LNK: |
125 if (!listing->follow_links()) { | 139 if (!listing->follow_links()) { |
126 return kListLink; | 140 return kListLink; |
127 } | 141 } |
128 // Else fall through to next case. | 142 // Else fall through to next case. |
129 // Fall through. | 143 // Fall through. |
130 case DT_UNKNOWN: { | 144 case DT_UNKNOWN: { |
131 // On some file systems the entry type is not determined by | 145 // On some file systems the entry type is not determined by |
132 // readdir_r. For those and for links we use stat to determine | 146 // readdir_r. For those and for links we use stat to determine |
133 // the actual entry type. Notice that stat returns the type of | 147 // the actual entry type. Notice that stat returns the type of |
134 // the file pointed to. | 148 // the file pointed to. |
135 struct stat entry_info; | 149 struct stat entry_info; |
136 int stat_success; | 150 int stat_success; |
137 stat_success = NO_RETRY_EXPECTED( | 151 stat_success = NO_RETRY_EXPECTED( |
138 lstat(listing->path_buffer().AsString(), &entry_info)); | 152 lstat(listing->path_buffer().AsString(), &entry_info)); |
139 if (stat_success == -1) { | 153 if (stat_success == -1) { |
140 return kListError; | 154 return kListError; |
141 } | 155 } |
142 if (listing->follow_links() && S_ISLNK(entry_info.st_mode)) { | 156 if (listing->follow_links() && S_ISLNK(entry_info.st_mode)) { |
143 // Check to see if we are in a loop created by a symbolic link. | 157 // Check to see if we are in a loop created by a symbolic link. |
144 LinkList current_link = { entry_info.st_dev, | 158 LinkList current_link = { entry_info.st_dev, |
145 entry_info.st_ino, | 159 entry_info.st_ino, |
146 link_ }; | 160 link_ }; |
147 LinkList* previous = link_; | 161 LinkList* previous = link_; |
148 while (previous != NULL) { | 162 while (previous != NULL) { |
149 if (previous->dev == current_link.dev && | 163 if ((previous->dev == current_link.dev) && |
150 previous->ino == current_link.ino) { | 164 (previous->ino == current_link.ino)) { |
151 // Report the looping link as a link, rather than following it. | 165 // Report the looping link as a link, rather than following it. |
152 return kListLink; | 166 return kListLink; |
153 } | 167 } |
154 previous = previous->next; | 168 previous = previous->next; |
155 } | 169 } |
156 stat_success = NO_RETRY_EXPECTED( | 170 stat_success = NO_RETRY_EXPECTED( |
157 stat(listing->path_buffer().AsString(), &entry_info)); | 171 stat(listing->path_buffer().AsString(), &entry_info)); |
158 if (stat_success == -1) { | 172 if (stat_success == -1) { |
159 // Report a broken link as a link, even if follow_links is true. | 173 // Report a broken link as a link, even if follow_links is true. |
160 return kListLink; | 174 return kListLink; |
161 } | 175 } |
162 if (S_ISDIR(entry_info.st_mode)) { | 176 if (S_ISDIR(entry_info.st_mode)) { |
163 // Recurse into the subdirectory with current_link added to the | 177 // Recurse into the subdirectory with current_link added to the |
164 // linked list of seen file system links. | 178 // linked list of seen file system links. |
165 link_ = new LinkList(current_link); | 179 link_ = new LinkList(current_link); |
166 if (strcmp(entry.d_name, ".") == 0) return Next(listing); | 180 if ((strcmp(entry.d_name, ".") == 0) || |
167 if (strcmp(entry.d_name, "..") == 0) return Next(listing); | 181 (strcmp(entry.d_name, "..") == 0)) { |
| 182 return Next(listing); |
| 183 } |
168 return kListDirectory; | 184 return kListDirectory; |
169 } | 185 } |
170 } | 186 } |
171 if (S_ISDIR(entry_info.st_mode)) { | 187 if (S_ISDIR(entry_info.st_mode)) { |
172 if (strcmp(entry.d_name, ".") == 0) return Next(listing); | 188 if ((strcmp(entry.d_name, ".") == 0) || |
173 if (strcmp(entry.d_name, "..") == 0) return Next(listing); | 189 (strcmp(entry.d_name, "..") == 0)) { |
| 190 return Next(listing); |
| 191 } |
174 return kListDirectory; | 192 return kListDirectory; |
175 } else if (S_ISREG(entry_info.st_mode)) { | 193 } else if (S_ISREG(entry_info.st_mode)) { |
176 return kListFile; | 194 return kListFile; |
177 } else if (S_ISLNK(entry_info.st_mode)) { | 195 } else if (S_ISLNK(entry_info.st_mode)) { |
178 return kListLink; | 196 return kListLink; |
179 } | 197 } |
180 } | 198 } |
181 | 199 |
182 default: | 200 default: |
183 break; | 201 break; |
(...skipping 12 matching lines...) Expand all Loading... |
196 | 214 |
197 DirectoryListingEntry::~DirectoryListingEntry() { | 215 DirectoryListingEntry::~DirectoryListingEntry() { |
198 ResetLink(); | 216 ResetLink(); |
199 if (lister_ != 0) { | 217 if (lister_ != 0) { |
200 closedir(reinterpret_cast<DIR*>(lister_)); | 218 closedir(reinterpret_cast<DIR*>(lister_)); |
201 } | 219 } |
202 } | 220 } |
203 | 221 |
204 | 222 |
205 void DirectoryListingEntry::ResetLink() { | 223 void DirectoryListingEntry::ResetLink() { |
206 if (link_ != NULL && (parent_ == NULL || parent_->link_ != link_)) { | 224 if ((link_ != NULL) && ((parent_ == NULL) || (parent_->link_ != link_))) { |
207 delete link_; | 225 delete link_; |
208 link_ = NULL; | 226 link_ = NULL; |
209 } | 227 } |
210 if (parent_ != NULL) { | 228 if (parent_ != NULL) { |
211 link_ = parent_->link_; | 229 link_ = parent_->link_; |
212 } | 230 } |
213 } | 231 } |
214 | 232 |
215 | 233 |
216 static bool DeleteRecursively(PathBuffer* path); | 234 static bool DeleteRecursively(PathBuffer* path); |
217 | 235 |
218 | 236 |
219 static bool DeleteFile(char* file_name, | 237 static bool DeleteFile(char* file_name, |
220 PathBuffer* path) { | 238 PathBuffer* path) { |
221 return path->Add(file_name) && unlink(path->AsString()) == 0; | 239 return path->Add(file_name) && (unlink(path->AsString()) == 0); |
222 } | 240 } |
223 | 241 |
224 | 242 |
225 static bool DeleteDir(char* dir_name, | 243 static bool DeleteDir(char* dir_name, |
226 PathBuffer* path) { | 244 PathBuffer* path) { |
227 if (strcmp(dir_name, ".") == 0) return true; | 245 if ((strcmp(dir_name, ".") == 0) || (strcmp(dir_name, "..") == 0)) { |
228 if (strcmp(dir_name, "..") == 0) return true; | 246 return true; |
| 247 } |
229 return path->Add(dir_name) && DeleteRecursively(path); | 248 return path->Add(dir_name) && DeleteRecursively(path); |
230 } | 249 } |
231 | 250 |
232 | 251 |
233 static bool DeleteRecursively(PathBuffer* path) { | 252 static bool DeleteRecursively(PathBuffer* path) { |
234 // Do not recurse into links for deletion. Instead delete the link. | 253 // Do not recurse into links for deletion. Instead delete the link. |
235 // If it's a file, delete it. | 254 // If it's a file, delete it. |
236 struct stat st; | 255 struct stat st; |
237 if (NO_RETRY_EXPECTED(lstat(path->AsString(), &st)) == -1) { | 256 if (NO_RETRY_EXPECTED(lstat(path->AsString(), &st)) == -1) { |
238 return false; | 257 return false; |
239 } else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { | 258 } else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { |
240 return (unlink(path->AsString()) == 0); | 259 return (unlink(path->AsString()) == 0); |
241 } | 260 } |
242 | 261 |
243 if (!path->Add(File::PathSeparator())) return false; | 262 if (!path->Add(File::PathSeparator())) { |
| 263 return false; |
| 264 } |
244 | 265 |
245 // Not a link. Attempt to open as a directory and recurse into the | 266 // Not a link. Attempt to open as a directory and recurse into the |
246 // directory. | 267 // directory. |
247 DIR* dir_pointer; | 268 DIR* dir_pointer; |
248 do { | 269 do { |
249 dir_pointer = opendir(path->AsString()); | 270 dir_pointer = opendir(path->AsString()); |
250 } while (dir_pointer == NULL && errno == EINTR); | 271 } while ((dir_pointer == NULL) && (errno == EINTR)); |
251 if (dir_pointer == NULL) { | 272 if (dir_pointer == NULL) { |
252 return false; | 273 return false; |
253 } | 274 } |
254 | 275 |
255 // Iterate the directory and delete all files and directories. | 276 // Iterate the directory and delete all files and directories. |
256 int path_length = path->length(); | 277 int path_length = path->length(); |
257 dirent entry; | 278 dirent entry; |
258 dirent* result; | 279 dirent* result; |
259 while (NO_RETRY_EXPECTED(readdir_r(dir_pointer, &entry, &result)) == 0) { | 280 while (NO_RETRY_EXPECTED(readdir_r(dir_pointer, &entry, &result)) == 0) { |
260 if (result == NULL) { | 281 if (result == NULL) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 Directory::ExistsResult Directory::Exists(const char* dir_name) { | 337 Directory::ExistsResult Directory::Exists(const char* dir_name) { |
317 struct stat entry_info; | 338 struct stat entry_info; |
318 int success = NO_RETRY_EXPECTED(stat(dir_name, &entry_info)); | 339 int success = NO_RETRY_EXPECTED(stat(dir_name, &entry_info)); |
319 if (success == 0) { | 340 if (success == 0) { |
320 if (S_ISDIR(entry_info.st_mode)) { | 341 if (S_ISDIR(entry_info.st_mode)) { |
321 return EXISTS; | 342 return EXISTS; |
322 } else { | 343 } else { |
323 return DOES_NOT_EXIST; | 344 return DOES_NOT_EXIST; |
324 } | 345 } |
325 } else { | 346 } else { |
326 if (errno == EACCES || | 347 if ((errno == EACCES) || |
327 errno == EBADF || | 348 (errno == EBADF) || |
328 errno == EFAULT || | 349 (errno == EFAULT) || |
329 errno == ENOMEM || | 350 (errno == ENOMEM) || |
330 errno == EOVERFLOW) { | 351 (errno == EOVERFLOW)) { |
331 // Search permissions denied for one of the directories in the | 352 // Search permissions denied for one of the directories in the |
332 // path or a low level error occured. We do not know if the | 353 // path or a low level error occured. We do not know if the |
333 // directory exists. | 354 // directory exists. |
334 return UNKNOWN; | 355 return UNKNOWN; |
335 } | 356 } |
336 ASSERT(errno == ELOOP || | 357 ASSERT((errno == ELOOP) || |
337 errno == ENAMETOOLONG || | 358 (errno == ENAMETOOLONG) || |
338 errno == ENOENT || | 359 (errno == ENOENT) || |
339 errno == ENOTDIR); | 360 (errno == ENOTDIR)); |
340 return DOES_NOT_EXIST; | 361 return DOES_NOT_EXIST; |
341 } | 362 } |
342 } | 363 } |
343 | 364 |
344 | 365 |
345 char* Directory::Current() { | 366 char* Directory::CurrentNoScope() { |
346 // Android's getcwd adheres closely to the POSIX standard. It won't | 367 // Android's getcwd adheres closely to the POSIX standard. It won't |
347 // allocate memory. We need to make our own copy. | 368 // allocate memory. We need to make our own copy. |
348 | 369 |
349 char buffer[PATH_MAX]; | 370 char buffer[PATH_MAX]; |
350 if (NULL == getcwd(buffer, PATH_MAX)) { | 371 if (NULL == getcwd(buffer, PATH_MAX)) { |
351 return NULL; | 372 return NULL; |
352 } | 373 } |
353 | 374 |
354 return strdup(buffer); | 375 return strdup(buffer); |
355 } | 376 } |
356 | 377 |
357 | 378 |
| 379 const char* Directory::Current() { |
| 380 char* result = DartUtils::ScopedCString(PATH_MAX); |
| 381 ASSERT(result != NULL); |
| 382 return getcwd(result, PATH_MAX); |
| 383 } |
| 384 |
| 385 |
358 bool Directory::SetCurrent(const char* path) { | 386 bool Directory::SetCurrent(const char* path) { |
359 int result = NO_RETRY_EXPECTED(chdir(path)); | 387 int result = NO_RETRY_EXPECTED(chdir(path)); |
360 return result == 0; | 388 return result == 0; |
361 } | 389 } |
362 | 390 |
363 | 391 |
364 bool Directory::Create(const char* dir_name) { | 392 bool Directory::Create(const char* dir_name) { |
365 // Create the directory with the permissions specified by the | 393 // Create the directory with the permissions specified by the |
366 // process umask. | 394 // process umask. |
367 int result = NO_RETRY_EXPECTED(mkdir(dir_name, 0777)); | 395 int result = NO_RETRY_EXPECTED(mkdir(dir_name, 0777)); |
368 // If the directory already exists, treat it as a success. | 396 // If the directory already exists, treat it as a success. |
369 if (result == -1 && errno == EEXIST) { | 397 if ((result == -1) && (errno == EEXIST)) { |
370 return (Exists(dir_name) == EXISTS); | 398 return (Exists(dir_name) == EXISTS); |
371 } | 399 } |
372 return (result == 0); | 400 return (result == 0); |
373 } | 401 } |
374 | 402 |
375 | 403 |
376 char* Directory::SystemTemp() { | 404 const char* Directory::SystemTemp() { |
377 // Android does not have a /tmp directory. A partial substitute, | 405 // Android does not have a /tmp directory. A partial substitute, |
378 // suitable for bring-up work and tests, is to create a tmp | 406 // suitable for bring-up work and tests, is to create a tmp |
379 // directory in /data/local/tmp. | 407 // directory in /data/local/tmp. |
380 // | 408 // |
381 // TODO(4413): In the long run, when running in an application we should | 409 // TODO(4413): In the long run, when running in an application we should |
382 // probably use the appropriate directory from the Android API, | 410 // probably use the appropriate directory from the Android API, |
383 // probably what File.createTempFile uses. | 411 // probably what File.createTempFile uses. |
384 #define ANDROID_TEMP_DIR "/data/local/tmp" | 412 #define ANDROID_TEMP_DIR "/data/local/tmp" |
385 struct stat st; | 413 struct stat st; |
386 if (stat(ANDROID_TEMP_DIR, &st) != 0) { | 414 if (stat(ANDROID_TEMP_DIR, &st) != 0) { |
387 mkdir(ANDROID_TEMP_DIR, 0777); | 415 mkdir(ANDROID_TEMP_DIR, 0777); |
388 } | 416 } |
389 return strdup(ANDROID_TEMP_DIR); | 417 return ANDROID_TEMP_DIR; |
390 } | 418 } |
391 | 419 |
392 | 420 |
393 char* Directory::CreateTemp(const char* prefix) { | 421 const char* Directory::CreateTemp(const char* prefix) { |
394 // Returns a new, unused directory name, adding characters to the end | 422 // Returns a new, unused directory name, adding characters to the end |
395 // of prefix. Creates the directory with the permissions specified | 423 // of prefix. Creates the directory with the permissions specified |
396 // by the process umask. | 424 // by the process umask. |
397 // The return value must be freed by the caller. | 425 // The return value is Dart_ScopeAllocated. |
398 PathBuffer path; | 426 PathBuffer path; |
399 path.Add(prefix); | 427 if (!path.Add(prefix)) { |
| 428 return NULL; |
| 429 } |
400 if (!path.Add("XXXXXX")) { | 430 if (!path.Add("XXXXXX")) { |
401 // Pattern has overflowed. | 431 // Pattern has overflowed. |
402 return NULL; | 432 return NULL; |
403 } | 433 } |
404 char* result; | 434 char* result; |
405 do { | 435 do { |
406 result = mkdtemp(path.AsString()); | 436 result = mkdtemp(path.AsString()); |
407 } while (result == NULL && errno == EINTR); | 437 } while ((result == NULL) && (errno == EINTR)); |
408 if (result == NULL) { | 438 if (result == NULL) { |
409 return NULL; | 439 return NULL; |
410 } | 440 } |
411 return strdup(result); | 441 return path.AsScopedString(); |
412 } | 442 } |
413 | 443 |
414 | 444 |
415 bool Directory::Delete(const char* dir_name, bool recursive) { | 445 bool Directory::Delete(const char* dir_name, bool recursive) { |
416 if (!recursive) { | 446 if (!recursive) { |
417 if (File::GetType(dir_name, false) == File::kIsLink && | 447 if ((File::GetType(dir_name, false) == File::kIsLink) && |
418 File::GetType(dir_name, true) == File::kIsDirectory) { | 448 (File::GetType(dir_name, true) == File::kIsDirectory)) { |
419 return (NO_RETRY_EXPECTED(unlink(dir_name)) == 0); | 449 return (NO_RETRY_EXPECTED(unlink(dir_name)) == 0); |
420 } | 450 } |
421 return (NO_RETRY_EXPECTED(rmdir(dir_name)) == 0); | 451 return (NO_RETRY_EXPECTED(rmdir(dir_name)) == 0); |
422 } else { | 452 } else { |
423 PathBuffer path; | 453 PathBuffer path; |
424 if (!path.Add(dir_name)) { | 454 if (!path.Add(dir_name)) { |
425 return false; | 455 return false; |
426 } | 456 } |
427 return DeleteRecursively(&path); | 457 return DeleteRecursively(&path); |
428 } | 458 } |
429 } | 459 } |
430 | 460 |
431 | 461 |
432 bool Directory::Rename(const char* path, const char* new_path) { | 462 bool Directory::Rename(const char* path, const char* new_path) { |
433 ExistsResult exists = Exists(path); | 463 ExistsResult exists = Exists(path); |
434 if (exists != EXISTS) return false; | 464 if (exists != EXISTS) { |
| 465 return false; |
| 466 } |
435 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); | 467 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); |
436 } | 468 } |
437 | 469 |
438 } // namespace bin | 470 } // namespace bin |
439 } // namespace dart | 471 } // namespace dart |
440 | 472 |
441 #endif // defined(TARGET_OS_ANDROID) | 473 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |