OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 std::for_each(opened_key_files.begin(), opened_key_files.end(), CloseHandle); | 97 std::for_each(opened_key_files.begin(), opened_key_files.end(), CloseHandle); |
98 opened_key_files.clear(); | 98 opened_key_files.clear(); |
99 | 99 |
100 if (abort) { | 100 if (abort) { |
101 LOG(ERROR) << "Could not exclusively hold all key files."; | 101 LOG(ERROR) << "Could not exclusively hold all key files."; |
102 return ignore_failure_; | 102 return ignore_failure_; |
103 } | 103 } |
104 | 104 |
105 // Now that we've taken care of the key files, take care of the rest. | 105 // Now that we've taken care of the key files, take care of the rest. |
106 if (!root_path_.empty() && file_util::PathExists(root_path_)) { | 106 if (!root_path_.empty() && file_util::PathExists(root_path_)) { |
107 if (!backup_path_.CreateUniqueTempDirUnderPath(temp_path_)) { | 107 if (!ignore_failure_) { |
108 PLOG(ERROR) << "Failed to get backup path in folder " | 108 if (!backup_path_.CreateUniqueTempDirUnderPath(temp_path_)) { |
109 << temp_path_.value(); | 109 PLOG(ERROR) << "Failed to get backup path in folder " |
| 110 << temp_path_.value(); |
| 111 return false; |
| 112 } else { |
| 113 FilePath backup = backup_path_.path().Append(root_path_.BaseName()); |
| 114 if (!file_util::CopyDirectory(root_path_, backup, true)) { |
| 115 LOG(ERROR) << "can not copy " << root_path_.value() |
| 116 << " to backup path " << backup.value(); |
| 117 return false; |
| 118 } |
| 119 } |
| 120 } |
| 121 if (!file_util::Delete(root_path_, true)) { |
| 122 LOG(ERROR) << "can not delete " << root_path_.value(); |
110 return ignore_failure_; | 123 return ignore_failure_; |
111 } else { | |
112 FilePath backup = backup_path_.path().Append(root_path_.BaseName()); | |
113 if (!file_util::CopyDirectory(root_path_, backup, true) || | |
114 !file_util::Delete(root_path_, true)) { | |
115 LOG(ERROR) << "can not delete " << root_path_.value() | |
116 << " OR copy it to backup path " << backup.value(); | |
117 return ignore_failure_; | |
118 } | |
119 } | 124 } |
120 } | 125 } |
121 | 126 |
122 return true; | 127 return true; |
123 } | 128 } |
124 | 129 |
125 // If there are files in backup paths move them back. | 130 // If there are files in backup paths move them back. |
126 void DeleteTreeWorkItem::Rollback() { | 131 void DeleteTreeWorkItem::Rollback() { |
127 if (ignore_failure_) | 132 if (ignore_failure_) |
128 return; | 133 return; |
(...skipping 11 matching lines...) Expand all Loading... |
140 FilePath backup_file = backup_dir.path().Append(key_file.BaseName()); | 145 FilePath backup_file = backup_dir.path().Append(key_file.BaseName()); |
141 if (file_util::PathExists(backup_file) && | 146 if (file_util::PathExists(backup_file) && |
142 !file_util::Move(backup_file, key_file)) { | 147 !file_util::Move(backup_file, key_file)) { |
143 // This could happen if we could not delete the key file to begin with. | 148 // This could happen if we could not delete the key file to begin with. |
144 PLOG(WARNING) << "Rollback: Failed to move backup file back in place: " | 149 PLOG(WARNING) << "Rollback: Failed to move backup file back in place: " |
145 << backup_file.value() << " to " << key_file.value(); | 150 << backup_file.value() << " to " << key_file.value(); |
146 } | 151 } |
147 } | 152 } |
148 } | 153 } |
149 } | 154 } |
OLD | NEW |