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

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

Issue 1700453002: Update lzma_sdk sources to 15.14. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium modifications Created 4 years, 10 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 | « chrome/installer/util/lzma_file_allocator.h ('k') | third_party/lzma_sdk/7z.h » ('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) 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 #include "chrome/installer/util/lzma_util.h" 5 #include "chrome/installer/util/lzma_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return ERROR_INVALID_HANDLE; 156 return ERROR_INVALID_HANDLE;
157 } 157 }
158 158
159 Byte* outBuffer = 0; // it must be 0 before first call for each new archive 159 Byte* outBuffer = 0; // it must be 0 before first call for each new archive
160 UInt32 blockIndex = 0xFFFFFFFF; // can have any value if outBuffer = 0 160 UInt32 blockIndex = 0xFFFFFFFF; // can have any value if outBuffer = 0
161 size_t outBufferSize = 0; // can have any value if outBuffer = 0 161 size_t outBufferSize = 0; // can have any value if outBuffer = 0
162 162
163 // Extra parentheses are needed here to avoid the most vexing parse. 163 // Extra parentheses are needed here to avoid the most vexing parse.
164 LzmaFileAllocator fileAllocator((base::FilePath(location))); 164 LzmaFileAllocator fileAllocator((base::FilePath(location)));
165 165
166 for (unsigned int i = 0; i < db.db.NumFiles; i++) { 166 for (unsigned int i = 0; i < db.NumFiles; i++) {
167 DWORD written; 167 DWORD written;
168 size_t offset; 168 size_t offset;
169 size_t outSizeProcessed; 169 size_t outSizeProcessed;
170 CSzFileItem *f = db.db.Files + i;
171 170
172 if ((ret = SzArEx_Extract(&db, &lookStream.s, i, &blockIndex, &outBuffer, 171 if ((ret = SzArEx_Extract(&db, &lookStream.s, i, &blockIndex, &outBuffer,
173 &outBufferSize, &offset, &outSizeProcessed, 172 &outBufferSize, &offset, &outSizeProcessed,
174 &fileAllocator, &allocTempImp)) != SZ_OK) { 173 &fileAllocator, &allocTempImp)) != SZ_OK) {
175 LOG(ERROR) << L"Error returned by SzExtract: " << ret; 174 LOG(ERROR) << L"Error returned by SzExtract: " << ret;
176 ret = ERROR_INVALID_HANDLE; 175 ret = ERROR_INVALID_HANDLE;
177 break; 176 break;
178 } 177 }
179 178
180 size_t file_name_length = SzArEx_GetFileNameUtf16(&db, i, NULL); 179 size_t file_name_length = SzArEx_GetFileNameUtf16(&db, i, NULL);
181 if (file_name_length < 1) { 180 if (file_name_length < 1) {
182 LOG(ERROR) << L"Couldn't get file name"; 181 LOG(ERROR) << L"Couldn't get file name";
183 ret = ERROR_INVALID_HANDLE; 182 ret = ERROR_INVALID_HANDLE;
184 break; 183 break;
185 } 184 }
186 185
187 std::vector<UInt16> file_name(file_name_length); 186 std::vector<UInt16> file_name(file_name_length);
188 SzArEx_GetFileNameUtf16(&db, i, &file_name[0]); 187 SzArEx_GetFileNameUtf16(&db, i, &file_name[0]);
189 // |file_name| is NULL-terminated. 188 // |file_name| is NULL-terminated.
190 base::FilePath file_path = base::FilePath(location).Append( 189 base::FilePath file_path = base::FilePath(location).Append(
191 base::FilePath::StringType(file_name.begin(), file_name.end() - 1)); 190 base::FilePath::StringType(file_name.begin(), file_name.end() - 1));
192 191
193 if (output_file) 192 if (output_file)
194 *output_file = file_path.value(); 193 *output_file = file_path.value();
195 194
196 // If archive entry is directory create it and move on to the next entry. 195 // If archive entry is directory create it and move on to the next entry.
197 if (f->IsDir) { 196 if (SzArEx_IsDir(&db, i)) {
198 CreateDirectory(file_path); 197 CreateDirectory(file_path);
199 continue; 198 continue;
200 } 199 }
201 200
202 CreateDirectory(file_path.DirName()); 201 CreateDirectory(file_path.DirName());
203 202
204 HANDLE hFile; 203 HANDLE hFile;
205 hFile = CreateFile(file_path.value().c_str(), GENERIC_WRITE, 0, NULL, 204 hFile = CreateFile(file_path.value().c_str(), GENERIC_WRITE, 0, NULL,
206 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 205 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
207 if (hFile == INVALID_HANDLE_VALUE) { 206 if (hFile == INVALID_HANDLE_VALUE) {
208 ret = GetLastError(); 207 ret = GetLastError();
209 LOG(ERROR) << L"Error returned by CreateFile: " << ret; 208 LOG(ERROR) << L"Error returned by CreateFile: " << ret;
210 break; 209 break;
211 } 210 }
212 211
213 if ((!WriteFile(hFile, outBuffer + offset, (DWORD) outSizeProcessed, 212 if ((!WriteFile(hFile, outBuffer + offset, (DWORD) outSizeProcessed,
214 &written, NULL)) || 213 &written, NULL)) ||
215 (written != outSizeProcessed)) { 214 (written != outSizeProcessed)) {
216 ret = GetLastError(); 215 ret = GetLastError();
217 CloseHandle(hFile); 216 CloseHandle(hFile);
218 LOG(ERROR) << L"Error returned by WriteFile: " << ret; 217 LOG(ERROR) << L"Error returned by WriteFile: " << ret;
219 break; 218 break;
220 } 219 }
221 220
222 if (f->MTimeDefined) { 221 if (SzBitWithVals_Check(&db.MTime, i)) {
223 if (!SetFileTime(hFile, NULL, NULL, 222 if (!SetFileTime(hFile, NULL, NULL,
224 (const FILETIME *)&(f->MTime))) { 223 (const FILETIME *) (&db.MTime.Vals[i]))) {
225 ret = GetLastError(); 224 ret = GetLastError();
226 CloseHandle(hFile); 225 CloseHandle(hFile);
227 LOG(ERROR) << L"Error returned by SetFileTime: " << ret; 226 LOG(ERROR) << L"Error returned by SetFileTime: " << ret;
228 break; 227 break;
229 } 228 }
230 } 229 }
231 if (!CloseHandle(hFile)) { 230 if (!CloseHandle(hFile)) {
232 ret = GetLastError(); 231 ret = GetLastError();
233 LOG(ERROR) << L"Error returned by CloseHandle: " << ret; 232 LOG(ERROR) << L"Error returned by CloseHandle: " << ret;
234 break; 233 break;
(...skipping 13 matching lines...) Expand all
248 247
249 bool LzmaUtil::CreateDirectory(const base::FilePath& dir) { 248 bool LzmaUtil::CreateDirectory(const base::FilePath& dir) {
250 bool ret = true; 249 bool ret = true;
251 if (directories_created_.find(dir.value()) == directories_created_.end()) { 250 if (directories_created_.find(dir.value()) == directories_created_.end()) {
252 ret = base::CreateDirectory(dir); 251 ret = base::CreateDirectory(dir);
253 if (ret) 252 if (ret)
254 directories_created_.insert(dir.value()); 253 directories_created_.insert(dir.value());
255 } 254 }
256 return ret; 255 return ret;
257 } 256 }
OLDNEW
« no previous file with comments | « chrome/installer/util/lzma_file_allocator.h ('k') | third_party/lzma_sdk/7z.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698