| 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 | 376 |
| 377 | 377 |
| 378 char* Directory::Current() { | 378 char* Directory::Current() { |
| 379 return getcwd(NULL, 0); | 379 return getcwd(NULL, 0); |
| 380 } | 380 } |
| 381 | 381 |
| 382 | 382 |
| 383 bool Directory::Create(const char* dir_name) { | 383 bool Directory::Create(const char* dir_name) { |
| 384 // If the directory already exists and is a directory do not | |
| 385 // attempt to create it again and treat it as a success. | |
| 386 if (Exists(dir_name) == EXISTS) return true; | |
| 387 // Create the directory with the permissions specified by the | 384 // Create the directory with the permissions specified by the |
| 388 // process umask. | 385 // process umask. |
| 389 return (TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)) == 0); | 386 int result = TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)); |
| 387 // If the directory already exists, treat it as a success. |
| 388 if (result == -1 && errno == EEXIST) { |
| 389 return (Exists(dir_name) == EXISTS); |
| 390 } |
| 391 return (result == 0); |
| 390 } | 392 } |
| 391 | 393 |
| 392 | 394 |
| 393 char* Directory::CreateTemp(const char* const_template) { | 395 char* Directory::CreateTemp(const char* const_template) { |
| 394 // Returns a new, unused directory name, modifying the contents of | 396 // Returns a new, unused directory name, modifying the contents of |
| 395 // dir_template. Creates the directory with the permissions specified | 397 // dir_template. Creates the directory with the permissions specified |
| 396 // by the process umask. | 398 // by the process umask. |
| 397 // The return value must be freed by the caller. | 399 // The return value must be freed by the caller. |
| 398 char* path = static_cast<char*>(malloc(PATH_MAX + 1)); | 400 char* path = static_cast<char*>(malloc(PATH_MAX + 1)); |
| 399 SafeStrNCpy(path, const_template, PATH_MAX + 1); | 401 SafeStrNCpy(path, const_template, PATH_MAX + 1); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 426 return DeleteRecursively(dir_name); | 428 return DeleteRecursively(dir_name); |
| 427 } | 429 } |
| 428 } | 430 } |
| 429 | 431 |
| 430 | 432 |
| 431 bool Directory::Rename(const char* path, const char* new_path) { | 433 bool Directory::Rename(const char* path, const char* new_path) { |
| 432 ExistsResult exists = Exists(path); | 434 ExistsResult exists = Exists(path); |
| 433 if (exists != EXISTS) return false; | 435 if (exists != EXISTS) return false; |
| 434 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); | 436 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); |
| 435 } | 437 } |
| OLD | NEW |