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

Side by Side Diff: chrome/installer/util/delete_tree_work_item.cc

Issue 11359217: Move scoped_temp_dir from base to base/files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 20 matching lines...) Expand all
31 const FilePath& root_path, 31 const FilePath& root_path,
32 const FilePath& temp_path, 32 const FilePath& temp_path,
33 const std::vector<FilePath>& key_paths) 33 const std::vector<FilePath>& key_paths)
34 : root_path_(root_path), 34 : root_path_(root_path),
35 temp_path_(temp_path), 35 temp_path_(temp_path),
36 copied_to_backup_(false) { 36 copied_to_backup_(false) {
37 if (!SafeCast(key_paths.size(), &num_key_files_)) { 37 if (!SafeCast(key_paths.size(), &num_key_files_)) {
38 NOTREACHED() << "Impossibly large key_paths collection"; 38 NOTREACHED() << "Impossibly large key_paths collection";
39 } else if (num_key_files_ != 0) { 39 } else if (num_key_files_ != 0) {
40 key_paths_.reset(new FilePath[num_key_files_]); 40 key_paths_.reset(new FilePath[num_key_files_]);
41 key_backup_paths_.reset(new ScopedTempDir[num_key_files_]); 41 key_backup_paths_.reset(new base::ScopedTempDir[num_key_files_]);
42 std::copy(key_paths.begin(), key_paths.end(), &key_paths_[0]); 42 std::copy(key_paths.begin(), key_paths.end(), &key_paths_[0]);
43 } 43 }
44 } 44 }
45 45
46 DeleteTreeWorkItem::~DeleteTreeWorkItem() { 46 DeleteTreeWorkItem::~DeleteTreeWorkItem() {
47 } 47 }
48 48
49 // We first try to move key_path_ to backup_path. If it succeeds, we go ahead 49 // We first try to move key_path_ to backup_path. If it succeeds, we go ahead
50 // and move the rest. 50 // and move the rest.
51 bool DeleteTreeWorkItem::Do() { 51 bool DeleteTreeWorkItem::Do() {
52 // Go through all the key files and see if we can open them exclusively 52 // Go through all the key files and see if we can open them exclusively
53 // with only the FILE_SHARE_DELETE flag. Once we know we have all of them, 53 // with only the FILE_SHARE_DELETE flag. Once we know we have all of them,
54 // we can delete them. 54 // we can delete them.
55 std::vector<HANDLE> opened_key_files; 55 std::vector<HANDLE> opened_key_files;
56 opened_key_files.reserve(num_key_files_); 56 opened_key_files.reserve(num_key_files_);
57 bool abort = false; 57 bool abort = false;
58 for (ptrdiff_t i = 0; !abort && i != num_key_files_; ++i) { 58 for (ptrdiff_t i = 0; !abort && i != num_key_files_; ++i) {
59 FilePath& key_file = key_paths_[i]; 59 FilePath& key_file = key_paths_[i];
60 ScopedTempDir& backup = key_backup_paths_[i]; 60 base::ScopedTempDir& backup = key_backup_paths_[i];
61 if (!ignore_failure_) { 61 if (!ignore_failure_) {
62 if (!backup.CreateUniqueTempDirUnderPath(temp_path_)) { 62 if (!backup.CreateUniqueTempDirUnderPath(temp_path_)) {
63 PLOG(ERROR) << "Could not create temp dir in " << temp_path_.value(); 63 PLOG(ERROR) << "Could not create temp dir in " << temp_path_.value();
64 abort = true; 64 abort = true;
65 } else if (!file_util::CopyFile(key_file, 65 } else if (!file_util::CopyFile(key_file,
66 backup.path().Append(key_file.BaseName()))) { 66 backup.path().Append(key_file.BaseName()))) {
67 PLOG(ERROR) << "Could not back up " << key_file.value() 67 PLOG(ERROR) << "Could not back up " << key_file.value()
68 << " to directory " << backup.path().value(); 68 << " to directory " << backup.path().value();
69 abort = true; 69 abort = true;
70 backup.Delete(); 70 backup.Delete();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 return; 140 return;
141 141
142 if (copied_to_backup_) { 142 if (copied_to_backup_) {
143 DCHECK(!backup_path_.path().empty()); 143 DCHECK(!backup_path_.path().empty());
144 FilePath backup = backup_path_.path().Append(root_path_.BaseName()); 144 FilePath backup = backup_path_.path().Append(root_path_.BaseName());
145 if (file_util::PathExists(backup)) 145 if (file_util::PathExists(backup))
146 file_util::Move(backup, root_path_); 146 file_util::Move(backup, root_path_);
147 } 147 }
148 148
149 for (ptrdiff_t i = 0; i != num_key_files_; ++i) { 149 for (ptrdiff_t i = 0; i != num_key_files_; ++i) {
150 ScopedTempDir& backup_dir = key_backup_paths_[i]; 150 base::ScopedTempDir& backup_dir = key_backup_paths_[i];
151 if (!backup_dir.path().empty()) { 151 if (!backup_dir.path().empty()) {
152 FilePath& key_file = key_paths_[i]; 152 FilePath& key_file = key_paths_[i];
153 FilePath backup_file = backup_dir.path().Append(key_file.BaseName()); 153 FilePath backup_file = backup_dir.path().Append(key_file.BaseName());
154 if (file_util::PathExists(backup_file) && 154 if (file_util::PathExists(backup_file) &&
155 !file_util::Move(backup_file, key_file)) { 155 !file_util::Move(backup_file, key_file)) {
156 // This could happen if we could not delete the key file to begin with. 156 // This could happen if we could not delete the key file to begin with.
157 PLOG(WARNING) << "Rollback: Failed to move backup file back in place: " 157 PLOG(WARNING) << "Rollback: Failed to move backup file back in place: "
158 << backup_file.value() << " to " << key_file.value(); 158 << backup_file.value() << " to " << key_file.value();
159 } 159 }
160 } 160 }
161 } 161 }
162 } 162 }
OLDNEW
« no previous file with comments | « chrome/installer/util/delete_tree_work_item.h ('k') | chrome/installer/util/delete_tree_work_item_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698