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

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

Issue 2379543002: installer and some misc files: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: regroup ifs Created 4 years, 2 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"
11 #include "chrome/installer/util/logging_installer.h" 11 #include "chrome/installer/util/logging_installer.h"
12 12
13 CopyTreeWorkItem::~CopyTreeWorkItem() { 13 CopyTreeWorkItem::~CopyTreeWorkItem() {
14 } 14 }
15 15
16 CopyTreeWorkItem::CopyTreeWorkItem(const base::FilePath& source_path, 16 CopyTreeWorkItem::CopyTreeWorkItem(const base::FilePath& source_path,
17 const base::FilePath& dest_path, 17 const base::FilePath& dest_path,
18 const base::FilePath& temp_dir, 18 const base::FilePath& temp_dir,
19 CopyOverWriteOption overwrite_option, 19 CopyOverWriteOption overwrite_option,
20 const base::FilePath& alternative_path) 20 const base::FilePath& alternative_path)
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 backup_path_created_(false) {}
30 30
31 bool CopyTreeWorkItem::DoImpl() { 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) &&
(...skipping 29 matching lines...) Expand all
69 return true; 69 return true;
70 } 70 }
71 71
72 // In all cases that reach here, move dest to a backup path. 72 // In all cases that reach here, move dest to a backup path.
73 if (dest_exist) { 73 if (dest_exist) {
74 if (!backup_path_.CreateUniqueTempDirUnderPath(temp_dir_)) { 74 if (!backup_path_.CreateUniqueTempDirUnderPath(temp_dir_)) {
75 PLOG(ERROR) << "Failed to get backup path in folder " 75 PLOG(ERROR) << "Failed to get backup path in folder "
76 << temp_dir_.value(); 76 << temp_dir_.value();
77 return false; 77 return false;
78 } 78 }
79 backup_path_created_ = true;
79 80
80 base::FilePath backup = backup_path_.path().Append(dest_path_.BaseName()); 81 base::FilePath backup =
82 backup_path_.GetPath().Append(dest_path_.BaseName());
81 if (base::Move(dest_path_, backup)) { 83 if (base::Move(dest_path_, backup)) {
82 moved_to_backup_ = true; 84 moved_to_backup_ = true;
83 VLOG(1) << "Moved destination " << dest_path_.value() << 85 VLOG(1) << "Moved destination " << dest_path_.value() <<
84 " to backup path " << backup.value(); 86 " to backup path " << backup.value();
85 } else { 87 } else {
86 PLOG(ERROR) << "failed moving " << dest_path_.value() 88 PLOG(ERROR) << "failed moving " << dest_path_.value()
87 << " to " << backup.value(); 89 << " to " << backup.value();
88 return false; 90 return false;
89 } 91 }
90 } 92 }
(...skipping 15 matching lines...) Expand all
106 void CopyTreeWorkItem::RollbackImpl() { 108 void CopyTreeWorkItem::RollbackImpl() {
107 // Normally the delete operations below should not fail unless some 109 // Normally the delete operations below should not fail unless some
108 // programs like anti-virus are inspecting the files we just copied. 110 // programs like anti-virus are inspecting the files we just copied.
109 // If this does happen sometimes, we may consider using Move instead of 111 // 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 112 // Delete here. For now we just log the error and continue with the
111 // rest of rollback operation. 113 // rest of rollback operation.
112 if (copied_to_dest_path_ && !base::DeleteFile(dest_path_, true)) { 114 if (copied_to_dest_path_ && !base::DeleteFile(dest_path_, true)) {
113 LOG(ERROR) << "Can not delete " << dest_path_.value(); 115 LOG(ERROR) << "Can not delete " << dest_path_.value();
114 } 116 }
115 if (moved_to_backup_) { 117 if (moved_to_backup_) {
116 base::FilePath backup(backup_path_.path().Append(dest_path_.BaseName())); 118 base::FilePath backup(backup_path_.GetPath().Append(dest_path_.BaseName()));
117 if (!base::Move(backup, dest_path_)) { 119 if (!base::Move(backup, dest_path_)) {
118 PLOG(ERROR) << "failed move " << backup.value() 120 PLOG(ERROR) << "failed move " << backup.value()
119 << " to " << dest_path_.value(); 121 << " to " << dest_path_.value();
120 } 122 }
121 } 123 }
122 if (copied_to_alternate_path_ && 124 if (copied_to_alternate_path_ &&
123 !base::DeleteFile(alternative_path_, true)) { 125 !base::DeleteFile(alternative_path_, true)) {
124 LOG(ERROR) << "Can not delete " << alternative_path_.value(); 126 LOG(ERROR) << "Can not delete " << alternative_path_.value();
125 } 127 }
126 } 128 }
127 129
128 bool CopyTreeWorkItem::IsFileInUse(const base::FilePath& path) { 130 bool CopyTreeWorkItem::IsFileInUse(const base::FilePath& path) {
129 if (!base::PathExists(path)) 131 if (!base::PathExists(path))
130 return false; 132 return false;
131 133
132 HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS, 134 HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS,
133 NULL, NULL, OPEN_EXISTING, NULL, NULL); 135 NULL, NULL, OPEN_EXISTING, NULL, NULL);
134 if (handle == INVALID_HANDLE_VALUE) 136 if (handle == INVALID_HANDLE_VALUE)
135 return true; 137 return true;
136 138
137 CloseHandle(handle); 139 CloseHandle(handle);
138 return false; 140 return false;
139 } 141 }
OLDNEW
« no previous file with comments | « chrome/installer/util/copy_tree_work_item.h ('k') | chrome/installer/util/copy_tree_work_item_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698