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 <psapi.h> | 9 #include <psapi.h> |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 | 580 |
581 bool CreateNewTempDirectory(const FilePath::StringType& prefix, | 581 bool CreateNewTempDirectory(const FilePath::StringType& prefix, |
582 FilePath* new_temp_path) { | 582 FilePath* new_temp_path) { |
583 FilePath system_temp_dir; | 583 FilePath system_temp_dir; |
584 if (!GetTempDir(&system_temp_dir)) | 584 if (!GetTempDir(&system_temp_dir)) |
585 return false; | 585 return false; |
586 | 586 |
587 return CreateTemporaryDirInDir(system_temp_dir, prefix, new_temp_path); | 587 return CreateTemporaryDirInDir(system_temp_dir, prefix, new_temp_path); |
588 } | 588 } |
589 | 589 |
| 590 bool CreateDirectory(const FilePath& full_path) { |
| 591 return file_util::CreateDirectoryExtraLogging(full_path, LOG(INFO)); |
| 592 } |
| 593 |
590 // TODO(skerner): Extra logging has been added to understand crbug/35198 . | 594 // TODO(skerner): Extra logging has been added to understand crbug/35198 . |
591 // Remove it once we get a log from a user who can reproduce the issue. | 595 // Remove it once we get a log from a user who can reproduce the issue. |
592 bool CreateDirectory(const FilePath& full_path) { | 596 bool CreateDirectoryExtraLogging(const FilePath& full_path, |
593 LOG(INFO) << "Enter CreateDirectory: full_path = " << full_path.value(); | 597 std::ostream& log) { |
| 598 log << "Enter CreateDirectory: full_path = " << full_path.value() |
| 599 << std::endl; |
594 // If the path exists, we've succeeded if it's a directory, failed otherwise. | 600 // If the path exists, we've succeeded if it's a directory, failed otherwise. |
595 const wchar_t* full_path_str = full_path.value().c_str(); | 601 const wchar_t* full_path_str = full_path.value().c_str(); |
596 DWORD fileattr = ::GetFileAttributes(full_path_str); | 602 DWORD fileattr = ::GetFileAttributes(full_path_str); |
597 LOG(INFO) << "::GetFileAttributes() returned " << fileattr; | 603 log << "::GetFileAttributes() returned " << fileattr << std::endl; |
598 if (fileattr != INVALID_FILE_ATTRIBUTES) { | 604 if (fileattr == INVALID_FILE_ATTRIBUTES) { |
| 605 DWORD fileattr_error = GetLastError(); |
| 606 log << "::GetFileAttributes() failed. GetLastError() = " |
| 607 << fileattr_error << std::endl; |
| 608 } else { |
599 if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) { | 609 if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) { |
600 LOG(INFO) << "CreateDirectory(" << full_path_str << "), " << | 610 log << "CreateDirectory(" << full_path_str << "), " |
601 "directory already exists."; | 611 << "directory already exists." << std::endl; |
602 return true; | 612 return true; |
603 } else { | 613 } else { |
604 LOG(WARNING) << "CreateDirectory(" << full_path_str << "), " << | 614 log << "CreateDirectory(" << full_path_str << "), " |
605 "conflicts with existing file."; | 615 << "conflicts with existing file." << std::endl; |
606 } | 616 } |
607 } | 617 } |
608 | 618 |
609 // Invariant: Path does not exist as file or directory. | 619 // Invariant: Path does not exist as file or directory. |
610 | 620 |
611 // Attempt to create the parent recursively. This will immediately return | 621 // Attempt to create the parent recursively. This will immediately return |
612 // true if it already exists, otherwise will create all required parent | 622 // true if it already exists, otherwise will create all required parent |
613 // directories starting with the highest-level missing parent. | 623 // directories starting with the highest-level missing parent. |
614 FilePath parent_path(full_path.DirName()); | 624 FilePath parent_path(full_path.DirName()); |
615 if (parent_path.value() == full_path.value()) { | 625 if (parent_path.value() == full_path.value()) { |
616 LOG(INFO) << "Can't create directory: parent_path " << | 626 log << "Can't create directory: parent_path " << parent_path.value() |
617 parent_path.value() << " should not equal full_path " << | 627 << " should not equal full_path " << full_path.value() |
618 full_path.value(); | 628 << std::endl; |
619 return false; | 629 return false; |
620 } | 630 } |
621 if (!CreateDirectory(parent_path)) { | 631 if (!CreateDirectory(parent_path)) { |
622 LOG(INFO) << "Failed to create one of the parent directories: " << | 632 log << "Failed to create one of the parent directories: " |
623 parent_path.value(); | 633 << parent_path.value() << std::endl; |
624 return false; | 634 return false; |
625 } | 635 } |
626 | 636 |
627 LOG(INFO) << "About to call ::CreateDirectory() with full_path_str = " << | 637 log << "About to call ::CreateDirectory() with full_path_str = " |
628 full_path_str; | 638 << full_path_str << std::endl; |
629 if (!::CreateDirectory(full_path_str, NULL)) { | 639 if (!::CreateDirectory(full_path_str, NULL)) { |
630 DWORD error_code = ::GetLastError(); | 640 DWORD error_code = ::GetLastError(); |
| 641 log << "CreateDirectory() gave last error " << error_code << std::endl; |
| 642 |
| 643 DWORD fileattr = GetFileAttributes(full_path.value().c_str()); |
| 644 if (fileattr == INVALID_FILE_ATTRIBUTES) { |
| 645 DWORD fileattr_error = ::GetLastError(); |
| 646 log << "GetFileAttributes() failed, GetLastError() = " |
| 647 << fileattr_error << std::endl; |
| 648 } else { |
| 649 log << "GetFileAttributes() returned " << fileattr << std::endl; |
| 650 log << "Is the path a directory: " |
| 651 << ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) << std::endl; |
| 652 } |
631 if (error_code == ERROR_ALREADY_EXISTS && DirectoryExists(full_path)) { | 653 if (error_code == ERROR_ALREADY_EXISTS && DirectoryExists(full_path)) { |
632 // This error code doesn't indicate whether we were racing with someone | 654 // This error code doesn't indicate whether we were racing with someone |
633 // creating the same directory, or a file with the same path, therefore | 655 // creating the same directory, or a file with the same path, therefore |
634 // we check. | 656 // we check. |
635 LOG(INFO) << "Race condition? Directory already exists: " << | 657 log << "Race condition? Directory already exists: " |
636 full_path.value(); | 658 << full_path.value() << std::endl; |
637 return true; | 659 return true; |
638 } else { | 660 } else { |
639 LOG(WARNING) << "Failed to create directory " << full_path_str << | 661 DWORD dir_exists_error = ::GetLastError(); |
640 ", le=" << error_code; | 662 log << "Failed to create directory " << full_path_str << std::endl; |
| 663 log << "GetLastError() for DirectoryExists() is " |
| 664 << dir_exists_error << std::endl; |
641 return false; | 665 return false; |
642 } | 666 } |
643 } else { | 667 } else { |
644 LOG(INFO) << "::CreateDirectory() worked."; | 668 log << "::CreateDirectory() succeeded." << std::endl; |
645 return true; | 669 return true; |
646 } | 670 } |
647 } | 671 } |
648 | 672 |
649 bool GetFileInfo(const FilePath& file_path, FileInfo* results) { | 673 bool GetFileInfo(const FilePath& file_path, FileInfo* results) { |
650 WIN32_FILE_ATTRIBUTE_DATA attr; | 674 WIN32_FILE_ATTRIBUTE_DATA attr; |
651 if (!GetFileAttributesEx(file_path.value().c_str(), | 675 if (!GetFileAttributesEx(file_path.value().c_str(), |
652 GetFileExInfoStandard, &attr)) { | 676 GetFileExInfoStandard, &attr)) { |
653 return false; | 677 return false; |
654 } | 678 } |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 // will find a drive letter which maps to the path's device, so | 1027 // will find a drive letter which maps to the path's device, so |
1004 // that we return a path starting with a drive letter. | 1028 // that we return a path starting with a drive letter. |
1005 FilePath mapped_file(mapped_file_path); | 1029 FilePath mapped_file(mapped_file_path); |
1006 success = DevicePathToDriveLetterPath(mapped_file, real_path); | 1030 success = DevicePathToDriveLetterPath(mapped_file, real_path); |
1007 } | 1031 } |
1008 UnmapViewOfFile(file_view); | 1032 UnmapViewOfFile(file_view); |
1009 return success; | 1033 return success; |
1010 } | 1034 } |
1011 | 1035 |
1012 } // namespace file_util | 1036 } // namespace file_util |
OLD | NEW |