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

Side by Side Diff: base/files/file_util_win.cc

Issue 2854323002: Make TestingProfile delete failures explicitly CHECK-fail.
Patch Set: TEMP: Deliberately crash tests on ~ScopedTempDir, to see logs. Created 3 years, 7 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
« no previous file with comments | « no previous file | base/files/scoped_temp_dir.h » ('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/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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 FilePath MakeAbsoluteFilePath(const FilePath& input) { 84 FilePath MakeAbsoluteFilePath(const FilePath& input) {
85 ThreadRestrictions::AssertIOAllowed(); 85 ThreadRestrictions::AssertIOAllowed();
86 wchar_t file_path[MAX_PATH]; 86 wchar_t file_path[MAX_PATH];
87 if (!_wfullpath(file_path, input.value().c_str(), MAX_PATH)) 87 if (!_wfullpath(file_path, input.value().c_str(), MAX_PATH))
88 return FilePath(); 88 return FilePath();
89 return FilePath(file_path); 89 return FilePath(file_path);
90 } 90 }
91 91
92 bool DeleteFile(const FilePath& path, bool recursive) { 92 bool DeleteFile(const FilePath& path, bool recursive) {
93 LOG(WARNING) << "base::DeleteFile: Asserting IO allowed";
93 ThreadRestrictions::AssertIOAllowed(); 94 ThreadRestrictions::AssertIOAllowed();
94 95
95 if (path.empty()) 96 LOG(WARNING) << "base::DeleteFile: IO allowed assertion is OK";
97 if (path.empty()) {
98 LOG(WARNING) << "base::DeleteFile: Succeeded (path was empty)";
96 return true; 99 return true;
100 }
97 101
98 if (path.value().length() >= MAX_PATH) 102 if (path.value().length() >= MAX_PATH) {
103 LOG(WARNING) << "base::DeleteFile: Failed (path was too long)";
99 return false; 104 return false;
105 }
100 106
101 // Handle any path with wildcards. 107 // Handle any path with wildcards.
102 if (path.BaseName().value().find_first_of(L"*?") != 108 if (path.BaseName().value().find_first_of(L"*?") !=
103 FilePath::StringType::npos) { 109 FilePath::StringType::npos) {
104 return DeleteFileRecursive(path.DirName(), path.BaseName().value(), 110 bool r =
105 recursive); 111 DeleteFileRecursive(path.DirName(), path.BaseName().value(), recursive);
112 LOG(WARNING) << "base::DeleteFile: " << (r ? "succeeded" : "failed")
113 << " due to DeleteFileRecursive.";
114 return r;
106 } 115 }
107 DWORD attr = GetFileAttributes(path.value().c_str()); 116 DWORD attr = GetFileAttributes(path.value().c_str());
108 // We're done if we can't find the path. 117 // We're done if we can't find the path.
109 if (attr == INVALID_FILE_ATTRIBUTES) 118 if (attr == INVALID_FILE_ATTRIBUTES) {
119 LOG(WARNING) << "base::DeleteFile: Succeeded because doesn't exist.";
110 return true; 120 return true;
121 }
111 // We may need to clear the read-only bit. 122 // We may need to clear the read-only bit.
112 if ((attr & FILE_ATTRIBUTE_READONLY) && 123 if ((attr & FILE_ATTRIBUTE_READONLY) &&
113 !SetFileAttributes(path.value().c_str(), 124 !SetFileAttributes(path.value().c_str(),
114 attr & ~FILE_ATTRIBUTE_READONLY)) { 125 attr & ~FILE_ATTRIBUTE_READONLY)) {
126 LOG(WARNING) << "base::DeleteFile: Failed because read only.";
115 return false; 127 return false;
116 } 128 }
117 // Directories are handled differently if they're recursive. 129 // Directories are handled differently if they're recursive.
118 if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) 130 if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) {
119 return !!::DeleteFile(path.value().c_str()); 131 bool r = !!::DeleteFile(path.value().c_str());
132 LOG(WARNING) << "base::DeleteFile: " << (r ? "succeeded" : "failed")
133 << " due to ::DeleteFile.";
134 return r;
135 }
120 // Handle a simple, single file delete. 136 // Handle a simple, single file delete.
121 if (!recursive || DeleteFileRecursive(path, L"*", true)) 137 if (!recursive || DeleteFileRecursive(path, L"*", true)) {
122 return !!RemoveDirectory(path.value().c_str()); 138 bool r = !!RemoveDirectory(path.value().c_str());
139 LOG(WARNING) << "base::DeleteFile: " << (r ? "succeeded" : "failed")
140 << " due to RemoveDirectory.";
141 return r;
142 }
123 143
144 LOG(WARNING) << "base::DeleteFile: Failed because ???.";
124 return false; 145 return false;
125 } 146 }
126 147
127 bool DeleteFileAfterReboot(const FilePath& path) { 148 bool DeleteFileAfterReboot(const FilePath& path) {
128 ThreadRestrictions::AssertIOAllowed(); 149 ThreadRestrictions::AssertIOAllowed();
129 150
130 if (path.value().length() >= MAX_PATH) 151 if (path.value().length() >= MAX_PATH)
131 return false; 152 return false;
132 153
133 return MoveFileEx(path.value().c_str(), NULL, 154 return MoveFileEx(path.value().c_str(), NULL,
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 // Like Move, this function is not transactional, so we just 886 // Like Move, this function is not transactional, so we just
866 // leave the copied bits behind if deleting from_path fails. 887 // leave the copied bits behind if deleting from_path fails.
867 // If to_path exists previously then we have already overwritten 888 // If to_path exists previously then we have already overwritten
868 // it by now, we don't get better off by deleting the new bits. 889 // it by now, we don't get better off by deleting the new bits.
869 } 890 }
870 return false; 891 return false;
871 } 892 }
872 893
873 } // namespace internal 894 } // namespace internal
874 } // namespace base 895 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/files/scoped_temp_dir.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698