OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file declares util functions for setup project. | 5 // This file declares util functions for setup project. |
6 | 6 |
7 #include "chrome/installer/setup/setup_util.h" | 7 #include "chrome/installer/setup/setup_util.h" |
8 | 8 |
9 #include <windows.h> | 9 #include <windows.h> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/files/file_enumerator.h" | 13 #include "base/files/file_enumerator.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/process_util.h" | 16 #include "base/process_util.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/version.h" | 18 #include "base/version.h" |
19 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
20 #include "chrome/installer/util/copy_tree_work_item.h" | 20 #include "chrome/installer/util/copy_tree_work_item.h" |
21 #include "chrome/installer/util/installation_state.h" | 21 #include "chrome/installer/util/installation_state.h" |
22 #include "chrome/installer/util/installer_state.h" | 22 #include "chrome/installer/util/installer_state.h" |
23 #include "chrome/installer/util/master_preferences.h" | 23 #include "chrome/installer/util/master_preferences.h" |
24 #include "chrome/installer/util/util_constants.h" | 24 #include "chrome/installer/util/util_constants.h" |
25 #include "chrome/installer/util/work_item.h" | 25 #include "chrome/installer/util/work_item.h" |
26 #include "courgette/courgette.h" | 26 #include "courgette/courgette.h" |
27 #include "courgette/third_party/bsdiff.h" | |
27 #include "third_party/bspatch/mbspatch.h" | 28 #include "third_party/bspatch/mbspatch.h" |
28 | 29 |
29 namespace installer { | 30 namespace installer { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 // Launches |setup_exe| with |command_line|, save --install-archive and its | 34 // Launches |setup_exe| with |command_line|, save --install-archive and its |
34 // value if present. Returns false if the process failed to launch. Otherwise, | 35 // value if present. Returns false if the process failed to launch. Otherwise, |
35 // waits indefinitely for it to exit and populates |exit_code| as expected. On | 36 // waits indefinitely for it to exit and populates |exit_code| as expected. On |
36 // the off chance that waiting itself fails, |exit_code| is set to | 37 // the off chance that waiting itself fails, |exit_code| is set to |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 80 |
80 // Returns true if product |type| cam be meaningfully installed without the | 81 // Returns true if product |type| cam be meaningfully installed without the |
81 // --multi-install flag. | 82 // --multi-install flag. |
82 bool SupportsSingleInstall(BrowserDistribution::Type type) { | 83 bool SupportsSingleInstall(BrowserDistribution::Type type) { |
83 return (type == BrowserDistribution::CHROME_BROWSER || | 84 return (type == BrowserDistribution::CHROME_BROWSER || |
84 type == BrowserDistribution::CHROME_FRAME); | 85 type == BrowserDistribution::CHROME_FRAME); |
85 } | 86 } |
86 | 87 |
87 } // namespace | 88 } // namespace |
88 | 89 |
90 int CourgettePatchFiles(const base::FilePath& src, | |
91 const base::FilePath& patch, | |
92 const base::FilePath& dest) { | |
93 LOG(WARNING) << "Applying Courgette patch " << patch.value() << " to file " | |
grt (UTC plus 2)
2013/06/20 14:04:14
Seems like an "installer logging" style guide is i
Sorin Jianu
2013/06/20 17:40:15
Done.
| |
94 << src.value() << " and generating file " << dest.value(); | |
95 | |
96 if (src.empty() || patch.empty() || dest.empty()) | |
97 return installer::PATCH_INVALID_ARGUMENTS; | |
grt (UTC plus 2)
2013/06/20 14:04:14
nit: only indent two spaces
Sorin Jianu
2013/06/20 17:40:15
Done.
| |
98 | |
99 const courgette::Status patch_status = | |
100 courgette::ApplyEnsemblePatch(src.value().c_str(), | |
101 patch.value().c_str(), | |
102 dest.value().c_str()); | |
103 const int exit_code = (patch_status != courgette::C_OK) ? | |
104 static_cast<int>(patch_status) + kCourgetteErrorOffset : 0; | |
105 | |
106 LOG_IF(ERROR, exit_code) << "Failed to apply patch " << patch.value() | |
107 << ". err=" << exit_code; | |
108 return exit_code; | |
109 } | |
110 | |
111 int BsdiffPatchFiles(const base::FilePath& src, | |
112 const base::FilePath& patch, | |
113 const base::FilePath& dest) { | |
114 LOG(WARNING) << "Applying bsdiff patch " << patch.value() << " to file " | |
115 << src.value() << " and generating file " << dest.value(); | |
116 | |
117 if (src.empty() || patch.empty() || dest.empty()) | |
118 return installer::PATCH_INVALID_ARGUMENTS; | |
grt (UTC plus 2)
2013/06/20 14:04:14
nit: only indent two spaces
Sorin Jianu
2013/06/20 17:40:15
Done.
| |
119 | |
120 const int patch_status = courgette::ApplyBinaryPatch(src, patch, dest); | |
121 const int exit_code = patch_status ? | |
122 patch_status + kBsdiffErrorOffset : 0; | |
123 | |
124 LOG_IF(ERROR, exit_code) << "Failed to apply patch " << patch.value() | |
125 << ". err=" << exit_code; | |
126 return exit_code; | |
127 } | |
128 | |
89 int ApplyDiffPatch(const base::FilePath& src, | 129 int ApplyDiffPatch(const base::FilePath& src, |
90 const base::FilePath& patch, | 130 const base::FilePath& patch, |
91 const base::FilePath& dest, | 131 const base::FilePath& dest, |
92 const InstallerState* installer_state) { | 132 const InstallerState* installer_state) { |
93 VLOG(1) << "Applying patch " << patch.value() << " to file " << src.value() | 133 LOG(WARNING) << "Applying patch " << patch.value() << " to file " |
94 << " and generating file " << dest.value(); | 134 << src.value() << " and generating file " << dest.value(); |
95 | 135 |
96 if (installer_state != NULL) | 136 if (installer_state != NULL) |
97 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); | 137 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); |
98 | 138 |
99 // Try Courgette first. Courgette checks the patch file first and fails | 139 // Try Courgette first. Courgette checks the patch file first and fails |
100 // quickly if the patch file does not have a valid Courgette header. | 140 // quickly if the patch file does not have a valid Courgette header. |
101 courgette::Status patch_status = | 141 courgette::Status patch_status = |
102 courgette::ApplyEnsemblePatch(src.value().c_str(), | 142 courgette::ApplyEnsemblePatch(src.value().c_str(), |
103 patch.value().c_str(), | 143 patch.value().c_str(), |
104 dest.value().c_str()); | 144 dest.value().c_str()); |
105 if (patch_status == courgette::C_OK) | 145 if (patch_status == courgette::C_OK) |
106 return 0; | 146 return 0; |
107 | 147 |
108 VLOG(1) << "Failed to apply patch " << patch.value() | 148 LOG(ERROR) << "Failed to apply patch " << patch.value() |
109 << " using courgette. err=" << patch_status; | 149 << " using courgette. err=" << patch_status; |
110 | 150 |
111 // If we ran out of memory or disk space, then these are likely the errors | 151 // If we ran out of memory or disk space, then these are likely the errors |
112 // we will see. If we run into them, return an error and stay on the | 152 // we will see. If we run into them, return an error and stay on the |
113 // 'ENSEMBLE_PATCHING' update stage. | 153 // 'ENSEMBLE_PATCHING' update stage. |
114 if (patch_status == courgette::C_DISASSEMBLY_FAILED || | 154 if (patch_status == courgette::C_DISASSEMBLY_FAILED || |
115 patch_status == courgette::C_STREAM_ERROR) { | 155 patch_status == courgette::C_STREAM_ERROR) { |
116 return MEM_ERROR; | 156 return MEM_ERROR; |
117 } | 157 } |
118 | 158 |
119 if (installer_state != NULL) | 159 if (installer_state != NULL) |
120 installer_state->UpdateStage(installer::BINARY_PATCHING); | 160 installer_state->UpdateStage(installer::BINARY_PATCHING); |
121 | 161 |
122 return ApplyBinaryPatch(src.value().c_str(), patch.value().c_str(), | 162 int binary_patch_status = ApplyBinaryPatch(src.value().c_str(), |
123 dest.value().c_str()); | 163 patch.value().c_str(), |
164 dest.value().c_str()); | |
165 | |
166 LOG_IF(ERROR, binary_patch_status != OK) << "Failed to apply patch " | |
167 << patch.value() << " using bsdiff. err=" << binary_patch_status; | |
168 | |
169 return binary_patch_status; | |
124 } | 170 } |
125 | 171 |
126 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { | 172 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { |
127 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); | 173 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); |
128 Version* version = NULL; | 174 Version* version = NULL; |
129 base::FileEnumerator version_enum(chrome_path, false, | 175 base::FileEnumerator version_enum(chrome_path, false, |
130 base::FileEnumerator::DIRECTORIES); | 176 base::FileEnumerator::DIRECTORIES); |
131 // TODO(tommi): The version directory really should match the version of | 177 // TODO(tommi): The version directory really should match the version of |
132 // setup.exe. To begin with, we should at least DCHECK that that's true. | 178 // setup.exe. To begin with, we should at least DCHECK that that's true. |
133 | 179 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 } | 408 } |
363 | 409 |
364 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 410 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
365 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 411 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
366 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, | 412 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, |
367 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 413 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
368 } | 414 } |
369 } | 415 } |
370 | 416 |
371 } // namespace installer | 417 } // namespace installer |
OLD | NEW |