| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/installer/util/delete_tree_work_item.h" | 5 #include "chrome/installer/util/delete_tree_work_item.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 std::for_each(opened_key_files.begin(), opened_key_files.end(), CloseHandle); | 102 std::for_each(opened_key_files.begin(), opened_key_files.end(), CloseHandle); |
| 103 opened_key_files.clear(); | 103 opened_key_files.clear(); |
| 104 | 104 |
| 105 if (abort) { | 105 if (abort) { |
| 106 LOG(ERROR) << "Could not exclusively hold all key files."; | 106 LOG(ERROR) << "Could not exclusively hold all key files."; |
| 107 return ignore_failure_; | 107 return ignore_failure_; |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Now that we've taken care of the key files, take care of the rest. | 110 // Now that we've taken care of the key files, take care of the rest. |
| 111 if (!root_path_.empty() && file_util::PathExists(root_path_)) { | 111 if (!root_path_.empty() && base::PathExists(root_path_)) { |
| 112 if (!ignore_failure_) { | 112 if (!ignore_failure_) { |
| 113 if (!backup_path_.CreateUniqueTempDirUnderPath(temp_path_)) { | 113 if (!backup_path_.CreateUniqueTempDirUnderPath(temp_path_)) { |
| 114 PLOG(ERROR) << "Failed to get backup path in folder " | 114 PLOG(ERROR) << "Failed to get backup path in folder " |
| 115 << temp_path_.value(); | 115 << temp_path_.value(); |
| 116 return false; | 116 return false; |
| 117 } else { | 117 } else { |
| 118 base::FilePath backup = | 118 base::FilePath backup = |
| 119 backup_path_.path().Append(root_path_.BaseName()); | 119 backup_path_.path().Append(root_path_.BaseName()); |
| 120 if (!base::CopyDirectory(root_path_, backup, true)) { | 120 if (!base::CopyDirectory(root_path_, backup, true)) { |
| 121 LOG(ERROR) << "can not copy " << root_path_.value() | 121 LOG(ERROR) << "can not copy " << root_path_.value() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 136 } | 136 } |
| 137 | 137 |
| 138 // If there are files in backup paths move them back. | 138 // If there are files in backup paths move them back. |
| 139 void DeleteTreeWorkItem::Rollback() { | 139 void DeleteTreeWorkItem::Rollback() { |
| 140 if (ignore_failure_) | 140 if (ignore_failure_) |
| 141 return; | 141 return; |
| 142 | 142 |
| 143 if (copied_to_backup_) { | 143 if (copied_to_backup_) { |
| 144 DCHECK(!backup_path_.path().empty()); | 144 DCHECK(!backup_path_.path().empty()); |
| 145 base::FilePath backup = backup_path_.path().Append(root_path_.BaseName()); | 145 base::FilePath backup = backup_path_.path().Append(root_path_.BaseName()); |
| 146 if (file_util::PathExists(backup)) | 146 if (base::PathExists(backup)) |
| 147 base::Move(backup, root_path_); | 147 base::Move(backup, root_path_); |
| 148 } | 148 } |
| 149 | 149 |
| 150 for (ptrdiff_t i = 0; i != num_key_files_; ++i) { | 150 for (ptrdiff_t i = 0; i != num_key_files_; ++i) { |
| 151 base::ScopedTempDir& backup_dir = key_backup_paths_[i]; | 151 base::ScopedTempDir& backup_dir = key_backup_paths_[i]; |
| 152 if (!backup_dir.path().empty()) { | 152 if (!backup_dir.path().empty()) { |
| 153 base::FilePath& key_file = key_paths_[i]; | 153 base::FilePath& key_file = key_paths_[i]; |
| 154 base::FilePath backup_file = | 154 base::FilePath backup_file = |
| 155 backup_dir.path().Append(key_file.BaseName()); | 155 backup_dir.path().Append(key_file.BaseName()); |
| 156 if (file_util::PathExists(backup_file) && | 156 if (base::PathExists(backup_file) && |
| 157 !base::Move(backup_file, key_file)) { | 157 !base::Move(backup_file, key_file)) { |
| 158 // This could happen if we could not delete the key file to begin with. | 158 // This could happen if we could not delete the key file to begin with. |
| 159 PLOG(WARNING) << "Rollback: Failed to move backup file back in place: " | 159 PLOG(WARNING) << "Rollback: Failed to move backup file back in place: " |
| 160 << backup_file.value() << " to " << key_file.value(); | 160 << backup_file.value() << " to " << key_file.value(); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 } | 164 } |
| OLD | NEW |