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

Side by Side Diff: chrome/installer/setup/install.cc

Issue 39048: Move files instead of copying them. (Closed)
Patch Set: More code review comments. Created 11 years, 9 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
« no previous file with comments | « no previous file | chrome/installer/util/installer_unittests.vcproj » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <time.h> 5 #include <time.h>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/registry.h" 8 #include "base/registry.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 std::wstring exe_dst(installer_dir); 102 std::wstring exe_dst(installer_dir);
103 std::wstring archive_dst(installer_dir); 103 std::wstring archive_dst(installer_dir);
104 file_util::AppendToPath(&exe_dst, 104 file_util::AppendToPath(&exe_dst,
105 file_util::GetFilenameFromPath(exe_path)); 105 file_util::GetFilenameFromPath(exe_path));
106 file_util::AppendToPath(&archive_dst, 106 file_util::AppendToPath(&archive_dst,
107 file_util::GetFilenameFromPath(archive_path)); 107 file_util::GetFilenameFromPath(archive_path));
108 108
109 install_list->AddCopyTreeWorkItem(exe_path, exe_dst, temp_path, 109 install_list->AddCopyTreeWorkItem(exe_path, exe_dst, temp_path,
110 WorkItem::ALWAYS); 110 WorkItem::ALWAYS);
111 install_list->AddCopyTreeWorkItem(archive_path, archive_dst, temp_path, 111 install_list->AddMoveTreeWorkItem(archive_path, archive_dst, temp_path);
112 WorkItem::ALWAYS);
113 } 112 }
114 113
115 114
116 // This method tells if we are running on 64 bit platform so that we can copy 115 // This method tells if we are running on 64 bit platform so that we can copy
117 // one extra exe. If the API call to determine 64 bit fails, we play it safe 116 // one extra exe. If the API call to determine 64 bit fails, we play it safe
118 // and return true anyway so that the executable can be copied. 117 // and return true anyway so that the executable can be copied.
119 bool Is64bit() { 118 bool Is64bit() {
120 typedef BOOL (WINAPI *WOW_FUNC)(HANDLE, PBOOL); 119 typedef BOOL (WINAPI *WOW_FUNC)(HANDLE, PBOOL);
121 BOOL is64 = FALSE; 120 BOOL is64 = FALSE;
122 121
(...skipping 19 matching lines...) Expand all
142 const Version& new_version) { 141 const Version& new_version) {
143 142
144 if (reg_root != HKEY_LOCAL_MACHINE && reg_root != HKEY_CURRENT_USER) 143 if (reg_root != HKEY_LOCAL_MACHINE && reg_root != HKEY_CURRENT_USER)
145 return false; 144 return false;
146 145
147 scoped_ptr<WorkItemList> install_list(WorkItem::CreateWorkItemList()); 146 scoped_ptr<WorkItemList> install_list(WorkItem::CreateWorkItemList());
148 // A temp directory that work items need and the actual install directory. 147 // A temp directory that work items need and the actual install directory.
149 install_list->AddCreateDirWorkItem(temp_dir); 148 install_list->AddCreateDirWorkItem(temp_dir);
150 install_list->AddCreateDirWorkItem(install_path); 149 install_list->AddCreateDirWorkItem(install_path);
151 150
152 // Copy the version folder 151 // Move the version folder
153 install_list->AddCopyTreeWorkItem( 152 install_list->AddMoveTreeWorkItem(
154 AppendPath(src_path, new_version.GetString()), 153 AppendPath(src_path, new_version.GetString()),
155 AppendPath(install_path, new_version.GetString()), 154 AppendPath(install_path, new_version.GetString()),
156 temp_dir, WorkItem::ALWAYS); // Always overwrite. 155 temp_dir);
157 156
158 // Delete any new_chrome.exe if present (we will end up create a new one 157 // Delete any new_chrome.exe if present (we will end up create a new one
159 // if required) and then copy chrome.exe 158 // if required) and then copy chrome.exe
160 std::wstring new_chrome_exe = AppendPath(install_path, 159 std::wstring new_chrome_exe = AppendPath(install_path,
161 installer_util::kChromeNewExe); 160 installer_util::kChromeNewExe);
162 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 161 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
163 RegKey chrome_key(reg_root, dist->GetVersionKey().c_str(), KEY_READ); 162 RegKey chrome_key(reg_root, dist->GetVersionKey().c_str(), KEY_READ);
164 std::wstring current_version; 163 std::wstring current_version;
165 if (file_util::PathExists(new_chrome_exe)) 164 if (file_util::PathExists(new_chrome_exe))
166 chrome_key.ReadValue(google_update::kRegOldVersionField, &current_version); 165 chrome_key.ReadValue(google_update::kRegOldVersionField, &current_version);
167 if (current_version.empty()) 166 if (current_version.empty())
168 chrome_key.ReadValue(google_update::kRegVersionField, &current_version); 167 chrome_key.ReadValue(google_update::kRegVersionField, &current_version);
169 chrome_key.Close(); 168 chrome_key.Close();
170 169
171 install_list->AddDeleteTreeWorkItem(new_chrome_exe, std::wstring()); 170 install_list->AddDeleteTreeWorkItem(new_chrome_exe, std::wstring());
172 install_list->AddCopyTreeWorkItem( 171 install_list->AddCopyTreeWorkItem(
173 AppendPath(src_path, installer_util::kChromeExe), 172 AppendPath(src_path, installer_util::kChromeExe),
174 AppendPath(install_path, installer_util::kChromeExe), 173 AppendPath(install_path, installer_util::kChromeExe),
175 temp_dir, WorkItem::NEW_NAME_IF_IN_USE, new_chrome_exe); 174 temp_dir, WorkItem::NEW_NAME_IF_IN_USE, new_chrome_exe);
176 175
177 // Extra executable for 64 bit systems. 176 // Extra executable for 64 bit systems.
178 if (Is64bit()) { 177 if (Is64bit()) {
179 install_list->AddCopyTreeWorkItem( 178 install_list->AddMoveTreeWorkItem(
180 AppendPath(src_path, installer::kWowHelperExe), 179 AppendPath(src_path, installer::kWowHelperExe),
181 AppendPath(install_path, installer::kWowHelperExe), 180 AppendPath(install_path, installer::kWowHelperExe),
182 temp_dir, WorkItem::ALWAYS); 181 temp_dir);
183 } 182 }
184 183
185 // Copy the default Dictionaries only if the folder doesnt exist already 184 // Copy the default Dictionaries only if the folder doesnt exist already
186 install_list->AddCopyTreeWorkItem( 185 install_list->AddCopyTreeWorkItem(
187 AppendPath(src_path, installer::kDictionaries), 186 AppendPath(src_path, installer::kDictionaries),
188 AppendPath(install_path, installer::kDictionaries), 187 AppendPath(install_path, installer::kDictionaries),
189 temp_dir, WorkItem::IF_NOT_PRESENT); 188 temp_dir, WorkItem::IF_NOT_PRESENT);
190 189
191 // Copy installer in install directory and 190 // Copy installer in install directory and
192 // add shortcut in Control Panel->Add/Remove Programs. 191 // add shortcut in Control Panel->Add/Remove Programs.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 269 }
271 270
272 if (!success) { 271 if (!success) {
273 LOG(ERROR) << "Install failed, rolling back... "; 272 LOG(ERROR) << "Install failed, rolling back... ";
274 install_list->Rollback(); 273 install_list->Rollback();
275 LOG(ERROR) << "Rollback complete. "; 274 LOG(ERROR) << "Rollback complete. ";
276 } 275 }
277 return success; 276 return success;
278 } 277 }
279 278
OLDNEW
« no previous file with comments | « no previous file | chrome/installer/util/installer_unittests.vcproj » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698