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 // Add |mode_char| immediately before the comma or at the end of the string. | |
Mark Mentovai
2017/02/11 00:52:29
Pretty much a dupe here too.
grt (UTC plus 2)
2017/02/13 07:53:28
Done.
| |
77 size_t comma_pos = mode->find(L','); | |
78 mode->insert(comma_pos == base::string16::npos ? mode->length() : comma_pos, | |
79 1, mode_char); | |
80 } | |
81 | |
73 } // namespace | 82 } // namespace |
74 | 83 |
75 FilePath MakeAbsoluteFilePath(const FilePath& input) { | 84 FilePath MakeAbsoluteFilePath(const FilePath& input) { |
76 ThreadRestrictions::AssertIOAllowed(); | 85 ThreadRestrictions::AssertIOAllowed(); |
77 wchar_t file_path[MAX_PATH]; | 86 wchar_t file_path[MAX_PATH]; |
78 if (!_wfullpath(file_path, input.value().c_str(), MAX_PATH)) | 87 if (!_wfullpath(file_path, input.value().c_str(), MAX_PATH)) |
79 return FilePath(); | 88 return FilePath(); |
80 return FilePath(file_path); | 89 return FilePath(file_path); |
81 } | 90 } |
82 | 91 |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 results->is_directory = | 588 results->is_directory = |
580 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | 589 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
581 results->last_modified = Time::FromFileTime(attr.ftLastWriteTime); | 590 results->last_modified = Time::FromFileTime(attr.ftLastWriteTime); |
582 results->last_accessed = Time::FromFileTime(attr.ftLastAccessTime); | 591 results->last_accessed = Time::FromFileTime(attr.ftLastAccessTime); |
583 results->creation_time = Time::FromFileTime(attr.ftCreationTime); | 592 results->creation_time = Time::FromFileTime(attr.ftCreationTime); |
584 | 593 |
585 return true; | 594 return true; |
586 } | 595 } |
587 | 596 |
588 FILE* OpenFile(const FilePath& filename, const char* mode) { | 597 FILE* OpenFile(const FilePath& filename, const char* mode) { |
598 // 'N' is unconditionally added below, so be sure there is not one already | |
599 // present before a comma in |mode|. | |
600 DCHECK( | |
601 strchr(mode, 'N') == nullptr || | |
602 (strchr(mode, ',') != nullptr && strchr(mode, 'N') > strchr(mode, ','))); | |
589 ThreadRestrictions::AssertIOAllowed(); | 603 ThreadRestrictions::AssertIOAllowed(); |
590 string16 w_mode = ASCIIToUTF16(mode); | 604 string16 w_mode = ASCIIToUTF16(mode); |
605 AppendModeCharacter(L'N', &w_mode); | |
591 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); | 606 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); |
592 } | 607 } |
593 | 608 |
594 FILE* FileToFILE(File file, const char* mode) { | 609 FILE* FileToFILE(File file, const char* mode) { |
595 if (!file.IsValid()) | 610 if (!file.IsValid()) |
596 return NULL; | 611 return NULL; |
597 int fd = | 612 int fd = |
598 _open_osfhandle(reinterpret_cast<intptr_t>(file.GetPlatformFile()), 0); | 613 _open_osfhandle(reinterpret_cast<intptr_t>(file.GetPlatformFile()), 0); |
599 if (fd < 0) | 614 if (fd < 0) |
600 return NULL; | 615 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 | 835 // Like Move, this function is not transactional, so we just |
821 // leave the copied bits behind if deleting from_path fails. | 836 // leave the copied bits behind if deleting from_path fails. |
822 // If to_path exists previously then we have already overwritten | 837 // 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. | 838 // it by now, we don't get better off by deleting the new bits. |
824 } | 839 } |
825 return false; | 840 return false; |
826 } | 841 } |
827 | 842 |
828 } // namespace internal | 843 } // namespace internal |
829 } // namespace base | 844 } // namespace base |
OLD | NEW |