| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <propvarutil.h> | 8 #include <propvarutil.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 | 532 |
| 533 bool CreateNewTempDirectory(const FilePath::StringType& prefix, | 533 bool CreateNewTempDirectory(const FilePath::StringType& prefix, |
| 534 FilePath* new_temp_path) { | 534 FilePath* new_temp_path) { |
| 535 FilePath system_temp_dir; | 535 FilePath system_temp_dir; |
| 536 if (!GetTempDir(&system_temp_dir)) | 536 if (!GetTempDir(&system_temp_dir)) |
| 537 return false; | 537 return false; |
| 538 | 538 |
| 539 return CreateTemporaryDirInDir(system_temp_dir, prefix, new_temp_path); | 539 return CreateTemporaryDirInDir(system_temp_dir, prefix, new_temp_path); |
| 540 } | 540 } |
| 541 | 541 |
| 542 // TODO(skerner): Extra logging has been added to understand crbug/35198 . |
| 543 // Remove it once we get a log from a user who can reproduce the issue. |
| 542 bool CreateDirectory(const FilePath& full_path) { | 544 bool CreateDirectory(const FilePath& full_path) { |
| 545 LOG(INFO) << "Enter CreateDirectory: full_path = " << full_path.value(); |
| 543 // If the path exists, we've succeeded if it's a directory, failed otherwise. | 546 // If the path exists, we've succeeded if it's a directory, failed otherwise. |
| 544 const wchar_t* full_path_str = full_path.value().c_str(); | 547 const wchar_t* full_path_str = full_path.value().c_str(); |
| 545 DWORD fileattr = ::GetFileAttributes(full_path_str); | 548 DWORD fileattr = ::GetFileAttributes(full_path_str); |
| 549 LOG(INFO) << "::GetFileAttributes() returned " << fileattr; |
| 546 if (fileattr != INVALID_FILE_ATTRIBUTES) { | 550 if (fileattr != INVALID_FILE_ATTRIBUTES) { |
| 547 if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) { | 551 if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) { |
| 548 DLOG(INFO) << "CreateDirectory(" << full_path_str << "), " << | 552 LOG(INFO) << "CreateDirectory(" << full_path_str << "), " << |
| 549 "directory already exists."; | 553 "directory already exists."; |
| 550 return true; | 554 return true; |
| 551 } else { | 555 } else { |
| 552 LOG(WARNING) << "CreateDirectory(" << full_path_str << "), " << | 556 LOG(WARNING) << "CreateDirectory(" << full_path_str << "), " << |
| 553 "conflicts with existing file."; | 557 "conflicts with existing file."; |
| 554 } | 558 } |
| 555 } | 559 } |
| 556 | 560 |
| 557 // Invariant: Path does not exist as file or directory. | 561 // Invariant: Path does not exist as file or directory. |
| 558 | 562 |
| 559 // Attempt to create the parent recursively. This will immediately return | 563 // Attempt to create the parent recursively. This will immediately return |
| 560 // true if it already exists, otherwise will create all required parent | 564 // true if it already exists, otherwise will create all required parent |
| 561 // directories starting with the highest-level missing parent. | 565 // directories starting with the highest-level missing parent. |
| 562 FilePath parent_path(full_path.DirName()); | 566 FilePath parent_path(full_path.DirName()); |
| 563 if (parent_path.value() == full_path.value()) { | 567 if (parent_path.value() == full_path.value()) { |
| 568 LOG(INFO) << "Can't create directory: parent_path " << |
| 569 parent_path.value() << " should not equal full_path " << |
| 570 full_path.value(); |
| 564 return false; | 571 return false; |
| 565 } | 572 } |
| 566 if (!CreateDirectory(parent_path)) { | 573 if (!CreateDirectory(parent_path)) { |
| 567 DLOG(WARNING) << "Failed to create one of the parent directories."; | 574 LOG(INFO) << "Failed to create one of the parent directories: " << |
| 575 parent_path.value(); |
| 568 return false; | 576 return false; |
| 569 } | 577 } |
| 570 | 578 |
| 579 LOG(INFO) << "About to call ::CreateDirectory() with full_path_str = " << |
| 580 full_path_str; |
| 571 if (!::CreateDirectory(full_path_str, NULL)) { | 581 if (!::CreateDirectory(full_path_str, NULL)) { |
| 572 DWORD error_code = ::GetLastError(); | 582 DWORD error_code = ::GetLastError(); |
| 573 if (error_code == ERROR_ALREADY_EXISTS && DirectoryExists(full_path)) { | 583 if (error_code == ERROR_ALREADY_EXISTS && DirectoryExists(full_path)) { |
| 574 // This error code doesn't indicate whether we were racing with someone | 584 // This error code doesn't indicate whether we were racing with someone |
| 575 // creating the same directory, or a file with the same path, therefore | 585 // creating the same directory, or a file with the same path, therefore |
| 576 // we check. | 586 // we check. |
| 587 LOG(INFO) << "Race condition? Directory already exists: " << |
| 588 full_path.value(); |
| 577 return true; | 589 return true; |
| 578 } else { | 590 } else { |
| 579 LOG(WARNING) << "Failed to create directory " << full_path_str << | 591 LOG(WARNING) << "Failed to create directory " << full_path_str << |
| 580 ", le=" << error_code; | 592 ", le=" << error_code; |
| 581 return false; | 593 return false; |
| 582 } | 594 } |
| 583 } else { | 595 } else { |
| 596 LOG(INFO) << "::CreateDirectory() worked."; |
| 584 return true; | 597 return true; |
| 585 } | 598 } |
| 586 } | 599 } |
| 587 | 600 |
| 588 bool GetFileInfo(const FilePath& file_path, FileInfo* results) { | 601 bool GetFileInfo(const FilePath& file_path, FileInfo* results) { |
| 589 WIN32_FILE_ATTRIBUTE_DATA attr; | 602 WIN32_FILE_ATTRIBUTE_DATA attr; |
| 590 if (!GetFileAttributesEx(file_path.ToWStringHack().c_str(), | 603 if (!GetFileAttributesEx(file_path.ToWStringHack().c_str(), |
| 591 GetFileExInfoStandard, &attr)) { | 604 GetFileExInfoStandard, &attr)) { |
| 592 return false; | 605 return false; |
| 593 } | 606 } |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 } | 890 } |
| 878 | 891 |
| 879 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, | 892 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, |
| 880 const base::Time& cutoff_time) { | 893 const base::Time& cutoff_time) { |
| 881 long result = CompareFileTime(&find_info.ftLastWriteTime, | 894 long result = CompareFileTime(&find_info.ftLastWriteTime, |
| 882 &cutoff_time.ToFileTime()); | 895 &cutoff_time.ToFileTime()); |
| 883 return result == 1 || result == 0; | 896 return result == 1 || result == 0; |
| 884 } | 897 } |
| 885 | 898 |
| 886 } // namespace file_util | 899 } // namespace file_util |
| OLD | NEW |