| 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/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #include <psapi.h> | 9 #include <psapi.h> |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 if (recursive && (!DeleteFileRecursive(current, pattern, true) || | 63 if (recursive && (!DeleteFileRecursive(current, pattern, true) || |
| 64 !RemoveDirectory(current.value().c_str()))) | 64 !RemoveDirectory(current.value().c_str()))) |
| 65 return false; | 65 return false; |
| 66 } else if (!::DeleteFile(current.value().c_str())) { | 66 } else if (!::DeleteFile(current.value().c_str())) { |
| 67 return false; | 67 return false; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Appends |mode_char| to |mode| before the optional character set encoding; see |
| 74 // https://msdn.microsoft.com/library/yeby3zcb.aspx for details. |
| 75 void AppendModeCharacter(base::char16 mode_char, base::string16* mode) { |
| 76 size_t comma_pos = mode->find(L','); |
| 77 mode->insert(comma_pos == base::string16::npos ? mode->length() : comma_pos, |
| 78 1, mode_char); |
| 79 } |
| 80 |
| 73 } // namespace | 81 } // namespace |
| 74 | 82 |
| 75 FilePath MakeAbsoluteFilePath(const FilePath& input) { | 83 FilePath MakeAbsoluteFilePath(const FilePath& input) { |
| 76 ThreadRestrictions::AssertIOAllowed(); | 84 ThreadRestrictions::AssertIOAllowed(); |
| 77 wchar_t file_path[MAX_PATH]; | 85 wchar_t file_path[MAX_PATH]; |
| 78 if (!_wfullpath(file_path, input.value().c_str(), MAX_PATH)) | 86 if (!_wfullpath(file_path, input.value().c_str(), MAX_PATH)) |
| 79 return FilePath(); | 87 return FilePath(); |
| 80 return FilePath(file_path); | 88 return FilePath(file_path); |
| 81 } | 89 } |
| 82 | 90 |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 results->is_directory = | 595 results->is_directory = |
| 588 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | 596 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
| 589 results->last_modified = Time::FromFileTime(attr.ftLastWriteTime); | 597 results->last_modified = Time::FromFileTime(attr.ftLastWriteTime); |
| 590 results->last_accessed = Time::FromFileTime(attr.ftLastAccessTime); | 598 results->last_accessed = Time::FromFileTime(attr.ftLastAccessTime); |
| 591 results->creation_time = Time::FromFileTime(attr.ftCreationTime); | 599 results->creation_time = Time::FromFileTime(attr.ftCreationTime); |
| 592 | 600 |
| 593 return true; | 601 return true; |
| 594 } | 602 } |
| 595 | 603 |
| 596 FILE* OpenFile(const FilePath& filename, const char* mode) { | 604 FILE* OpenFile(const FilePath& filename, const char* mode) { |
| 605 // 'N' is unconditionally added below, so be sure there is not one already |
| 606 // present before a comma in |mode|. |
| 607 DCHECK( |
| 608 strchr(mode, 'N') == nullptr || |
| 609 (strchr(mode, ',') != nullptr && strchr(mode, 'N') > strchr(mode, ','))); |
| 597 ThreadRestrictions::AssertIOAllowed(); | 610 ThreadRestrictions::AssertIOAllowed(); |
| 598 string16 w_mode = ASCIIToUTF16(mode); | 611 string16 w_mode = ASCIIToUTF16(mode); |
| 612 AppendModeCharacter(L'N', &w_mode); |
| 599 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); | 613 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); |
| 600 } | 614 } |
| 601 | 615 |
| 602 FILE* FileToFILE(File file, const char* mode) { | 616 FILE* FileToFILE(File file, const char* mode) { |
| 603 if (!file.IsValid()) | 617 if (!file.IsValid()) |
| 604 return NULL; | 618 return NULL; |
| 605 int fd = | 619 int fd = |
| 606 _open_osfhandle(reinterpret_cast<intptr_t>(file.GetPlatformFile()), 0); | 620 _open_osfhandle(reinterpret_cast<intptr_t>(file.GetPlatformFile()), 0); |
| 607 if (fd < 0) | 621 if (fd < 0) |
| 608 return NULL; | 622 return NULL; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 // Like Move, this function is not transactional, so we just | 842 // Like Move, this function is not transactional, so we just |
| 829 // leave the copied bits behind if deleting from_path fails. | 843 // leave the copied bits behind if deleting from_path fails. |
| 830 // If to_path exists previously then we have already overwritten | 844 // If to_path exists previously then we have already overwritten |
| 831 // it by now, we don't get better off by deleting the new bits. | 845 // it by now, we don't get better off by deleting the new bits. |
| 832 } | 846 } |
| 833 return false; | 847 return false; |
| 834 } | 848 } |
| 835 | 849 |
| 836 } // namespace internal | 850 } // namespace internal |
| 837 } // namespace base | 851 } // namespace base |
| OLD | NEW |