| 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 | 9 |
| 10 #include "bin/log.h" | 10 #include "bin/log.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 wchar_t* current = new wchar_t[length + 1]; | 337 wchar_t* current = new wchar_t[length + 1]; |
| 338 GetCurrentDirectoryW(length + 1, current); | 338 GetCurrentDirectoryW(length + 1, current); |
| 339 char* result = StringUtils::WideToUtf8(current); | 339 char* result = StringUtils::WideToUtf8(current); |
| 340 delete[] current; | 340 delete[] current; |
| 341 return result; | 341 return result; |
| 342 } | 342 } |
| 343 | 343 |
| 344 | 344 |
| 345 bool Directory::Create(const char* dir_name) { | 345 bool Directory::Create(const char* dir_name) { |
| 346 const wchar_t* system_name = StringUtils::Utf8ToWide(dir_name); | 346 const wchar_t* system_name = StringUtils::Utf8ToWide(dir_name); |
| 347 // If the directory already exists and is a directory do not | 347 int create_status = CreateDirectoryW(system_name, NULL); |
| 348 // attempt to create it again and treat it as a success. | 348 // If the directory already existed, treat it as a success. |
| 349 if (ExistsHelper(system_name) == EXISTS) { | 349 if (create_status == 0 && |
| 350 GetLastError() == ERROR_ALREADY_EXISTS && |
| 351 ExistsHelper(system_name) == EXISTS) { |
| 350 free(const_cast<wchar_t*>(system_name)); | 352 free(const_cast<wchar_t*>(system_name)); |
| 351 return true; | 353 return true; |
| 352 } | 354 } |
| 353 int create_status = CreateDirectoryW(system_name, NULL); | |
| 354 free(const_cast<wchar_t*>(system_name)); | 355 free(const_cast<wchar_t*>(system_name)); |
| 355 return (create_status != 0); | 356 return (create_status != 0); |
| 356 } | 357 } |
| 357 | 358 |
| 358 | 359 |
| 359 char* Directory::CreateTemp(const char* const_template) { | 360 char* Directory::CreateTemp(const char* const_template) { |
| 360 // Returns a new, unused directory name, modifying the contents of | 361 // Returns a new, unused directory name, modifying the contents of |
| 361 // dir_template. Creates this directory, with a default security | 362 // dir_template. Creates this directory, with a default security |
| 362 // descriptor inherited from its parent directory. | 363 // descriptor inherited from its parent directory. |
| 363 // The return value must be freed by the caller. | 364 // The return value must be freed by the caller. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 bool success = DeleteRecursively(system_new_path); | 438 bool success = DeleteRecursively(system_new_path); |
| 438 if (!success) return false; | 439 if (!success) return false; |
| 439 } | 440 } |
| 440 DWORD flags = MOVEFILE_WRITE_THROUGH; | 441 DWORD flags = MOVEFILE_WRITE_THROUGH; |
| 441 int move_status = | 442 int move_status = |
| 442 MoveFileExW(system_path, system_new_path, flags); | 443 MoveFileExW(system_path, system_new_path, flags); |
| 443 free(const_cast<wchar_t*>(system_path)); | 444 free(const_cast<wchar_t*>(system_path)); |
| 444 free(const_cast<wchar_t*>(system_new_path)); | 445 free(const_cast<wchar_t*>(system_new_path)); |
| 445 return (move_status != 0); | 446 return (move_status != 0); |
| 446 } | 447 } |
| OLD | NEW |