Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: base/file_util_win.cc

Issue 18584011: Rename base::Delete to base::DeleteFile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util_unittest.cc ('k') | base/files/file_path_watcher_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } // namespace 75 } // namespace
76 76
77 FilePath MakeAbsoluteFilePath(const FilePath& input) { 77 FilePath MakeAbsoluteFilePath(const FilePath& input) {
78 ThreadRestrictions::AssertIOAllowed(); 78 ThreadRestrictions::AssertIOAllowed();
79 wchar_t file_path[MAX_PATH]; 79 wchar_t file_path[MAX_PATH];
80 if (!_wfullpath(file_path, input.value().c_str(), MAX_PATH)) 80 if (!_wfullpath(file_path, input.value().c_str(), MAX_PATH))
81 return FilePath(); 81 return FilePath();
82 return FilePath(file_path); 82 return FilePath(file_path);
83 } 83 }
84 84
85 bool Delete(const FilePath& path, bool recursive) { 85 bool DeleteFile(const FilePath& path, bool recursive) {
86 ThreadRestrictions::AssertIOAllowed(); 86 ThreadRestrictions::AssertIOAllowed();
87 87
88 if (path.value().length() >= MAX_PATH) 88 if (path.value().length() >= MAX_PATH)
89 return false; 89 return false;
90 90
91 if (!recursive) { 91 if (!recursive) {
92 // If not recursing, then first check to see if |path| is a directory. 92 // If not recursing, then first check to see if |path| is a directory.
93 // If it is, then remove it with RemoveDirectory. 93 // If it is, then remove it with RemoveDirectory.
94 PlatformFileInfo file_info; 94 PlatformFileInfo file_info;
95 if (file_util::GetFileInfo(path, &file_info) && file_info.is_directory) 95 if (file_util::GetFileInfo(path, &file_info) && file_info.is_directory)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // happen). See MSDN for SHFileOperation and SHFILEOPTSTRUCT. 129 // happen). See MSDN for SHFileOperation and SHFILEOPTSTRUCT.
130 if (file_operation.fAnyOperationsAborted) 130 if (file_operation.fAnyOperationsAborted)
131 return false; 131 return false;
132 132
133 // Some versions of Windows return ERROR_FILE_NOT_FOUND (0x2) when deleting 133 // Some versions of Windows return ERROR_FILE_NOT_FOUND (0x2) when deleting
134 // an empty directory and some return 0x402 when they should be returning 134 // an empty directory and some return 0x402 when they should be returning
135 // ERROR_FILE_NOT_FOUND. MSDN says Vista and up won't return 0x402. 135 // ERROR_FILE_NOT_FOUND. MSDN says Vista and up won't return 0x402.
136 return (err == 0 || err == ERROR_FILE_NOT_FOUND || err == 0x402); 136 return (err == 0 || err == ERROR_FILE_NOT_FOUND || err == 0x402);
137 } 137 }
138 138
139 bool DeleteAfterReboot(const FilePath& path) { 139 bool DeleteFileAfterReboot(const FilePath& path) {
140 ThreadRestrictions::AssertIOAllowed(); 140 ThreadRestrictions::AssertIOAllowed();
141 141
142 if (path.value().length() >= MAX_PATH) 142 if (path.value().length() >= MAX_PATH)
143 return false; 143 return false;
144 144
145 return MoveFileEx(path.value().c_str(), NULL, 145 return MoveFileEx(path.value().c_str(), NULL,
146 MOVEFILE_DELAY_UNTIL_REBOOT | 146 MOVEFILE_DELAY_UNTIL_REBOOT |
147 MOVEFILE_REPLACE_EXISTING) != FALSE; 147 MOVEFILE_REPLACE_EXISTING) != FALSE;
148 } 148 }
149 149
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 return false; 737 return false;
738 } 738 }
739 return (::CopyFile(from_path.value().c_str(), to_path.value().c_str(), 739 return (::CopyFile(from_path.value().c_str(), to_path.value().c_str(),
740 false) != 0); 740 false) != 0);
741 } 741 }
742 742
743 bool CopyAndDeleteDirectory(const FilePath& from_path, 743 bool CopyAndDeleteDirectory(const FilePath& from_path,
744 const FilePath& to_path) { 744 const FilePath& to_path) {
745 ThreadRestrictions::AssertIOAllowed(); 745 ThreadRestrictions::AssertIOAllowed();
746 if (CopyDirectory(from_path, to_path, true)) { 746 if (CopyDirectory(from_path, to_path, true)) {
747 if (Delete(from_path, true)) 747 if (DeleteFile(from_path, true))
748 return true; 748 return true;
749 749
750 // Like Move, this function is not transactional, so we just 750 // Like Move, this function is not transactional, so we just
751 // leave the copied bits behind if deleting from_path fails. 751 // leave the copied bits behind if deleting from_path fails.
752 // If to_path exists previously then we have already overwritten 752 // If to_path exists previously then we have already overwritten
753 // it by now, we don't get better off by deleting the new bits. 753 // it by now, we don't get better off by deleting the new bits.
754 } 754 }
755 return false; 755 return false;
756 } 756 }
757 757
758 } // namespace internal 758 } // namespace internal
759 } // namespace base 759 } // namespace base
OLDNEW
« no previous file with comments | « base/file_util_unittest.cc ('k') | base/files/file_path_watcher_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698