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 VLOG(1) << "Applying Courgette patch " << patch.value() |
| 94 << " to file " << src.value() |
| 95 << " and generating file " << dest.value(); |
| 96 |
| 97 if (src.empty() || patch.empty() || dest.empty()) |
| 98 return installer::PATCH_INVALID_ARGUMENTS; |
| 99 |
| 100 const courgette::Status patch_status = |
| 101 courgette::ApplyEnsemblePatch(src.value().c_str(), |
| 102 patch.value().c_str(), |
| 103 dest.value().c_str()); |
| 104 const int exit_code = (patch_status != courgette::C_OK) ? |
| 105 static_cast<int>(patch_status) + kCourgetteErrorOffset : 0; |
| 106 |
| 107 LOG_IF(ERROR, exit_code) |
| 108 << "Failed to apply Courgette patch " << patch.value() |
| 109 << " to file " << src.value() << " and generating file " << dest.value() |
| 110 << ". err=" << exit_code; |
| 111 |
| 112 return exit_code; |
| 113 } |
| 114 |
| 115 int BsdiffPatchFiles(const base::FilePath& src, |
| 116 const base::FilePath& patch, |
| 117 const base::FilePath& dest) { |
| 118 VLOG(1) << "Applying bsdiff patch " << patch.value() |
| 119 << " to file " << src.value() |
| 120 << " and generating file " << dest.value(); |
| 121 |
| 122 if (src.empty() || patch.empty() || dest.empty()) |
| 123 return installer::PATCH_INVALID_ARGUMENTS; |
| 124 |
| 125 const int patch_status = courgette::ApplyBinaryPatch(src, patch, dest); |
| 126 const int exit_code = patch_status != OK ? |
| 127 patch_status + kBsdiffErrorOffset : 0; |
| 128 |
| 129 LOG_IF(ERROR, exit_code) |
| 130 << "Failed to apply bsdiff patch " << patch.value() |
| 131 << " to file " << src.value() << " and generating file " << dest.value() |
| 132 << ". err=" << exit_code; |
| 133 |
| 134 return exit_code; |
| 135 } |
| 136 |
89 int ApplyDiffPatch(const base::FilePath& src, | 137 int ApplyDiffPatch(const base::FilePath& src, |
90 const base::FilePath& patch, | 138 const base::FilePath& patch, |
91 const base::FilePath& dest, | 139 const base::FilePath& dest, |
92 const InstallerState* installer_state) { | 140 const InstallerState* installer_state) { |
93 VLOG(1) << "Applying patch " << patch.value() << " to file " << src.value() | 141 VLOG(1) << "Applying patch " << patch.value() << " to file " |
94 << " and generating file " << dest.value(); | 142 << src.value() << " and generating file " << dest.value(); |
95 | 143 |
96 if (installer_state != NULL) | 144 if (installer_state != NULL) |
97 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); | 145 installer_state->UpdateStage(installer::ENSEMBLE_PATCHING); |
98 | 146 |
99 // Try Courgette first. Courgette checks the patch file first and fails | 147 // Try Courgette first. Courgette checks the patch file first and fails |
100 // quickly if the patch file does not have a valid Courgette header. | 148 // quickly if the patch file does not have a valid Courgette header. |
101 courgette::Status patch_status = | 149 courgette::Status patch_status = |
102 courgette::ApplyEnsemblePatch(src.value().c_str(), | 150 courgette::ApplyEnsemblePatch(src.value().c_str(), |
103 patch.value().c_str(), | 151 patch.value().c_str(), |
104 dest.value().c_str()); | 152 dest.value().c_str()); |
105 if (patch_status == courgette::C_OK) | 153 if (patch_status == courgette::C_OK) |
106 return 0; | 154 return 0; |
107 | 155 |
108 VLOG(1) << "Failed to apply patch " << patch.value() | 156 LOG(ERROR) |
109 << " using courgette. err=" << patch_status; | 157 << "Failed to apply patch " << patch.value() |
| 158 << " to file " << src.value() << " and generating file " << dest.value() |
| 159 << " using courgette. err=" << patch_status; |
110 | 160 |
111 // If we ran out of memory or disk space, then these are likely the errors | 161 // 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 | 162 // we will see. If we run into them, return an error and stay on the |
113 // 'ENSEMBLE_PATCHING' update stage. | 163 // 'ENSEMBLE_PATCHING' update stage. |
114 if (patch_status == courgette::C_DISASSEMBLY_FAILED || | 164 if (patch_status == courgette::C_DISASSEMBLY_FAILED || |
115 patch_status == courgette::C_STREAM_ERROR) { | 165 patch_status == courgette::C_STREAM_ERROR) { |
116 return MEM_ERROR; | 166 return MEM_ERROR; |
117 } | 167 } |
118 | 168 |
119 if (installer_state != NULL) | 169 if (installer_state != NULL) |
120 installer_state->UpdateStage(installer::BINARY_PATCHING); | 170 installer_state->UpdateStage(installer::BINARY_PATCHING); |
121 | 171 |
122 return ApplyBinaryPatch(src.value().c_str(), patch.value().c_str(), | 172 int binary_patch_status = ApplyBinaryPatch(src.value().c_str(), |
123 dest.value().c_str()); | 173 patch.value().c_str(), |
| 174 dest.value().c_str()); |
| 175 |
| 176 LOG_IF(ERROR, binary_patch_status != OK) |
| 177 << "Failed to apply patch " << patch.value() |
| 178 << " to file " << src.value() << " and generating file " << dest.value() |
| 179 << " using bsdiff. err=" << binary_patch_status; |
| 180 |
| 181 return binary_patch_status; |
124 } | 182 } |
125 | 183 |
126 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { | 184 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path) { |
127 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); | 185 VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); |
128 Version* version = NULL; | 186 Version* version = NULL; |
129 base::FileEnumerator version_enum(chrome_path, false, | 187 base::FileEnumerator version_enum(chrome_path, false, |
130 base::FileEnumerator::DIRECTORIES); | 188 base::FileEnumerator::DIRECTORIES); |
131 // TODO(tommi): The version directory really should match the version of | 189 // 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. | 190 // setup.exe. To begin with, we should at least DCHECK that that's true. |
133 | 191 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 420 } |
363 | 421 |
364 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 422 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
365 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 423 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
366 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, | 424 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, |
367 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 425 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
368 } | 426 } |
369 } | 427 } |
370 | 428 |
371 } // namespace installer | 429 } // namespace installer |
OLD | NEW |