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

Side by Side Diff: chrome/installer/util/move_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) 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/move_tree_work_item.h" 5 #include "chrome/installer/util/move_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"
11 #include "chrome/installer/util/duplicate_tree_detector.h" 11 #include "chrome/installer/util/duplicate_tree_detector.h"
12 #include "chrome/installer/util/logging_installer.h" 12 #include "chrome/installer/util/logging_installer.h"
13 13
14 MoveTreeWorkItem::~MoveTreeWorkItem() { 14 MoveTreeWorkItem::~MoveTreeWorkItem() {
15 } 15 }
16 16
17 MoveTreeWorkItem::MoveTreeWorkItem(const base::FilePath& source_path, 17 MoveTreeWorkItem::MoveTreeWorkItem(const base::FilePath& source_path,
18 const base::FilePath& dest_path, 18 const base::FilePath& dest_path,
19 const base::FilePath& temp_dir, 19 const base::FilePath& temp_dir,
20 MoveTreeOption duplicate_option) 20 MoveTreeOption duplicate_option)
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 moved_to_dest_path_(false), 24 moved_to_dest_path_(false),
25 moved_to_backup_(false), 25 moved_to_backup_(false),
26 source_moved_to_backup_(false), 26 source_moved_to_backup_(false),
27 duplicate_option_(duplicate_option) { 27 duplicate_option_(duplicate_option) {
28 } 28 }
29 29
30 bool MoveTreeWorkItem::Do() { 30 bool MoveTreeWorkItem::DoImpl() {
31 if (!base::PathExists(source_path_)) { 31 if (!base::PathExists(source_path_)) {
32 LOG(ERROR) << source_path_.value() << " does not exist"; 32 LOG(ERROR) << source_path_.value() << " does not exist";
33 return false; 33 return false;
34 } 34 }
35 35
36 // If dest_path_ exists, we can do one of two things: 36 // If dest_path_ exists, we can do one of two things:
37 // 1) If the contents of src_path_are already fully contained in dest_path_ 37 // 1) If the contents of src_path_are already fully contained in dest_path_
38 // then do nothing and return success. Fully contained means the full 38 // then do nothing and return success. Fully contained means the full
39 // file structure with identical files is contained in dest_path_. For 39 // file structure with identical files is contained in dest_path_. For
40 // Chrome, if dest_path_ exists, this is expected to be the common case. 40 // Chrome, if dest_path_ exists, this is expected to be the common case.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 << " to destination " << dest_path_.value(); 92 << " to destination " << dest_path_.value();
93 } else { 93 } else {
94 PLOG(ERROR) << "failed move " << source_path_.value() 94 PLOG(ERROR) << "failed move " << source_path_.value()
95 << " to " << dest_path_.value(); 95 << " to " << dest_path_.value();
96 return false; 96 return false;
97 } 97 }
98 98
99 return true; 99 return true;
100 } 100 }
101 101
102 void MoveTreeWorkItem::Rollback() { 102 void MoveTreeWorkItem::RollbackImpl() {
103 if (moved_to_dest_path_ && !base::Move(dest_path_, source_path_)) { 103 if (moved_to_dest_path_ && !base::Move(dest_path_, source_path_)) {
104 PLOG(ERROR) << "Can not move " << dest_path_.value() 104 PLOG(ERROR) << "Can not move " << dest_path_.value()
105 << " to " << source_path_.value(); 105 << " to " << source_path_.value();
106 } 106 }
107 107
108 base::FilePath backup = backup_path_.path().Append(dest_path_.BaseName()); 108 base::FilePath backup = backup_path_.path().Append(dest_path_.BaseName());
109 if (moved_to_backup_ && !base::Move(backup, dest_path_)) { 109 if (moved_to_backup_ && !base::Move(backup, dest_path_)) {
110 PLOG(ERROR) << "failed move " << backup.value() 110 PLOG(ERROR) << "failed move " << backup.value()
111 << " to " << dest_path_.value(); 111 << " to " << dest_path_.value();
112 } 112 }
113 113
114 if (source_moved_to_backup_ && !base::Move(backup, source_path_)) { 114 if (source_moved_to_backup_ && !base::Move(backup, source_path_)) {
115 PLOG(ERROR) << "Can not restore " << backup.value() 115 PLOG(ERROR) << "Can not restore " << backup.value()
116 << " to " << source_path_.value(); 116 << " to " << source_path_.value();
117 } 117 }
118 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698