| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "update_engine/delta_diff_generator.h" | 5 #include "update_engine/delta_diff_generator.h" |
| 6 #include <sys/stat.h> | 6 #include <sys/stat.h> |
| 7 #include <sys/types.h> | 7 #include <sys/types.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> | 14 #include <vector> |
| 15 #include <bzlib.h> | 15 #include <bzlib.h> |
| 16 #include "chromeos/obsolete_logging.h" | 16 #include "base/logging.h" |
| 17 #include "update_engine/bzip.h" | 17 #include "update_engine/bzip.h" |
| 18 #include "update_engine/cycle_breaker.h" | 18 #include "update_engine/cycle_breaker.h" |
| 19 #include "update_engine/extent_mapper.h" | 19 #include "update_engine/extent_mapper.h" |
| 20 #include "update_engine/file_writer.h" | 20 #include "update_engine/file_writer.h" |
| 21 #include "update_engine/filesystem_iterator.h" | 21 #include "update_engine/filesystem_iterator.h" |
| 22 #include "update_engine/graph_types.h" | 22 #include "update_engine/graph_types.h" |
| 23 #include "update_engine/graph_utils.h" | 23 #include "update_engine/graph_utils.h" |
| 24 #include "update_engine/subprocess.h" | 24 #include "update_engine/subprocess.h" |
| 25 #include "update_engine/topological_sort.h" | 25 #include "update_engine/topological_sort.h" |
| 26 #include "update_engine/update_metadata.pb.h" | 26 #include "update_engine/update_metadata.pb.h" |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 graph->back().op.set_dst_length(graph->back().op.src_length()); | 645 graph->back().op.set_dst_length(graph->back().op.src_length()); |
| 646 | 646 |
| 647 // make the dest node read from the scratch space | 647 // make the dest node read from the scratch space |
| 648 DeltaDiffGenerator::SubstituteBlocks( | 648 DeltaDiffGenerator::SubstituteBlocks( |
| 649 &((*graph)[it->second].op), | 649 &((*graph)[it->second].op), |
| 650 (*graph)[it->first].out_edges[it->second].extents, | 650 (*graph)[it->first].out_edges[it->second].extents, |
| 651 scratch); | 651 scratch); |
| 652 | 652 |
| 653 // delete the old edge | 653 // delete the old edge |
| 654 CHECK_EQ(1, (*graph)[it->first].out_edges.erase(it->second)); | 654 CHECK_EQ(1, (*graph)[it->first].out_edges.erase(it->second)); |
| 655 | 655 |
| 656 // Add an edge from dst to copy operation | 656 // Add an edge from dst to copy operation |
| 657 (*graph)[it->second].out_edges.insert(make_pair(graph->size() - 1, | 657 (*graph)[it->second].out_edges.insert(make_pair(graph->size() - 1, |
| 658 EdgeProperties())); | 658 EdgeProperties())); |
| 659 } | 659 } |
| 660 return true; | 660 return true; |
| 661 } | 661 } |
| 662 | 662 |
| 663 // Stores all Extents in 'extents' into 'out'. | 663 // Stores all Extents in 'extents' into 'out'. |
| 664 void DeltaDiffGenerator::StoreExtents( | 664 void DeltaDiffGenerator::StoreExtents( |
| 665 vector<Extent>& extents, | 665 vector<Extent>& extents, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 685 if (blocks[i].reader == blocks[i].writer) | 685 if (blocks[i].reader == blocks[i].writer) |
| 686 continue; | 686 continue; |
| 687 // See if there's already an edge we can add onto | 687 // See if there's already an edge we can add onto |
| 688 Vertex::EdgeMap::iterator edge_it = | 688 Vertex::EdgeMap::iterator edge_it = |
| 689 (*graph)[blocks[i].writer].out_edges.find(blocks[i].reader); | 689 (*graph)[blocks[i].writer].out_edges.find(blocks[i].reader); |
| 690 if (edge_it == (*graph)[blocks[i].writer].out_edges.end()) { | 690 if (edge_it == (*graph)[blocks[i].writer].out_edges.end()) { |
| 691 // No existing edge. Create one | 691 // No existing edge. Create one |
| 692 (*graph)[blocks[i].writer].out_edges.insert( | 692 (*graph)[blocks[i].writer].out_edges.insert( |
| 693 make_pair(blocks[i].reader, EdgeProperties())); | 693 make_pair(blocks[i].reader, EdgeProperties())); |
| 694 edge_it = (*graph)[blocks[i].writer].out_edges.find(blocks[i].reader); | 694 edge_it = (*graph)[blocks[i].writer].out_edges.find(blocks[i].reader); |
| 695 CHECK_NE(edge_it, (*graph)[blocks[i].writer].out_edges.end()); | 695 CHECK(edge_it != (*graph)[blocks[i].writer].out_edges.end()); |
| 696 } | 696 } |
| 697 graph_utils::AppendBlockToExtents(&edge_it->second.extents, i); | 697 graph_utils::AppendBlockToExtents(&edge_it->second.extents, i); |
| 698 } | 698 } |
| 699 } | 699 } |
| 700 | 700 |
| 701 bool DeltaDiffGenerator::ReorderDataBlobs( | 701 bool DeltaDiffGenerator::ReorderDataBlobs( |
| 702 DeltaArchiveManifest* manifest, | 702 DeltaArchiveManifest* manifest, |
| 703 const std::string& data_blobs_path, | 703 const std::string& data_blobs_path, |
| 704 const std::string& new_data_blobs_path) { | 704 const std::string& new_data_blobs_path) { |
| 705 int in_fd = open(data_blobs_path.c_str(), O_RDONLY, 0); | 705 int in_fd = open(data_blobs_path.c_str(), O_RDONLY, 0); |
| 706 TEST_AND_RETURN_FALSE_ERRNO(in_fd >= 0); | 706 TEST_AND_RETURN_FALSE_ERRNO(in_fd >= 0); |
| 707 ScopedFdCloser in_fd_closer(&in_fd); | 707 ScopedFdCloser in_fd_closer(&in_fd); |
| 708 | 708 |
| 709 DirectFileWriter writer; | 709 DirectFileWriter writer; |
| 710 TEST_AND_RETURN_FALSE( | 710 TEST_AND_RETURN_FALSE( |
| 711 writer.Open(new_data_blobs_path.c_str(), | 711 writer.Open(new_data_blobs_path.c_str(), |
| 712 O_WRONLY | O_TRUNC | O_CREAT, | 712 O_WRONLY | O_TRUNC | O_CREAT, |
| 713 0644) == 0); | 713 0644) == 0); |
| 714 ScopedFileWriterCloser writer_closer(&writer); | 714 ScopedFileWriterCloser writer_closer(&writer); |
| 715 uint64_t out_file_size = 0; | 715 uint64_t out_file_size = 0; |
| 716 | 716 |
| 717 for (int i = 0; i < (manifest->install_operations_size() + | 717 for (int i = 0; i < (manifest->install_operations_size() + |
| 718 manifest->kernel_install_operations_size()); i++) { | 718 manifest->kernel_install_operations_size()); i++) { |
| 719 DeltaArchiveManifest_InstallOperation* op = NULL; | 719 DeltaArchiveManifest_InstallOperation* op = NULL; |
| 720 if (i < manifest->install_operations_size()) { | 720 if (i < manifest->install_operations_size()) { |
| 721 op = manifest->mutable_install_operations(i); | 721 op = manifest->mutable_install_operations(i); |
| 722 } else { | 722 } else { |
| 723 op = manifest->mutable_kernel_install_operations( | 723 op = manifest->mutable_kernel_install_operations( |
| 724 i - manifest->install_operations_size()); | 724 i - manifest->install_operations_size()); |
| 725 } | 725 } |
| 726 if (!op->has_data_offset()) | 726 if (!op->has_data_offset()) |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 | 942 |
| 943 LOG(INFO) << "All done. Successfully created delta file."; | 943 LOG(INFO) << "All done. Successfully created delta file."; |
| 944 return true; | 944 return true; |
| 945 } | 945 } |
| 946 | 946 |
| 947 const char* const kBsdiffPath = "/usr/bin/bsdiff"; | 947 const char* const kBsdiffPath = "/usr/bin/bsdiff"; |
| 948 const char* const kBspatchPath = "/usr/bin/bspatch"; | 948 const char* const kBspatchPath = "/usr/bin/bspatch"; |
| 949 const char* const kDeltaMagic = "CrAU"; | 949 const char* const kDeltaMagic = "CrAU"; |
| 950 | 950 |
| 951 }; // namespace chromeos_update_engine | 951 }; // namespace chromeos_update_engine |
| OLD | NEW |