| OLD | NEW | 
|     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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   457 }; |   457 }; | 
|   458  |   458  | 
|   459 static const char* kInstallOperationTypes[] = { |   459 static const char* kInstallOperationTypes[] = { | 
|   460   "REPLACE", |   460   "REPLACE", | 
|   461   "REPLACE_BZ", |   461   "REPLACE_BZ", | 
|   462   "MOVE", |   462   "MOVE", | 
|   463   "BSDIFF" |   463   "BSDIFF" | 
|   464 }; |   464 }; | 
|   465  |   465  | 
|   466 void ReportPayloadUsage(const Graph& graph, |   466 void ReportPayloadUsage(const Graph& graph, | 
|   467                         const DeltaArchiveManifest& manifest) { |   467                         const DeltaArchiveManifest& manifest, | 
 |   468                         const int64_t manifest_metadata_size) { | 
|   468   vector<DeltaObject> objects; |   469   vector<DeltaObject> objects; | 
|   469   off_t total_size = 0; |   470   off_t total_size = 0; | 
|   470  |   471  | 
|   471   // Graph nodes with information about file names. |   472   // Graph nodes with information about file names. | 
|   472   for (Vertex::Index node = 0; node < graph.size(); node++) { |   473   for (Vertex::Index node = 0; node < graph.size(); node++) { | 
|   473     const Vertex& vertex = graph[node]; |   474     const Vertex& vertex = graph[node]; | 
|   474     if (!vertex.valid) { |   475     if (!vertex.valid) { | 
|   475       continue; |   476       continue; | 
|   476     } |   477     } | 
|   477     objects.push_back(DeltaObject(vertex.file_name, |   478     objects.push_back(DeltaObject(vertex.file_name, | 
|   478                                   vertex.op.type(), |   479                                   vertex.op.type(), | 
|   479                                   vertex.op.data_length())); |   480                                   vertex.op.data_length())); | 
|   480     total_size += vertex.op.data_length(); |   481     total_size += vertex.op.data_length(); | 
|   481   } |   482   } | 
|   482  |   483  | 
|   483   // Kernel install operations. |   484   // Kernel install operations. | 
|   484   for (int i = 0; i < manifest.kernel_install_operations_size(); ++i) { |   485   for (int i = 0; i < manifest.kernel_install_operations_size(); ++i) { | 
|   485     const DeltaArchiveManifest_InstallOperation& op = |   486     const DeltaArchiveManifest_InstallOperation& op = | 
|   486         manifest.kernel_install_operations(i); |   487         manifest.kernel_install_operations(i); | 
|   487     objects.push_back(DeltaObject(StringPrintf("<kernel-operation-%d>", i), |   488     objects.push_back(DeltaObject(StringPrintf("<kernel-operation-%d>", i), | 
|   488                                   op.type(), |   489                                   op.type(), | 
|   489                                   op.data_length())); |   490                                   op.data_length())); | 
|   490     total_size += op.data_length(); |   491     total_size += op.data_length(); | 
|   491   } |   492   } | 
|   492  |   493  | 
 |   494   objects.push_back(DeltaObject("<manifest-metadata>", | 
 |   495                                 -1, | 
 |   496                                 manifest_metadata_size)); | 
 |   497   total_size += manifest_metadata_size; | 
 |   498  | 
|   493   std::sort(objects.begin(), objects.end()); |   499   std::sort(objects.begin(), objects.end()); | 
|   494  |   500  | 
|   495   static const char kFormatString[] = "%6.2f%% %10llu %-10s %s\n"; |   501   static const char kFormatString[] = "%6.2f%% %10llu %-10s %s\n"; | 
|   496   for (vector<DeltaObject>::const_iterator it = objects.begin(); |   502   for (vector<DeltaObject>::const_iterator it = objects.begin(); | 
|   497        it != objects.end(); ++it) { |   503        it != objects.end(); ++it) { | 
|   498     const DeltaObject& object = *it; |   504     const DeltaObject& object = *it; | 
|   499     fprintf(stderr, kFormatString, |   505     fprintf(stderr, kFormatString, | 
|   500             object.size * 100.0 / total_size, |   506             object.size * 100.0 / total_size, | 
|   501             object.size, |   507             object.size, | 
|   502             kInstallOperationTypes[object.type], |   508             object.type >= 0 ? kInstallOperationTypes[object.type] : "-", | 
|   503             object.name.c_str()); |   509             object.name.c_str()); | 
|   504   } |   510   } | 
|   505   fprintf(stderr, kFormatString, 100.0, total_size, "", "<total>"); |   511   fprintf(stderr, kFormatString, 100.0, total_size, "", "<total>"); | 
|   506 } |   512 } | 
|   507  |   513  | 
|   508 }  // namespace {} |   514 }  // namespace {} | 
|   509  |   515  | 
|   510 bool DeltaDiffGenerator::ReadFileToDiff( |   516 bool DeltaDiffGenerator::ReadFileToDiff( | 
|   511     const string& old_filename, |   517     const string& old_filename, | 
|   512     const string& new_filename, |   518     const string& new_filename, | 
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1475     LOG(INFO) << "Signing the update..."; |  1481     LOG(INFO) << "Signing the update..."; | 
|  1476     vector<char> signature_blob; |  1482     vector<char> signature_blob; | 
|  1477     TEST_AND_RETURN_FALSE(PayloadSigner::SignPayload(output_path, |  1483     TEST_AND_RETURN_FALSE(PayloadSigner::SignPayload(output_path, | 
|  1478                                                      private_key_path, |  1484                                                      private_key_path, | 
|  1479                                                      &signature_blob)); |  1485                                                      &signature_blob)); | 
|  1480     TEST_AND_RETURN_FALSE(writer.Write(&signature_blob[0], |  1486     TEST_AND_RETURN_FALSE(writer.Write(&signature_blob[0], | 
|  1481                                        signature_blob.size()) == |  1487                                        signature_blob.size()) == | 
|  1482                           static_cast<ssize_t>(signature_blob.size())); |  1488                           static_cast<ssize_t>(signature_blob.size())); | 
|  1483   } |  1489   } | 
|  1484  |  1490  | 
|  1485   ReportPayloadUsage(graph, manifest); |  1491   int64_t manifest_metadata_size = | 
 |  1492       strlen(kDeltaMagic) + 2 * sizeof(uint64_t) + serialized_manifest.size(); | 
 |  1493   ReportPayloadUsage(graph, manifest, manifest_metadata_size); | 
|  1486  |  1494  | 
|  1487   LOG(INFO) << "All done. Successfully created delta file."; |  1495   LOG(INFO) << "All done. Successfully created delta file."; | 
|  1488   return true; |  1496   return true; | 
|  1489 } |  1497 } | 
|  1490  |  1498  | 
|  1491 const char* const kBsdiffPath = "/usr/bin/bsdiff"; |  1499 const char* const kBsdiffPath = "/usr/bin/bsdiff"; | 
|  1492 const char* const kBspatchPath = "/usr/bin/bspatch"; |  1500 const char* const kBspatchPath = "/usr/bin/bspatch"; | 
|  1493 const char* const kDeltaMagic = "CrAU"; |  1501 const char* const kDeltaMagic = "CrAU"; | 
|  1494  |  1502  | 
|  1495 };  // namespace chromeos_update_engine |  1503 };  // namespace chromeos_update_engine | 
| OLD | NEW |