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/test/test_file_util.h" | 5 #include "base/test/test_file_util.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <aclapi.h> | 8 #include <aclapi.h> |
9 #include <shlwapi.h> | 9 #include <shlwapi.h> |
10 | 10 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 CHECK(::SetEndOfFile(file_handle)); | 209 CHECK(::SetEndOfFile(file_handle)); |
210 } | 210 } |
211 | 211 |
212 // Restore the file attributes. | 212 // Restore the file attributes. |
213 CHECK(::SetFileTime(file_handle, &bhi.ftCreationTime, &bhi.ftLastAccessTime, | 213 CHECK(::SetFileTime(file_handle, &bhi.ftCreationTime, &bhi.ftLastAccessTime, |
214 &bhi.ftLastWriteTime)); | 214 &bhi.ftLastWriteTime)); |
215 | 215 |
216 return true; | 216 return true; |
217 } | 217 } |
218 | 218 |
219 // Like CopyFileNoCache but recursively copies all files and subdirectories | |
220 // in the given input directory to the output directory. | |
221 bool CopyRecursiveDirNoCache(const base::FilePath& source_dir, | |
222 const base::FilePath& dest_dir) { | |
223 // Try to create the directory if it doesn't already exist. | |
224 if (!CreateDirectory(dest_dir)) { | |
225 if (GetLastError() != ERROR_ALREADY_EXISTS) | |
226 return false; | |
227 } | |
228 | |
229 std::vector<std::wstring> files_copied; | |
230 | |
231 base::FilePath src(source_dir.AppendASCII("*")); | |
232 | |
233 WIN32_FIND_DATA fd; | |
234 HANDLE fh = FindFirstFile(src.value().c_str(), &fd); | |
235 if (fh == INVALID_HANDLE_VALUE) | |
236 return false; | |
237 | |
238 do { | |
239 std::wstring cur_file(fd.cFileName); | |
240 if (cur_file == L"." || cur_file == L"..") | |
241 continue; // Skip these special entries. | |
242 | |
243 base::FilePath cur_source_path = source_dir.Append(cur_file); | |
244 base::FilePath cur_dest_path = dest_dir.Append(cur_file); | |
245 | |
246 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { | |
247 // Recursively copy a subdirectory. We stripped "." and ".." already. | |
248 if (!CopyRecursiveDirNoCache(cur_source_path, cur_dest_path)) { | |
249 FindClose(fh); | |
250 return false; | |
251 } | |
252 } else { | |
253 // Copy the file. | |
254 if (!::CopyFile(cur_source_path.value().c_str(), | |
255 cur_dest_path.value().c_str(), false)) { | |
256 FindClose(fh); | |
257 return false; | |
258 } | |
259 | |
260 // We don't check for errors from this function, often, we are copying | |
261 // files that are in the repository, and they will have read-only set. | |
262 // This will prevent us from evicting from the cache, but these don't | |
263 // matter anyway. | |
264 EvictFileFromSystemCache(cur_dest_path); | |
265 } | |
266 } while (FindNextFile(fh, &fd)); | |
267 | |
268 FindClose(fh); | |
269 return true; | |
270 } | |
271 | |
272 // Checks if the volume supports Alternate Data Streams. This is required for | 219 // Checks if the volume supports Alternate Data Streams. This is required for |
273 // the Zone Identifier implementation. | 220 // the Zone Identifier implementation. |
274 bool VolumeSupportsADS(const base::FilePath& path) { | 221 bool VolumeSupportsADS(const base::FilePath& path) { |
275 wchar_t drive[MAX_PATH] = {0}; | 222 wchar_t drive[MAX_PATH] = {0}; |
276 wcscpy_s(drive, MAX_PATH, path.value().c_str()); | 223 wcscpy_s(drive, MAX_PATH, path.value().c_str()); |
277 | 224 |
278 if (!PathStripToRootW(drive)) | 225 if (!PathStripToRootW(drive)) |
279 return false; | 226 return false; |
280 | 227 |
281 DWORD fs_flags = 0; | 228 DWORD fs_flags = 0; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 DCHECK(info_ != NULL); | 282 DCHECK(info_ != NULL); |
336 DCHECK_NE(0u, length_); | 283 DCHECK_NE(0u, length_); |
337 } | 284 } |
338 | 285 |
339 PermissionRestorer::~PermissionRestorer() { | 286 PermissionRestorer::~PermissionRestorer() { |
340 if (!RestorePermissionInfo(path_, info_, length_)) | 287 if (!RestorePermissionInfo(path_, info_, length_)) |
341 NOTREACHED(); | 288 NOTREACHED(); |
342 } | 289 } |
343 | 290 |
344 } // namespace file_util | 291 } // namespace file_util |
OLD | NEW |