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

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

Issue 1882923003: Add best-effort/allow rollback flags on WorkItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simple_list_tests
Patch Set: fix build error Created 4 years, 7 months 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
OLDNEW
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 #include "chrome/installer/util/copy_tree_work_item.h" 5 #include "chrome/installer/util/copy_tree_work_item.h"
6 6
7 #include <shlwapi.h> 7 #include <shlwapi.h>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 10 matching lines...) Expand all
21 : source_path_(source_path), 21 : source_path_(source_path),
22 dest_path_(dest_path), 22 dest_path_(dest_path),
23 temp_dir_(temp_dir), 23 temp_dir_(temp_dir),
24 overwrite_option_(overwrite_option), 24 overwrite_option_(overwrite_option),
25 alternative_path_(alternative_path), 25 alternative_path_(alternative_path),
26 copied_to_dest_path_(false), 26 copied_to_dest_path_(false),
27 moved_to_backup_(false), 27 moved_to_backup_(false),
28 copied_to_alternate_path_(false) { 28 copied_to_alternate_path_(false) {
29 } 29 }
30 30
31 bool CopyTreeWorkItem::Do() { 31 bool CopyTreeWorkItem::DoImpl() {
32 if (!base::PathExists(source_path_)) { 32 if (!base::PathExists(source_path_)) {
33 LOG(ERROR) << source_path_.value() << " does not exist"; 33 LOG(ERROR) << source_path_.value() << " does not exist";
34 return false; 34 return false;
35 } 35 }
36 36
37 bool dest_exist = base::PathExists(dest_path_); 37 bool dest_exist = base::PathExists(dest_path_);
38 // handle overwrite_option_ = IF_DIFFERENT case. 38 // handle overwrite_option_ = IF_DIFFERENT case.
39 if ((dest_exist) && 39 if ((dest_exist) &&
40 (overwrite_option_ == WorkItem::IF_DIFFERENT) && // only for single file 40 (overwrite_option_ == WorkItem::IF_DIFFERENT) && // only for single file
41 (!base::DirectoryExists(source_path_)) && 41 (!base::DirectoryExists(source_path_)) &&
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 << " to destination " << dest_path_.value(); 96 << " to destination " << dest_path_.value();
97 } else { 97 } else {
98 LOG(ERROR) << "failed copy " << source_path_.value() 98 LOG(ERROR) << "failed copy " << source_path_.value()
99 << " to " << dest_path_.value(); 99 << " to " << dest_path_.value();
100 return false; 100 return false;
101 } 101 }
102 102
103 return true; 103 return true;
104 } 104 }
105 105
106 void CopyTreeWorkItem::Rollback() { 106 void CopyTreeWorkItem::RollbackImpl() {
107 // Normally the delete operations below should not fail unless some 107 // Normally the delete operations below should not fail unless some
108 // programs like anti-virus are inspecting the files we just copied. 108 // programs like anti-virus are inspecting the files we just copied.
109 // If this does happen sometimes, we may consider using Move instead of 109 // If this does happen sometimes, we may consider using Move instead of
110 // Delete here. For now we just log the error and continue with the 110 // Delete here. For now we just log the error and continue with the
111 // rest of rollback operation. 111 // rest of rollback operation.
112 if (copied_to_dest_path_ && !base::DeleteFile(dest_path_, true)) { 112 if (copied_to_dest_path_ && !base::DeleteFile(dest_path_, true)) {
113 LOG(ERROR) << "Can not delete " << dest_path_.value(); 113 LOG(ERROR) << "Can not delete " << dest_path_.value();
114 } 114 }
115 if (moved_to_backup_) { 115 if (moved_to_backup_) {
116 base::FilePath backup(backup_path_.path().Append(dest_path_.BaseName())); 116 base::FilePath backup(backup_path_.path().Append(dest_path_.BaseName()));
(...skipping 13 matching lines...) Expand all
130 return false; 130 return false;
131 131
132 HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS, 132 HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS,
133 NULL, NULL, OPEN_EXISTING, NULL, NULL); 133 NULL, NULL, OPEN_EXISTING, NULL, NULL);
134 if (handle == INVALID_HANDLE_VALUE) 134 if (handle == INVALID_HANDLE_VALUE)
135 return true; 135 return true;
136 136
137 CloseHandle(handle); 137 CloseHandle(handle);
138 return false; 138 return false;
139 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698