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

Side by Side Diff: delta_diff_generator.cc

Issue 3657001: AU: fix new style full updates (Closed) Base URL: ssh://git@chromiumos-git/update_engine.git
Patch Set: Created 10 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
« no previous file with comments | « no previous file | no next file » | 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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 "update_engine/delta_diff_generator.h" 5 #include "update_engine/delta_diff_generator.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <inttypes.h> 9 #include <inttypes.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 1214
1215 TEST_AND_RETURN_FALSE(BzipCompress(buf, &buf_compressed)); 1215 TEST_AND_RETURN_FALSE(BzipCompress(buf, &buf_compressed));
1216 const bool compress = buf_compressed.size() < buf.size(); 1216 const bool compress = buf_compressed.size() < buf.size();
1217 const vector<char>& use_buf = compress ? buf_compressed : buf; 1217 const vector<char>& use_buf = compress ? buf_compressed : buf;
1218 if (compress) { 1218 if (compress) {
1219 op->set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ); 1219 op->set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ);
1220 } else { 1220 } else {
1221 op->set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE); 1221 op->set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE);
1222 } 1222 }
1223 op->set_data_offset(*data_file_size); 1223 op->set_data_offset(*data_file_size);
1224 TEST_AND_RETURN_FALSE(utils::WriteAll(fd, &use_buf[0], use_buf.size()));
1224 *data_file_size += use_buf.size(); 1225 *data_file_size += use_buf.size();
1225 op->set_data_length(use_buf.size()); 1226 op->set_data_length(use_buf.size());
1226 Extent* dst_extent = op->add_dst_extents(); 1227 Extent* dst_extent = op->add_dst_extents();
1227 dst_extent->set_start_block(offset / kBlockSize); 1228 dst_extent->set_start_block(offset / kBlockSize);
1228 dst_extent->set_num_blocks(chunk_size / kBlockSize); 1229 dst_extent->set_num_blocks(chunk_size / kBlockSize);
1229 } 1230 }
1230 } 1231 }
1231 1232
1232 return true; 1233 return true;
1233 } 1234 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 1275
1275 const string kTempFileTemplate("/tmp/CrAU_temp_data.XXXXXX"); 1276 const string kTempFileTemplate("/tmp/CrAU_temp_data.XXXXXX");
1276 string temp_file_path; 1277 string temp_file_path;
1277 off_t data_file_size = 0; 1278 off_t data_file_size = 0;
1278 1279
1279 LOG(INFO) << "Reading files..."; 1280 LOG(INFO) << "Reading files...";
1280 1281
1281 vector<DeltaArchiveManifest_InstallOperation> kernel_ops; 1282 vector<DeltaArchiveManifest_InstallOperation> kernel_ops;
1282 1283
1283 vector<Vertex::Index> final_order; 1284 vector<Vertex::Index> final_order;
1284 if (!old_image.empty()) { 1285 {
1285 // Delta update
1286 int fd; 1286 int fd;
1287 TEST_AND_RETURN_FALSE( 1287 TEST_AND_RETURN_FALSE(
1288 utils::MakeTempFile(kTempFileTemplate, &temp_file_path, &fd)); 1288 utils::MakeTempFile(kTempFileTemplate, &temp_file_path, &fd));
1289 TEST_AND_RETURN_FALSE(fd >= 0); 1289 TEST_AND_RETURN_FALSE(fd >= 0);
1290 ScopedFdCloser fd_closer(&fd); 1290 ScopedFdCloser fd_closer(&fd);
1291 if (!old_image.empty()) {
1292 // Delta update
1291 1293
1292 TEST_AND_RETURN_FALSE(DeltaReadFiles(&graph, 1294 TEST_AND_RETURN_FALSE(DeltaReadFiles(&graph,
1293 &blocks, 1295 &blocks,
1294 old_root, 1296 old_root,
1295 new_root, 1297 new_root,
1296 fd, 1298 fd,
1297 &data_file_size)); 1299 &data_file_size));
1298 LOG(INFO) << "done reading normal files"; 1300 LOG(INFO) << "done reading normal files";
1299 CheckGraph(graph); 1301 CheckGraph(graph);
1300 1302
1301 graph.resize(graph.size() + 1); 1303 graph.resize(graph.size() + 1);
1302 TEST_AND_RETURN_FALSE(ReadUnwrittenBlocks(blocks, 1304 TEST_AND_RETURN_FALSE(ReadUnwrittenBlocks(blocks,
1305 fd,
1306 &data_file_size,
1307 new_image,
1308 &graph.back()));
1309
1310 // Read kernel partition
1311 TEST_AND_RETURN_FALSE(DeltaCompressKernelPartition(old_kernel_part,
1312 new_kernel_part,
1313 &kernel_ops,
1314 fd,
1315 &data_file_size));
1316
1317 LOG(INFO) << "done reading kernel";
1318 CheckGraph(graph);
1319
1320 LOG(INFO) << "Creating edges...";
1321 CreateEdges(&graph, blocks);
1322 LOG(INFO) << "Done creating edges";
1323 CheckGraph(graph);
1324
1325 TEST_AND_RETURN_FALSE(ConvertGraphToDag(&graph,
1326 new_root,
1303 fd, 1327 fd,
1304 &data_file_size, 1328 &data_file_size,
1305 new_image, 1329 &final_order));
1306 &graph.back())); 1330 } else {
1307 1331 // Full update
1308 // Read kernel partition 1332 TEST_AND_RETURN_FALSE(ReadFullUpdateFromDisk(&graph,
1309 TEST_AND_RETURN_FALSE(DeltaCompressKernelPartition(old_kernel_part, 1333 new_kernel_part,
1310 new_kernel_part, 1334 new_image,
1311 &kernel_ops, 1335 fd,
1312 fd, 1336 &data_file_size,
1313 &data_file_size)); 1337 kFullUpdateChunkSize,
1314 1338 &kernel_ops,
1315 LOG(INFO) << "done reading kernel"; 1339 &final_order));
1316 CheckGraph(graph); 1340 }
1317
1318 LOG(INFO) << "Creating edges...";
1319 CreateEdges(&graph, blocks);
1320 LOG(INFO) << "Done creating edges";
1321 CheckGraph(graph);
1322
1323 TEST_AND_RETURN_FALSE(ConvertGraphToDag(&graph,
1324 new_root,
1325 fd,
1326 &data_file_size,
1327 &final_order));
1328 } else {
1329 // Full update
1330 int fd = 0;
1331 TEST_AND_RETURN_FALSE(ReadFullUpdateFromDisk(&graph,
1332 new_kernel_part,
1333 new_image,
1334 fd,
1335 &data_file_size,
1336 kFullUpdateChunkSize,
1337 &kernel_ops,
1338 &final_order));
1339 } 1341 }
1340 1342
1341 // Convert to protobuf Manifest object 1343 // Convert to protobuf Manifest object
1342 DeltaArchiveManifest manifest; 1344 DeltaArchiveManifest manifest;
1343 CheckGraph(graph); 1345 CheckGraph(graph);
1344 InstallOperationsToManifest(graph, final_order, kernel_ops, &manifest); 1346 InstallOperationsToManifest(graph, final_order, kernel_ops, &manifest);
1345 1347
1346 CheckGraph(graph); 1348 CheckGraph(graph);
1347 manifest.set_block_size(kBlockSize); 1349 manifest.set_block_size(kBlockSize);
1348 1350
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 LOG(INFO) << "Signing the update..."; 1477 LOG(INFO) << "Signing the update...";
1476 vector<char> signature_blob; 1478 vector<char> signature_blob;
1477 TEST_AND_RETURN_FALSE(PayloadSigner::SignPayload(output_path, 1479 TEST_AND_RETURN_FALSE(PayloadSigner::SignPayload(output_path,
1478 private_key_path, 1480 private_key_path,
1479 &signature_blob)); 1481 &signature_blob));
1480 TEST_AND_RETURN_FALSE(writer.Write(&signature_blob[0], 1482 TEST_AND_RETURN_FALSE(writer.Write(&signature_blob[0],
1481 signature_blob.size()) == 1483 signature_blob.size()) ==
1482 static_cast<ssize_t>(signature_blob.size())); 1484 static_cast<ssize_t>(signature_blob.size()));
1483 } 1485 }
1484 1486
1487 LOG(INFO) << "final dump";
1488 graph_utils::DumpGraph(graph);
1485 ReportPayloadUsage(graph, manifest); 1489 ReportPayloadUsage(graph, manifest);
1486 1490
1487 LOG(INFO) << "All done. Successfully created delta file."; 1491 LOG(INFO) << "All done. Successfully created delta file.";
1488 return true; 1492 return true;
1489 } 1493 }
1490 1494
1491 const char* const kBsdiffPath = "/usr/bin/bsdiff"; 1495 const char* const kBsdiffPath = "/usr/bin/bsdiff";
1492 const char* const kBspatchPath = "/usr/bin/bspatch"; 1496 const char* const kBspatchPath = "/usr/bin/bspatch";
1493 const char* const kDeltaMagic = "CrAU"; 1497 const char* const kDeltaMagic = "CrAU";
1494 1498
1495 }; // namespace chromeos_update_engine 1499 }; // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698