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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 results->is_directory = | 587 results->is_directory = |
580 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | 588 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
581 results->last_modified = Time::FromFileTime(attr.ftLastWriteTime); | 589 results->last_modified = Time::FromFileTime(attr.ftLastWriteTime); |
582 results->last_accessed = Time::FromFileTime(attr.ftLastAccessTime); | 590 results->last_accessed = Time::FromFileTime(attr.ftLastAccessTime); |
583 results->creation_time = Time::FromFileTime(attr.ftCreationTime); | 591 results->creation_time = Time::FromFileTime(attr.ftCreationTime); |
584 | 592 |
585 return true; | 593 return true; |
586 } | 594 } |
587 | 595 |
588 FILE* OpenFile(const FilePath& filename, const char* mode) { | 596 FILE* OpenFile(const FilePath& filename, const char* mode) { |
| 597 // 'N' is unconditionally added below, so be sure there is not one already |
| 598 // present before a comma in |mode|. |
| 599 DCHECK( |
| 600 strchr(mode, 'N') == nullptr || |
| 601 (strchr(mode, ',') != nullptr && strchr(mode, 'N') > strchr(mode, ','))); |
589 ThreadRestrictions::AssertIOAllowed(); | 602 ThreadRestrictions::AssertIOAllowed(); |
590 string16 w_mode = ASCIIToUTF16(mode); | 603 string16 w_mode = ASCIIToUTF16(mode); |
| 604 AppendModeCharacter(L'N', &w_mode); |
591 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); | 605 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); |
592 } | 606 } |
593 | 607 |
594 FILE* FileToFILE(File file, const char* mode) { | 608 FILE* FileToFILE(File file, const char* mode) { |
595 if (!file.IsValid()) | 609 if (!file.IsValid()) |
596 return NULL; | 610 return NULL; |
597 int fd = | 611 int fd = |
598 _open_osfhandle(reinterpret_cast<intptr_t>(file.GetPlatformFile()), 0); | 612 _open_osfhandle(reinterpret_cast<intptr_t>(file.GetPlatformFile()), 0); |
599 if (fd < 0) | 613 if (fd < 0) |
600 return NULL; | 614 return NULL; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 // Like Move, this function is not transactional, so we just | 834 // Like Move, this function is not transactional, so we just |
821 // leave the copied bits behind if deleting from_path fails. | 835 // leave the copied bits behind if deleting from_path fails. |
822 // If to_path exists previously then we have already overwritten | 836 // If to_path exists previously then we have already overwritten |
823 // it by now, we don't get better off by deleting the new bits. | 837 // it by now, we don't get better off by deleting the new bits. |
824 } | 838 } |
825 return false; | 839 return false; |
826 } | 840 } |
827 | 841 |
828 } // namespace internal | 842 } // namespace internal |
829 } // namespace base | 843 } // namespace base |
OLD | NEW |