| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <psapi.h> | 8 #include <psapi.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 *error = LastErrorToPlatformFileError(error_code); | 383 *error = LastErrorToPlatformFileError(error_code); |
| 384 DLOG(WARNING) << "Failed to create directory " << full_path_str | 384 DLOG(WARNING) << "Failed to create directory " << full_path_str |
| 385 << ", last error is " << error_code << "."; | 385 << ", last error is " << error_code << "."; |
| 386 return false; | 386 return false; |
| 387 } | 387 } |
| 388 } else { | 388 } else { |
| 389 return true; | 389 return true; |
| 390 } | 390 } |
| 391 } | 391 } |
| 392 | 392 |
| 393 bool NormalizeFilePath(const FilePath& path, FilePath* real_path) { |
| 394 ThreadRestrictions::AssertIOAllowed(); |
| 395 FilePath mapped_file; |
| 396 if (!NormalizeToNativeFilePath(path, &mapped_file)) |
| 397 return false; |
| 398 // NormalizeToNativeFilePath() will return a path that starts with |
| 399 // "\Device\Harddisk...". Helper DevicePathToDriveLetterPath() |
| 400 // will find a drive letter which maps to the path's device, so |
| 401 // that we return a path starting with a drive letter. |
| 402 return DevicePathToDriveLetterPath(mapped_file, real_path); |
| 403 } |
| 404 |
| 393 } // namespace base | 405 } // namespace base |
| 394 | 406 |
| 395 // ----------------------------------------------------------------------------- | 407 // ----------------------------------------------------------------------------- |
| 396 | 408 |
| 397 namespace file_util { | 409 namespace file_util { |
| 398 | 410 |
| 399 using base::DirectoryExists; | 411 using base::DirectoryExists; |
| 400 using base::FilePath; | 412 using base::FilePath; |
| 401 using base::kFileShareAll; | 413 using base::kFileShareAll; |
| 402 | 414 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 return true; | 552 return true; |
| 541 } | 553 } |
| 542 | 554 |
| 543 // Sets the current working directory for the process. | 555 // Sets the current working directory for the process. |
| 544 bool SetCurrentDirectory(const FilePath& directory) { | 556 bool SetCurrentDirectory(const FilePath& directory) { |
| 545 base::ThreadRestrictions::AssertIOAllowed(); | 557 base::ThreadRestrictions::AssertIOAllowed(); |
| 546 BOOL ret = ::SetCurrentDirectory(directory.value().c_str()); | 558 BOOL ret = ::SetCurrentDirectory(directory.value().c_str()); |
| 547 return ret != 0; | 559 return ret != 0; |
| 548 } | 560 } |
| 549 | 561 |
| 550 bool NormalizeFilePath(const FilePath& path, FilePath* real_path) { | |
| 551 base::ThreadRestrictions::AssertIOAllowed(); | |
| 552 FilePath mapped_file; | |
| 553 if (!NormalizeToNativeFilePath(path, &mapped_file)) | |
| 554 return false; | |
| 555 // NormalizeToNativeFilePath() will return a path that starts with | |
| 556 // "\Device\Harddisk...". Helper DevicePathToDriveLetterPath() | |
| 557 // will find a drive letter which maps to the path's device, so | |
| 558 // that we return a path starting with a drive letter. | |
| 559 return DevicePathToDriveLetterPath(mapped_file, real_path); | |
| 560 } | |
| 561 | |
| 562 bool DevicePathToDriveLetterPath(const FilePath& nt_device_path, | 562 bool DevicePathToDriveLetterPath(const FilePath& nt_device_path, |
| 563 FilePath* out_drive_letter_path) { | 563 FilePath* out_drive_letter_path) { |
| 564 base::ThreadRestrictions::AssertIOAllowed(); | 564 base::ThreadRestrictions::AssertIOAllowed(); |
| 565 | 565 |
| 566 // Get the mapping of drive letters to device paths. | 566 // Get the mapping of drive letters to device paths. |
| 567 const int kDriveMappingSize = 1024; | 567 const int kDriveMappingSize = 1024; |
| 568 wchar_t drive_mapping[kDriveMappingSize] = {'\0'}; | 568 wchar_t drive_mapping[kDriveMappingSize] = {'\0'}; |
| 569 if (!::GetLogicalDriveStrings(kDriveMappingSize - 1, drive_mapping)) { | 569 if (!::GetLogicalDriveStrings(kDriveMappingSize - 1, drive_mapping)) { |
| 570 DLOG(ERROR) << "Failed to get drive mapping."; | 570 DLOG(ERROR) << "Failed to get drive mapping."; |
| 571 return false; | 571 return false; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 // Like Move, this function is not transactional, so we just | 744 // Like Move, this function is not transactional, so we just |
| 745 // leave the copied bits behind if deleting from_path fails. | 745 // leave the copied bits behind if deleting from_path fails. |
| 746 // If to_path exists previously then we have already overwritten | 746 // If to_path exists previously then we have already overwritten |
| 747 // it by now, we don't get better off by deleting the new bits. | 747 // it by now, we don't get better off by deleting the new bits. |
| 748 } | 748 } |
| 749 return false; | 749 return false; |
| 750 } | 750 } |
| 751 | 751 |
| 752 } // namespace internal | 752 } // namespace internal |
| 753 } // namespace base | 753 } // namespace base |
| OLD | NEW |