| 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 "bin/directory.h" | 5 #include "bin/directory.h" |
| 6 | 6 |
| 7 #include <dirent.h> | 7 #include <dirent.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <sys/param.h> | 9 #include <sys/param.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 return NULL; | 384 return NULL; |
| 385 } | 385 } |
| 386 | 386 |
| 387 return strdup(buffer); | 387 return strdup(buffer); |
| 388 } | 388 } |
| 389 | 389 |
| 390 | 390 |
| 391 bool Directory::Create(const char* dir_name) { | 391 bool Directory::Create(const char* dir_name) { |
| 392 // Create the directory with the permissions specified by the | 392 // Create the directory with the permissions specified by the |
| 393 // process umask. | 393 // process umask. |
| 394 return (TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)) == 0); | 394 int result = TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)); |
| 395 // If the directory already exists, treat it as a success. |
| 396 if (result == -1 && errno == EEXISTS) { |
| 397 return (Exists(dir_name) == EXISTS); |
| 398 } |
| 399 return (result == 0); |
| 395 } | 400 } |
| 396 | 401 |
| 397 | 402 |
| 398 // Android doesn't currently provide mkdtemp. Once Android provied mkdtemp, | 403 // Android doesn't currently provide mkdtemp. Once Android provied mkdtemp, |
| 399 // remove this function in favor of calling mkdtemp directly. | 404 // remove this function in favor of calling mkdtemp directly. |
| 400 static char* MakeTempDirectory(char* path_template) { | 405 static char* MakeTempDirectory(char* path_template) { |
| 401 if (mktemp(path_template) == NULL) { | 406 if (mktemp(path_template) == NULL) { |
| 402 return NULL; | 407 return NULL; |
| 403 } | 408 } |
| 404 if (mkdir(path_template, 0700) != 0) { | 409 if (mkdir(path_template, 0700) != 0) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 return DeleteRecursively(dir_name); | 460 return DeleteRecursively(dir_name); |
| 456 } | 461 } |
| 457 } | 462 } |
| 458 | 463 |
| 459 | 464 |
| 460 bool Directory::Rename(const char* path, const char* new_path) { | 465 bool Directory::Rename(const char* path, const char* new_path) { |
| 461 ExistsResult exists = Exists(path); | 466 ExistsResult exists = Exists(path); |
| 462 if (exists != EXISTS) return false; | 467 if (exists != EXISTS) return false; |
| 463 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); | 468 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); |
| 464 } | 469 } |
| OLD | NEW |