OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This file defines helper methods used to schedule files for deletion | 5 // This file defines helper methods used to schedule files for deletion |
6 // on next reboot. The code here is heavily borrowed and simplified from | 6 // on next reboot. The code here is heavily borrowed and simplified from |
7 // http://code.google.com/p/omaha/source/browse/trunk/common/file.cc and | 7 // http://code.google.com/p/omaha/source/browse/trunk/common/file.cc and |
8 // http://code.google.com/p/omaha/source/browse/trunk/common/utils.cc | 8 // http://code.google.com/p/omaha/source/browse/trunk/common/utils.cc |
9 // | 9 // |
10 // This implementation really is not fast, so do not use it where that will | 10 // This implementation really is not fast, so do not use it where that will |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // Must only be called for regular files or directories that will be empty. | 55 // Must only be called for regular files or directories that will be empty. |
56 bool ScheduleFileSystemEntityForDeletion(const wchar_t* path) { | 56 bool ScheduleFileSystemEntityForDeletion(const wchar_t* path) { |
57 // Check if the file exists, return false if not. | 57 // Check if the file exists, return false if not. |
58 WIN32_FILE_ATTRIBUTE_DATA attrs = {0}; | 58 WIN32_FILE_ATTRIBUTE_DATA attrs = {0}; |
59 if (!::GetFileAttributesEx(path, ::GetFileExInfoStandard, &attrs)) { | 59 if (!::GetFileAttributesEx(path, ::GetFileExInfoStandard, &attrs)) { |
60 PLOG(WARNING) << path << " does not exist."; | 60 PLOG(WARNING) << path << " does not exist."; |
61 return false; | 61 return false; |
62 } | 62 } |
63 | 63 |
64 DWORD flags = MOVEFILE_DELAY_UNTIL_REBOOT; | 64 DWORD flags = MOVEFILE_DELAY_UNTIL_REBOOT; |
65 if (!file_util::DirectoryExists(FilePath::FromWStringHack(path))) { | 65 if (!file_util::DirectoryExists(base::FilePath::FromWStringHack(path))) { |
66 // This flag valid only for files | 66 // This flag valid only for files |
67 flags |= MOVEFILE_REPLACE_EXISTING; | 67 flags |= MOVEFILE_REPLACE_EXISTING; |
68 } | 68 } |
69 | 69 |
70 if (!::MoveFileEx(path, NULL, flags)) { | 70 if (!::MoveFileEx(path, NULL, flags)) { |
71 PLOG(ERROR) << "Could not schedule " << path << " for deletion."; | 71 PLOG(ERROR) << "Could not schedule " << path << " for deletion."; |
72 return false; | 72 return false; |
73 } | 73 } |
74 | 74 |
75 #ifndef NDEBUG | 75 #ifndef NDEBUG |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 109 } |
110 // Confirm it is a directory | 110 // Confirm it is a directory |
111 if (!(dir_attributes & FILE_ATTRIBUTE_DIRECTORY)) { | 111 if (!(dir_attributes & FILE_ATTRIBUTE_DIRECTORY)) { |
112 LOG(ERROR) << "Scheduled directory is not a directory: " << dir_name; | 112 LOG(ERROR) << "Scheduled directory is not a directory: " << dir_name; |
113 return false; | 113 return false; |
114 } | 114 } |
115 | 115 |
116 // First schedule all the normal files for deletion. | 116 // First schedule all the normal files for deletion. |
117 { | 117 { |
118 bool success = true; | 118 bool success = true; |
119 file_util::FileEnumerator file_enum(FilePath(dir_name), false, | 119 file_util::FileEnumerator file_enum(base::FilePath(dir_name), false, |
120 file_util::FileEnumerator::FILES); | 120 file_util::FileEnumerator::FILES); |
121 for (FilePath file = file_enum.Next(); !file.empty(); | 121 for (base::FilePath file = file_enum.Next(); !file.empty(); |
122 file = file_enum.Next()) { | 122 file = file_enum.Next()) { |
123 success = ScheduleFileSystemEntityForDeletion(file.value().c_str()); | 123 success = ScheduleFileSystemEntityForDeletion(file.value().c_str()); |
124 if (!success) { | 124 if (!success) { |
125 LOG(ERROR) << "Failed to schedule file for deletion: " << file.value(); | 125 LOG(ERROR) << "Failed to schedule file for deletion: " << file.value(); |
126 return false; | 126 return false; |
127 } | 127 } |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 // Then recurse to all the subdirectories. | 131 // Then recurse to all the subdirectories. |
132 { | 132 { |
133 bool success = true; | 133 bool success = true; |
134 file_util::FileEnumerator dir_enum(FilePath(dir_name), false, | 134 file_util::FileEnumerator dir_enum(base::FilePath(dir_name), false, |
135 file_util::FileEnumerator::DIRECTORIES); | 135 file_util::FileEnumerator::DIRECTORIES); |
136 for (FilePath sub_dir = dir_enum.Next(); !sub_dir.empty(); | 136 for (base::FilePath sub_dir = dir_enum.Next(); !sub_dir.empty(); |
137 sub_dir = dir_enum.Next()) { | 137 sub_dir = dir_enum.Next()) { |
138 success = ScheduleDirectoryForDeletion(sub_dir.value().c_str()); | 138 success = ScheduleDirectoryForDeletion(sub_dir.value().c_str()); |
139 if (!success) { | 139 if (!success) { |
140 LOG(ERROR) << "Failed to schedule subdirectory for deletion: " | 140 LOG(ERROR) << "Failed to schedule subdirectory for deletion: " |
141 << sub_dir.value(); | 141 << sub_dir.value(); |
142 return false; | 142 return false; |
143 } | 143 } |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 ERROR_SUCCESS); | 383 ERROR_SUCCESS); |
384 } | 384 } |
385 std::vector<char> buffer; | 385 std::vector<char> buffer; |
386 StringArrayToMultiSZBytes(strings_to_keep, &buffer); | 386 StringArrayToMultiSZBytes(strings_to_keep, &buffer); |
387 DCHECK_GT(buffer.size(), 0U); | 387 DCHECK_GT(buffer.size(), 0U); |
388 if (buffer.empty()) | 388 if (buffer.empty()) |
389 return false; | 389 return false; |
390 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], | 390 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], |
391 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS); | 391 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS); |
392 } | 392 } |
OLD | NEW |