update_engine: Run clang-format on payload_generator/
BUG=none
TEST=unittest
Change-Id: I00cafb1fc709d8f02119cb0058cfcb0b573ef25d
Reviewed-on: https://chromium-review.googlesource.com/1409927
Commit-Ready: Amin Hassani <[email protected]>
Tested-by: Amin Hassani <[email protected]>
Reviewed-by: Sen Jiang <[email protected]>
diff --git a/payload_generator/ab_generator.cc b/payload_generator/ab_generator.cc
index eb64f4a..f4cc9fb 100644
--- a/payload_generator/ab_generator.cc
+++ b/payload_generator/ab_generator.cc
@@ -35,16 +35,17 @@
namespace chromeos_update_engine {
-bool ABGenerator::GenerateOperations(
- const PayloadGenerationConfig& config,
- const PartitionConfig& old_part,
- const PartitionConfig& new_part,
- BlobFileWriter* blob_file,
- vector<AnnotatedOperation>* aops) {
+bool ABGenerator::GenerateOperations(const PayloadGenerationConfig& config,
+ const PartitionConfig& old_part,
+ const PartitionConfig& new_part,
+ BlobFileWriter* blob_file,
+ vector<AnnotatedOperation>* aops) {
TEST_AND_RETURN_FALSE(old_part.name == new_part.name);
- ssize_t hard_chunk_blocks = (config.hard_chunk_size == -1 ? -1 :
- config.hard_chunk_size / config.block_size);
+ ssize_t hard_chunk_blocks =
+ (config.hard_chunk_size == -1
+ ? -1
+ : config.hard_chunk_size / config.block_size);
size_t soft_chunk_blocks = config.soft_chunk_size / config.block_size;
aops->clear();
@@ -107,9 +108,8 @@
return true;
}
-bool ABGenerator::SplitSourceCopy(
- const AnnotatedOperation& original_aop,
- vector<AnnotatedOperation>* result_aops) {
+bool ABGenerator::SplitSourceCopy(const AnnotatedOperation& original_aop,
+ vector<AnnotatedOperation>* result_aops) {
InstallOperation original_op = original_aop.op;
TEST_AND_RETURN_FALSE(original_op.type() == InstallOperation::SOURCE_COPY);
// Keeps track of the index of curr_src_ext.
@@ -231,9 +231,8 @@
// merge), are contiguous, are fragmented to have one destination extent,
// and their combined block count would be less than chunk size, merge
// them.
- last_aop.name = base::StringPrintf("%s,%s",
- last_aop.name.c_str(),
- curr_aop.name.c_str());
+ last_aop.name = base::StringPrintf(
+ "%s,%s", last_aop.name.c_str(), curr_aop.name.c_str());
if (is_delta_op) {
ExtendExtents(last_aop.op.mutable_src_extents(),
@@ -273,11 +272,8 @@
vector<Extent> dst_extents;
ExtentsToVector(aop->op.dst_extents(), &dst_extents);
brillo::Blob data(utils::BlocksInExtents(dst_extents) * kBlockSize);
- TEST_AND_RETURN_FALSE(utils::ReadExtents(target_part_path,
- dst_extents,
- &data,
- data.size(),
- kBlockSize));
+ TEST_AND_RETURN_FALSE(utils::ReadExtents(
+ target_part_path, dst_extents, &data, data.size(), kBlockSize));
brillo::Blob blob;
InstallOperation_Type op_type;
diff --git a/payload_generator/ab_generator.h b/payload_generator/ab_generator.h
index 343b546..2accf1e 100644
--- a/payload_generator/ab_generator.h
+++ b/payload_generator/ab_generator.h
@@ -48,12 +48,11 @@
// order. The operations are stored in |aops| and should be executed in that
// order. All the offsets in the operations reference the data written to
// |blob_file|.
- bool GenerateOperations(
- const PayloadGenerationConfig& config,
- const PartitionConfig& old_part,
- const PartitionConfig& new_part,
- BlobFileWriter* blob_file,
- std::vector<AnnotatedOperation>* aops) override;
+ bool GenerateOperations(const PayloadGenerationConfig& config,
+ const PartitionConfig& old_part,
+ const PartitionConfig& new_part,
+ BlobFileWriter* blob_file,
+ std::vector<AnnotatedOperation>* aops) override;
// Split the operations in the vector of AnnotatedOperations |aops| such that
// for every operation there is only one dst extent and updates |aops| with
diff --git a/payload_generator/ab_generator_unittest.cc b/payload_generator/ab_generator_unittest.cc
index 90039f1..2f8c0c6 100644
--- a/payload_generator/ab_generator_unittest.cc
+++ b/payload_generator/ab_generator_unittest.cc
@@ -81,10 +81,10 @@
const size_t op_ex2_size = op_ex2_num_blocks * kBlockSize;
InstallOperation op;
op.set_type(orig_type);
- *(op.add_dst_extents()) = ExtentForRange(op_ex1_start_block,
- op_ex1_num_blocks);
- *(op.add_dst_extents()) = ExtentForRange(op_ex2_start_block,
- op_ex2_num_blocks);
+ *(op.add_dst_extents()) =
+ ExtentForRange(op_ex1_start_block, op_ex1_num_blocks);
+ *(op.add_dst_extents()) =
+ ExtentForRange(op_ex2_start_block, op_ex2_num_blocks);
brillo::Blob op_data;
op_data.insert(op_data.end(),
@@ -135,8 +135,8 @@
EXPECT_FALSE(first_op.has_src_length());
EXPECT_FALSE(first_op.has_dst_length());
EXPECT_EQ(1, first_op.dst_extents().size());
- EXPECT_TRUE(ExtentEquals(first_op.dst_extents(0), op_ex1_start_block,
- op_ex1_num_blocks));
+ EXPECT_TRUE(ExtentEquals(
+ first_op.dst_extents(0), op_ex1_start_block, op_ex1_num_blocks));
// Obtain the expected blob.
brillo::Blob first_expected_data(
part_data.begin() + op_ex1_offset,
@@ -165,8 +165,8 @@
EXPECT_FALSE(second_op.has_src_length());
EXPECT_FALSE(second_op.has_dst_length());
EXPECT_EQ(1, second_op.dst_extents().size());
- EXPECT_TRUE(ExtentEquals(second_op.dst_extents(0), op_ex2_start_block,
- op_ex2_num_blocks));
+ EXPECT_TRUE(ExtentEquals(
+ second_op.dst_extents(0), op_ex2_start_block, op_ex2_num_blocks));
// Obtain the expected blob.
brillo::Blob second_expected_data(
part_data.begin() + op_ex2_offset,
@@ -234,7 +234,7 @@
const size_t first_op_size = first_op_num_blocks * kBlockSize;
*(first_op.add_dst_extents()) = ExtentForRange(0, first_op_num_blocks);
brillo::Blob first_op_data(part_data.begin(),
- part_data.begin() + first_op_size);
+ part_data.begin() + first_op_size);
brillo::Blob first_op_blob;
if (orig_type == InstallOperation::REPLACE) {
first_op_blob = first_op_data;
@@ -251,10 +251,10 @@
InstallOperation second_op;
second_op.set_type(orig_type);
- *(second_op.add_dst_extents()) = ExtentForRange(first_op_num_blocks,
- second_op_num_blocks);
+ *(second_op.add_dst_extents()) =
+ ExtentForRange(first_op_num_blocks, second_op_num_blocks);
brillo::Blob second_op_data(part_data.begin() + first_op_size,
- part_data.begin() + total_op_size);
+ part_data.begin() + total_op_size);
brillo::Blob second_op_blob;
if (orig_type == InstallOperation::REPLACE) {
second_op_blob = second_op_data;
@@ -263,8 +263,8 @@
}
second_op.set_data_offset(first_op_blob.size());
second_op.set_data_length(second_op_blob.size());
- blob_data.insert(blob_data.end(), second_op_blob.begin(),
- second_op_blob.end());
+ blob_data.insert(
+ blob_data.end(), second_op_blob.begin(), second_op_blob.end());
AnnotatedOperation second_aop;
second_aop.op = second_op;
second_aop.name = "second";
@@ -300,7 +300,7 @@
// Check to see if the blob pointed to in the new extent has what we expect.
brillo::Blob expected_data(part_data.begin(),
- part_data.begin() + total_op_size);
+ part_data.begin() + total_op_size);
brillo::Blob expected_blob;
if (compressible) {
ASSERT_TRUE(BzipCompress(expected_data, &expected_blob));
diff --git a/payload_generator/annotated_operation.cc b/payload_generator/annotated_operation.cc
index e28fe85..5637cb1 100644
--- a/payload_generator/annotated_operation.cc
+++ b/payload_generator/annotated_operation.cc
@@ -55,7 +55,7 @@
// REPLACE_BZ 500 @3000
// name: /foo/bar
// dst: (123, 3) (127, 2)
- os << InstallOperationTypeName(aop.op.type()) << " " << aop.op.data_length();
+ os << InstallOperationTypeName(aop.op.type()) << " " << aop.op.data_length();
if (aop.op.data_length() > 0)
os << " @" << aop.op.data_offset();
if (!aop.name.empty()) {
diff --git a/payload_generator/blob_file_writer.cc b/payload_generator/blob_file_writer.cc
index 8225df4..7cdeb35 100644
--- a/payload_generator/blob_file_writer.cc
+++ b/payload_generator/blob_file_writer.cc
@@ -29,11 +29,10 @@
*blob_file_size_ += blob.size();
stored_blobs_++;
- if (total_blobs_ > 0 &&
- (10 * (stored_blobs_ - 1) / total_blobs_) !=
- (10 * stored_blobs_ / total_blobs_)) {
- LOG(INFO) << (100 * stored_blobs_ / total_blobs_)
- << "% complete " << stored_blobs_ << "/" << total_blobs_
+ if (total_blobs_ > 0 && (10 * (stored_blobs_ - 1) / total_blobs_) !=
+ (10 * stored_blobs_ / total_blobs_)) {
+ LOG(INFO) << (100 * stored_blobs_ / total_blobs_) << "% complete "
+ << stored_blobs_ << "/" << total_blobs_
<< " ops (output size: " << *blob_file_size_ << ")";
}
return result;
diff --git a/payload_generator/blob_file_writer.h b/payload_generator/blob_file_writer.h
index cbc13ae..48553be 100644
--- a/payload_generator/blob_file_writer.h
+++ b/payload_generator/blob_file_writer.h
@@ -29,8 +29,7 @@
// Create the BlobFileWriter object that will manage the blobs stored to
// |blob_fd| in a thread safe way.
BlobFileWriter(int blob_fd, off_t* blob_file_size)
- : blob_fd_(blob_fd),
- blob_file_size_(blob_file_size) {}
+ : blob_fd_(blob_fd), blob_file_size_(blob_file_size) {}
// Store the passed |blob| in the blob file. Returns the offset at which it
// was stored, or -1 in case of failure.
diff --git a/payload_generator/blob_file_writer_unittest.cc b/payload_generator/blob_file_writer_unittest.cc
index 5f94ef3..487bc73 100644
--- a/payload_generator/blob_file_writer_unittest.cc
+++ b/payload_generator/blob_file_writer_unittest.cc
@@ -33,9 +33,8 @@
TEST(BlobFileWriterTest, SimpleTest) {
string blob_path;
int blob_fd;
- EXPECT_TRUE(utils::MakeTempFile("BlobFileWriterTest.XXXXXX",
- &blob_path,
- &blob_fd));
+ EXPECT_TRUE(
+ utils::MakeTempFile("BlobFileWriterTest.XXXXXX", &blob_path, &blob_fd));
off_t blob_file_size = 0;
BlobFileWriter blob_file(blob_fd, &blob_file_size);
@@ -47,11 +46,8 @@
brillo::Blob stored_blob(blob_size);
ssize_t bytes_read;
- ASSERT_TRUE(utils::PReadAll(blob_fd,
- stored_blob.data(),
- blob_size,
- 0,
- &bytes_read));
+ ASSERT_TRUE(
+ utils::PReadAll(blob_fd, stored_blob.data(), blob_size, 0, &bytes_read));
EXPECT_EQ(bytes_read, blob_size);
EXPECT_EQ(blob, stored_blob);
}
diff --git a/payload_generator/block_mapping.cc b/payload_generator/block_mapping.cc
index ff10f0b..d0f0178 100644
--- a/payload_generator/block_mapping.cc
+++ b/payload_generator/block_mapping.cc
@@ -22,6 +22,7 @@
#include <functional>
#include <string>
+#include <utility>
#include <vector>
#include "update_engine/common/utils.h"
@@ -61,8 +62,8 @@
bool ret = true;
block_ids->resize(num_blocks);
for (size_t block = 0; block < num_blocks; block++) {
- (*block_ids)[block] = AddDiskBlock(
- fd, initial_byte_offset + block * block_size_);
+ (*block_ids)[block] =
+ AddDiskBlock(fd, initial_byte_offset + block * block_size_);
ret = ret && (*block_ids)[block] != -1;
}
return ret;
@@ -78,7 +79,7 @@
// We either reuse a UniqueBlock or create a new one. If we need a new
// UniqueBlock it could also be part of a new or existing bucket (if there is
// a hash collision).
- vector<UniqueBlock> *bucket = nullptr;
+ vector<UniqueBlock>* bucket = nullptr;
auto mapping_it = mapping_.find(h);
if (mapping_it == mapping_.end()) {
@@ -97,7 +98,7 @@
// No existing block was found at this point, so we create and fill in a new
// one.
bucket->emplace_back();
- UniqueBlock *new_ublock = &bucket->back();
+ UniqueBlock* new_ublock = &bucket->back();
new_ublock->times_read = 1;
new_ublock->fd = fd;
diff --git a/payload_generator/block_mapping.h b/payload_generator/block_mapping.h
index 3fe94ab..3738f6f 100644
--- a/payload_generator/block_mapping.h
+++ b/payload_generator/block_mapping.h
@@ -53,7 +53,9 @@
// from the file descriptor |fd| starting at offset |initial_byte_offset|.
// Returns whether it succeeded to add all the disk blocks and stores in
// |block_ids| the block id for each one of the added blocks.
- bool AddManyDiskBlocks(int fd, off_t initial_byte_offset, size_t num_blocks,
+ bool AddManyDiskBlocks(int fd,
+ off_t initial_byte_offset,
+ size_t num_blocks,
std::vector<BlockId>* block_ids);
private:
diff --git a/payload_generator/block_mapping_unittest.cc b/payload_generator/block_mapping_unittest.cc
index e1870ec..9b9b4f1 100644
--- a/payload_generator/block_mapping_unittest.cc
+++ b/payload_generator/block_mapping_unittest.cc
@@ -33,10 +33,6 @@
namespace chromeos_update_engine {
-namespace {
-
-} // namespace
-
class BlockMappingTest : public ::testing::Test {
protected:
// Old new partition files used in testing.
@@ -113,8 +109,7 @@
EXPECT_EQ((vector<BlockMapping::BlockId>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
old_ids);
- EXPECT_EQ((vector<BlockMapping::BlockId>{0, 11, 12, 13, 1, 2}),
- new_ids);
+ EXPECT_EQ((vector<BlockMapping::BlockId>{0, 11, 12, 13, 1, 2}), new_ids);
}
} // namespace chromeos_update_engine
diff --git a/payload_generator/cycle_breaker.cc b/payload_generator/cycle_breaker.cc
index a8a04ab..d76f679 100644
--- a/payload_generator/cycle_breaker.cc
+++ b/payload_generator/cycle_breaker.cc
@@ -78,10 +78,12 @@
// Set subgraph edges for the components in the SCC.
for (vector<Vertex::Index>::iterator it = component_indexes.begin();
- it != component_indexes.end(); ++it) {
+ it != component_indexes.end();
+ ++it) {
subgraph_[*it].subgraph_edges.clear();
for (vector<Vertex::Index>::iterator jt = component_indexes.begin();
- jt != component_indexes.end(); ++jt) {
+ jt != component_indexes.end();
+ ++jt) {
// If there's a link from *it -> *jt in the graph,
// add a subgraph_ edge
if (base::ContainsKey(subgraph_[*it].out_edges, *jt))
@@ -106,13 +108,13 @@
void CycleBreaker::HandleCircuit() {
stack_.push_back(current_vertex_);
- CHECK_GE(stack_.size(),
- static_cast<vector<Vertex::Index>::size_type>(2));
+ CHECK_GE(stack_.size(), static_cast<vector<Vertex::Index>::size_type>(2));
Edge min_edge = make_pair(stack_[0], stack_[1]);
uint64_t min_edge_weight = std::numeric_limits<uint64_t>::max();
size_t edges_considered = 0;
for (vector<Vertex::Index>::const_iterator it = stack_.begin();
- it != (stack_.end() - 1); ++it) {
+ it != (stack_.end() - 1);
+ ++it) {
Edge edge = make_pair(*it, *(it + 1));
if (cut_edges_.find(edge) != cut_edges_.end()) {
stack_.pop_back();
@@ -135,7 +137,7 @@
blocked_[u] = false;
for (Vertex::EdgeMap::iterator it = blocked_graph_[u].out_edges.begin();
- it != blocked_graph_[u].out_edges.end(); ) {
+ it != blocked_graph_[u].out_edges.end();) {
Vertex::Index w = it->first;
blocked_graph_[u].out_edges.erase(it++);
if (blocked_[w])
@@ -145,7 +147,9 @@
bool CycleBreaker::StackContainsCutEdge() const {
for (vector<Vertex::Index>::const_iterator it = ++stack_.begin(),
- e = stack_.end(); it != e; ++it) {
+ e = stack_.end();
+ it != e;
+ ++it) {
Edge edge = make_pair(*(it - 1), *it);
if (base::ContainsKey(cut_edges_, edge)) {
return true;
@@ -175,7 +179,8 @@
for (Vertex::SubgraphEdgeMap::iterator w =
subgraph_[vertex].subgraph_edges.begin();
- w != subgraph_[vertex].subgraph_edges.end(); ++w) {
+ w != subgraph_[vertex].subgraph_edges.end();
+ ++w) {
if (*w == current_vertex_) {
// The original paper called for printing stack_ followed by
// current_vertex_ here, which is a cycle. Instead, we call
@@ -196,11 +201,12 @@
} else {
for (Vertex::SubgraphEdgeMap::iterator w =
subgraph_[vertex].subgraph_edges.begin();
- w != subgraph_[vertex].subgraph_edges.end(); ++w) {
+ w != subgraph_[vertex].subgraph_edges.end();
+ ++w) {
if (blocked_graph_[*w].out_edges.find(vertex) ==
blocked_graph_[*w].out_edges.end()) {
- blocked_graph_[*w].out_edges.insert(make_pair(vertex,
- EdgeProperties()));
+ blocked_graph_[*w].out_edges.insert(
+ make_pair(vertex, EdgeProperties()));
}
}
}
diff --git a/payload_generator/cycle_breaker.h b/payload_generator/cycle_breaker.h
index 231d63a..01518fe 100644
--- a/payload_generator/cycle_breaker.h
+++ b/payload_generator/cycle_breaker.h
@@ -53,11 +53,11 @@
bool Circuit(Vertex::Index vertex, Vertex::Index depth);
bool StackContainsCutEdge() const;
- std::vector<bool> blocked_; // "blocked" in the paper
- Vertex::Index current_vertex_; // "s" in the paper
+ std::vector<bool> blocked_; // "blocked" in the paper
+ Vertex::Index current_vertex_; // "s" in the paper
std::vector<Vertex::Index> stack_; // the stack variable in the paper
- Graph subgraph_; // "A_K" in the paper
- Graph blocked_graph_; // "B" in the paper
+ Graph subgraph_; // "A_K" in the paper
+ Graph blocked_graph_; // "B" in the paper
std::set<Edge> cut_edges_;
diff --git a/payload_generator/cycle_breaker_unittest.cc b/payload_generator/cycle_breaker_unittest.cc
index 7554dbb..fdcf49b 100644
--- a/payload_generator/cycle_breaker_unittest.cc
+++ b/payload_generator/cycle_breaker_unittest.cc
@@ -96,7 +96,7 @@
namespace {
pair<Vertex::Index, EdgeProperties> EdgeWithWeight(Vertex::Index dest,
-uint64_t weight) {
+ uint64_t weight) {
EdgeProperties props;
props.extents.resize(1);
props.extents[0].set_num_blocks(weight);
@@ -104,7 +104,6 @@
}
} // namespace
-
// This creates a bunch of cycles like this:
//
// root <------.
@@ -168,7 +167,9 @@
set<Edge> expected_cuts;
for (Vertex::EdgeMap::const_iterator it = graph[n_root].out_edges.begin(),
- e = graph[n_root].out_edges.end(); it != e; ++it) {
+ e = graph[n_root].out_edges.end();
+ it != e;
+ ++it) {
expected_cuts.insert(make_pair(n_root, it->first));
}
diff --git a/payload_generator/deflate_utils.cc b/payload_generator/deflate_utils.cc
index 1bc3b36..a7a0503 100644
--- a/payload_generator/deflate_utils.cc
+++ b/payload_generator/deflate_utils.cc
@@ -31,10 +31,10 @@
#include "update_engine/payload_generator/squashfs_filesystem.h"
#include "update_engine/update_metadata.pb.h"
-using std::string;
-using std::vector;
using puffin::BitExtent;
using puffin::ByteExtent;
+using std::string;
+using std::vector;
namespace chromeos_update_engine {
namespace deflate_utils {
diff --git a/payload_generator/deflate_utils_unittest.cc b/payload_generator/deflate_utils_unittest.cc
index cb9476a..f2c4dba 100644
--- a/payload_generator/deflate_utils_unittest.cc
+++ b/payload_generator/deflate_utils_unittest.cc
@@ -29,9 +29,9 @@
#include "update_engine/payload_generator/extent_ranges.h"
#include "update_engine/payload_generator/extent_utils.h"
-using std::vector;
using puffin::BitExtent;
using puffin::ByteExtent;
+using std::vector;
namespace chromeos_update_engine {
namespace deflate_utils {
diff --git a/payload_generator/delta_diff_generator.cc b/payload_generator/delta_diff_generator.cc
index 1db2144..d484d32 100644
--- a/payload_generator/delta_diff_generator.cc
+++ b/payload_generator/delta_diff_generator.cc
@@ -50,11 +50,10 @@
const size_t kRootFSPartitionSize = static_cast<size_t>(2) * 1024 * 1024 * 1024;
const size_t kBlockSize = 4096; // bytes
-bool GenerateUpdatePayloadFile(
- const PayloadGenerationConfig& config,
- const string& output_path,
- const string& private_key_path,
- uint64_t* metadata_size) {
+bool GenerateUpdatePayloadFile(const PayloadGenerationConfig& config,
+ const string& output_path,
+ const string& private_key_path,
+ uint64_t* metadata_size) {
if (!config.version.Validate()) {
LOG(ERROR) << "Unsupported major.minor version: " << config.version.major
<< "." << config.version.minor;
@@ -108,11 +107,8 @@
vector<AnnotatedOperation> aops;
// Generate the operations using the strategy we selected above.
- TEST_AND_RETURN_FALSE(strategy->GenerateOperations(config,
- old_part,
- new_part,
- &blob_file,
- &aops));
+ TEST_AND_RETURN_FALSE(strategy->GenerateOperations(
+ config, old_part, new_part, &blob_file, &aops));
// Filter the no-operations. OperationsGenerators should not output this
// kind of operations normally, but this is an extra step to fix that if
@@ -125,8 +121,8 @@
LOG(INFO) << "Writing payload file...";
// Write payload file to disk.
- TEST_AND_RETURN_FALSE(payload.WritePayload(output_path, temp_file_path,
- private_key_path, metadata_size));
+ TEST_AND_RETURN_FALSE(payload.WritePayload(
+ output_path, temp_file_path, private_key_path, metadata_size));
LOG(INFO) << "All done. Successfully created delta file with "
<< "metadata size = " << *metadata_size;
diff --git a/payload_generator/delta_diff_generator.h b/payload_generator/delta_diff_generator.h
index d8bdae2..8323f47 100644
--- a/payload_generator/delta_diff_generator.h
+++ b/payload_generator/delta_diff_generator.h
@@ -41,7 +41,6 @@
const std::string& private_key_path,
uint64_t* metadata_size);
-
}; // namespace chromeos_update_engine
#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_DELTA_DIFF_GENERATOR_H_
diff --git a/payload_generator/delta_diff_utils.cc b/payload_generator/delta_diff_utils.cc
index dc38c33..1bad4d7 100644
--- a/payload_generator/delta_diff_utils.cc
+++ b/payload_generator/delta_diff_utils.cc
@@ -88,8 +88,10 @@
// removed, which may cause the extent to be trimmed, split or removed entirely.
// The value of |*idx_p| is updated to point to the next extent to be processed.
// Returns true iff the next extent to process is a new or updated one.
-bool ProcessExtentBlockRange(vector<Extent>* extents, size_t* idx_p,
- const bool do_remove, uint64_t range_start,
+bool ProcessExtentBlockRange(vector<Extent>* extents,
+ size_t* idx_p,
+ const bool do_remove,
+ uint64_t range_start,
uint64_t range_end) {
size_t idx = *idx_p;
uint64_t start_block = (*extents)[idx].start_block();
@@ -148,17 +150,17 @@
uint64_t src_num_blocks = (*src_extents)[src_idx].num_blocks();
uint64_t dst_num_blocks = (*dst_extents)[dst_idx].num_blocks();
- uint64_t min_num_blocks = std::min(src_num_blocks - src_offset,
- dst_num_blocks - dst_offset);
+ uint64_t min_num_blocks =
+ std::min(src_num_blocks - src_offset, dst_num_blocks - dst_offset);
uint64_t prev_src_offset = src_offset;
uint64_t prev_dst_offset = dst_offset;
src_offset += min_num_blocks;
dst_offset += min_num_blocks;
- bool new_src = ProcessExtentBlockRange(src_extents, &src_idx, do_remove,
- prev_src_offset, src_offset);
- bool new_dst = ProcessExtentBlockRange(dst_extents, &dst_idx, do_remove,
- prev_dst_offset, dst_offset);
+ bool new_src = ProcessExtentBlockRange(
+ src_extents, &src_idx, do_remove, prev_src_offset, src_offset);
+ bool new_dst = ProcessExtentBlockRange(
+ dst_extents, &dst_idx, do_remove, prev_dst_offset, dst_offset);
if (new_src) {
src_offset = 0;
}
@@ -428,8 +430,8 @@
// data blocks (for example, symlinks bigger than 60 bytes in ext2) are
// handled as normal files. We also ignore blocks that were already
// processed by a previous file.
- vector<Extent> new_file_extents = FilterExtentRanges(
- new_file.extents, new_visited_blocks);
+ vector<Extent> new_file_extents =
+ FilterExtentRanges(new_file.extents, new_visited_blocks);
new_visited_blocks.AddExtents(new_file_extents);
if (new_file_extents.empty())
@@ -559,7 +561,7 @@
// is a block from the new partition.
map<BlockMapping::BlockId, vector<uint64_t>> old_blocks_map;
- for (uint64_t block = old_num_blocks; block-- > 0; ) {
+ for (uint64_t block = old_num_blocks; block-- > 0;) {
if (old_block_ids[block] != 0 && !old_visited_blocks->ContainsBlock(block))
old_blocks_map[old_block_ids[block]].push_back(block);
@@ -706,15 +708,15 @@
chunk_blocks = total_blocks;
for (uint64_t block_offset = 0; block_offset < total_blocks;
- block_offset += chunk_blocks) {
+ block_offset += chunk_blocks) {
// Split the old/new file in the same chunks. Note that this could drop
// some information from the old file used for the new chunk. If the old
// file is smaller (or even empty when there's no old file) the chunk will
// also be empty.
- vector<Extent> old_extents_chunk = ExtentsSublist(
- old_extents, block_offset, chunk_blocks);
- vector<Extent> new_extents_chunk = ExtentsSublist(
- new_extents, block_offset, chunk_blocks);
+ vector<Extent> old_extents_chunk =
+ ExtentsSublist(old_extents, block_offset, chunk_blocks);
+ vector<Extent> new_extents_chunk =
+ ExtentsSublist(new_extents, block_offset, chunk_blocks);
NormalizeExtents(&old_extents_chunk);
NormalizeExtents(&new_extents_chunk);
@@ -731,8 +733,7 @@
// Check if the operation writes nothing.
if (operation.dst_extents_size() == 0) {
if (operation.type() == InstallOperation::MOVE) {
- LOG(INFO) << "Empty MOVE operation ("
- << name << "), skipping";
+ LOG(INFO) << "Empty MOVE operation (" << name << "), skipping";
continue;
} else {
LOG(ERROR) << "Empty non-MOVE operation";
@@ -744,8 +745,8 @@
AnnotatedOperation aop;
aop.name = name;
if (static_cast<uint64_t>(chunk_blocks) < total_blocks) {
- aop.name = base::StringPrintf("%s:%" PRIu64,
- name.c_str(), block_offset / chunk_blocks);
+ aop.name = base::StringPrintf(
+ "%s:%" PRIu64, name.c_str(), block_offset / chunk_blocks);
}
aop.op = operation;
@@ -870,9 +871,11 @@
brillo::Blob old_data;
if (blocks_to_read > 0) {
// Read old data.
- TEST_AND_RETURN_FALSE(
- utils::ReadExtents(old_part, src_extents, &old_data,
- kBlockSize * blocks_to_read, kBlockSize));
+ TEST_AND_RETURN_FALSE(utils::ReadExtents(old_part,
+ src_extents,
+ &old_data,
+ kBlockSize * blocks_to_read,
+ kBlockSize));
if (old_data == new_data) {
// No change in data.
operation.set_type(version.OperationAllowed(InstallOperation::SOURCE_COPY)
@@ -975,8 +978,8 @@
// Remove identical src/dst block ranges in MOVE operations.
if (operation.type() == InstallOperation::MOVE) {
- auto removed_bytes = RemoveIdenticalBlockRanges(
- &src_extents, &dst_extents, new_data.size());
+ auto removed_bytes =
+ RemoveIdenticalBlockRanges(&src_extents, &dst_extents, new_data.size());
operation.set_src_length(old_data.size() - removed_bytes);
operation.set_dst_length(new_data.size() - removed_bytes);
}
@@ -1014,8 +1017,7 @@
}
bool IsNoSourceOperation(InstallOperation_Type op_type) {
- return (IsAReplaceOperation(op_type) ||
- op_type == InstallOperation::ZERO ||
+ return (IsAReplaceOperation(op_type) || op_type == InstallOperation::ZERO ||
op_type == InstallOperation::DISCARD);
}
@@ -1027,11 +1029,12 @@
}
void FilterNoopOperations(vector<AnnotatedOperation>* ops) {
- ops->erase(
- std::remove_if(
- ops->begin(), ops->end(),
- [](const AnnotatedOperation& aop){return IsNoopOperation(aop.op);}),
- ops->end());
+ ops->erase(std::remove_if(ops->begin(),
+ ops->end(),
+ [](const AnnotatedOperation& aop) {
+ return IsNoopOperation(aop.op);
+ }),
+ ops->end());
}
bool InitializePartitionInfo(const PartitionConfig& part, PartitionInfo* info) {
diff --git a/payload_generator/delta_diff_utils_unittest.cc b/payload_generator/delta_diff_utils_unittest.cc
index 63e7506..f730cc9 100644
--- a/payload_generator/delta_diff_utils_unittest.cc
+++ b/payload_generator/delta_diff_utils_unittest.cc
@@ -59,8 +59,8 @@
uint64_t to_write =
std::min(static_cast<uint64_t>(extent.num_blocks()) * block_size,
static_cast<uint64_t>(data.size()) - offset);
- TEST_AND_RETURN_FALSE(
- fwrite(data.data() + offset, 1, to_write, fp.get()) == to_write);
+ TEST_AND_RETURN_FALSE(fwrite(data.data() + offset, 1, to_write, fp.get()) ==
+ to_write);
offset += extent.num_blocks() * block_size;
}
return true;
@@ -68,8 +68,10 @@
// Create a fake filesystem of the given |size| and initialize the partition
// holding it in the PartitionConfig |part|.
-void CreatePartition(PartitionConfig* part, const string& pattern,
- uint64_t block_size, off_t size) {
+void CreatePartition(PartitionConfig* part,
+ const string& pattern,
+ uint64_t block_size,
+ off_t size) {
int fd = -1;
ASSERT_TRUE(utils::MakeTempFile(pattern.c_str(), &part->path, &fd));
ASSERT_EQ(0, ftruncate(fd, size));
@@ -95,7 +97,8 @@
brillo::Blob block_data(prefix.begin(), prefix.end());
TEST_AND_RETURN_FALSE(prefix.size() <= block_size);
block_data.resize(block_size, 'X');
- std::copy(block_data.begin(), block_data.end(),
+ std::copy(block_data.begin(),
+ block_data.end(),
file_data.begin() + i * block_size);
}
return test_utils::WriteFileVector(part.path, file_data);
@@ -108,13 +111,16 @@
const uint64_t kDefaultBlockCount = 128;
void SetUp() override {
- CreatePartition(&old_part_, "DeltaDiffUtilsTest-old_part-XXXXXX",
- block_size_, block_size_ * kDefaultBlockCount);
- CreatePartition(&new_part_, "DeltaDiffUtilsTest-old_part-XXXXXX",
- block_size_, block_size_ * kDefaultBlockCount);
- ASSERT_TRUE(utils::MakeTempFile("DeltaDiffUtilsTest-blob-XXXXXX",
- &blob_path_,
- &blob_fd_));
+ CreatePartition(&old_part_,
+ "DeltaDiffUtilsTest-old_part-XXXXXX",
+ block_size_,
+ block_size_ * kDefaultBlockCount);
+ CreatePartition(&new_part_,
+ "DeltaDiffUtilsTest-old_part-XXXXXX",
+ block_size_,
+ block_size_ * kDefaultBlockCount);
+ ASSERT_TRUE(utils::MakeTempFile(
+ "DeltaDiffUtilsTest-blob-XXXXXX", &blob_path_, &blob_fd_));
}
void TearDown() override {
@@ -193,8 +199,8 @@
test_utils::FillWithData(&data_blob);
// The old file is on a different block than the new one.
- vector<Extent> old_extents = { ExtentForRange(11, 1) };
- vector<Extent> new_extents = { ExtentForRange(1, 1) };
+ vector<Extent> old_extents = {ExtentForRange(11, 1)};
+ vector<Extent> new_extents = {ExtentForRange(1, 1)};
EXPECT_TRUE(WriteExtents(old_part_.path, old_extents, kBlockSize, data_blob));
EXPECT_TRUE(WriteExtents(new_part_.path, new_extents, kBlockSize, data_blob));
@@ -237,15 +243,12 @@
// Old: [ 20 21 22 23 24 25 ] [ 28 29 ]
// New: [ 18 ] [ 21 22 ] [ 20 ] [ 24 25 26 ] [ 29 ]
// Same: ^^ ^^ ^^ ^^ ^^
- vector<Extent> old_extents = {
- ExtentForRange(20, 6),
- ExtentForRange(28, 2) };
- vector<Extent> new_extents = {
- ExtentForRange(18, 1),
- ExtentForRange(21, 2),
- ExtentForRange(20, 1),
- ExtentForRange(24, 3),
- ExtentForRange(29, 1) };
+ vector<Extent> old_extents = {ExtentForRange(20, 6), ExtentForRange(28, 2)};
+ vector<Extent> new_extents = {ExtentForRange(18, 1),
+ ExtentForRange(21, 2),
+ ExtentForRange(20, 1),
+ ExtentForRange(24, 3),
+ ExtentForRange(29, 1)};
uint64_t num_blocks = utils::BlocksInExtents(old_extents);
EXPECT_EQ(num_blocks, utils::BlocksInExtents(new_extents));
@@ -282,13 +285,9 @@
// The expected old and new extents that actually moved. See comment above.
old_extents = {
- ExtentForRange(20, 1),
- ExtentForRange(23, 1),
- ExtentForRange(28, 1) };
+ ExtentForRange(20, 1), ExtentForRange(23, 1), ExtentForRange(28, 1)};
new_extents = {
- ExtentForRange(18, 1),
- ExtentForRange(20, 1),
- ExtentForRange(26, 1) };
+ ExtentForRange(18, 1), ExtentForRange(20, 1), ExtentForRange(26, 1)};
num_blocks = utils::BlocksInExtents(old_extents);
EXPECT_EQ(num_blocks * kBlockSize, op.src_length());
@@ -317,8 +316,8 @@
test_utils::FillWithData(&data_blob);
// The old file is on a different block than the new one.
- vector<Extent> old_extents = { ExtentForRange(1, 1) };
- vector<Extent> new_extents = { ExtentForRange(2, 1) };
+ vector<Extent> old_extents = {ExtentForRange(1, 1)};
+ vector<Extent> new_extents = {ExtentForRange(2, 1)};
EXPECT_TRUE(WriteExtents(old_part_.path, old_extents, kBlockSize, data_blob));
// Modify one byte in the new file.
@@ -355,8 +354,8 @@
TEST_F(DeltaDiffUtilsTest, ReplaceSmallTest) {
// The old file is on a different block than the new one.
- vector<Extent> old_extents = { ExtentForRange(1, 1) };
- vector<Extent> new_extents = { ExtentForRange(2, 1) };
+ vector<Extent> old_extents = {ExtentForRange(1, 1)};
+ vector<Extent> new_extents = {ExtentForRange(2, 1)};
// Make a blob that's just 1's that will compress well.
brillo::Blob ones(kBlockSize, 1);
@@ -372,8 +371,8 @@
for (int i = 0; i < 2; i++) {
brillo::Blob data_to_test = i == 0 ? random_data : ones;
// The old_extents will be initialized with 0.
- EXPECT_TRUE(WriteExtents(new_part_.path, new_extents, kBlockSize,
- data_to_test));
+ EXPECT_TRUE(
+ WriteExtents(new_part_.path, new_extents, kBlockSize, data_to_test));
brillo::Blob data;
InstallOperation op;
@@ -412,8 +411,8 @@
test_utils::FillWithData(&data_blob);
// The old file is on a different block than the new one.
- vector<Extent> old_extents = { ExtentForRange(11, 1) };
- vector<Extent> new_extents = { ExtentForRange(1, 1) };
+ vector<Extent> old_extents = {ExtentForRange(11, 1)};
+ vector<Extent> new_extents = {ExtentForRange(1, 1)};
EXPECT_TRUE(WriteExtents(old_part_.path, old_extents, kBlockSize, data_blob));
EXPECT_TRUE(WriteExtents(new_part_.path, new_extents, kBlockSize, data_blob));
@@ -444,8 +443,8 @@
test_utils::FillWithData(&data_blob);
// The old file is on a different block than the new one.
- vector<Extent> old_extents = { ExtentForRange(1, 1) };
- vector<Extent> new_extents = { ExtentForRange(2, 1) };
+ vector<Extent> old_extents = {ExtentForRange(1, 1)};
+ vector<Extent> new_extents = {ExtentForRange(2, 1)};
EXPECT_TRUE(WriteExtents(old_part_.path, old_extents, kBlockSize, data_blob));
// Modify one byte in the new file.
@@ -600,7 +599,9 @@
// Override some of the old blocks with different data.
vector<Extent> different_blocks = {ExtentForRange(40, 5)};
- EXPECT_TRUE(WriteExtents(old_part_.path, different_blocks, kBlockSize,
+ EXPECT_TRUE(WriteExtents(old_part_.path,
+ different_blocks,
+ kBlockSize,
brillo::Blob(5 * kBlockSize, 'a')));
EXPECT_TRUE(RunDeltaMovedAndZeroBlocks(10, // chunk_blocks
@@ -650,8 +651,8 @@
brillo::Blob partition_data(old_part_.size);
for (size_t offset = 0; offset < partition_data.size();
offset += file_data.size()) {
- std::copy(file_data.begin(), file_data.end(),
- partition_data.begin() + offset);
+ std::copy(
+ file_data.begin(), file_data.end(), partition_data.begin() + offset);
}
EXPECT_TRUE(test_utils::WriteFileVector(old_part_.path, partition_data));
EXPECT_TRUE(test_utils::WriteFileVector(new_part_.path, partition_data));
@@ -751,8 +752,8 @@
// as block permutation[i] in the new_part_.
brillo::Blob new_contents;
EXPECT_TRUE(utils::ReadFile(new_part_.path, &new_contents));
- EXPECT_TRUE(WriteExtents(old_part_.path, perm_extents, block_size_,
- new_contents));
+ EXPECT_TRUE(
+ WriteExtents(old_part_.path, perm_extents, block_size_, new_contents));
EXPECT_TRUE(RunDeltaMovedAndZeroBlocks(-1, // chunk_blocks
kSourceMinorPayloadVersion));
diff --git a/payload_generator/ext2_filesystem.cc b/payload_generator/ext2_filesystem.cc
index 07ec371..06304f4 100644
--- a/payload_generator/ext2_filesystem.cc
+++ b/payload_generator/ext2_filesystem.cc
@@ -92,11 +92,11 @@
int UpdateFileAndAppend(ext2_ino_t dir,
int entry,
- struct ext2_dir_entry *dirent,
+ struct ext2_dir_entry* dirent,
int offset,
int blocksize,
- char *buf,
- void *priv_data) {
+ char* buf,
+ void* priv_data) {
UpdateFileAndAppendState* state =
static_cast<UpdateFileAndAppendState*>(priv_data);
uint32_t file_type = dirent->name_len >> 8;
@@ -224,20 +224,21 @@
// and triple indirect blocks (no data blocks). For directories and
// the journal, all blocks are considered metadata blocks.
int flags = it_ino < EXT2_GOOD_OLD_FIRST_INO ? 0 : BLOCK_FLAG_DATA_ONLY;
- error = ext2fs_block_iterate2(filsys_, it_ino, flags,
+ error = ext2fs_block_iterate2(filsys_,
+ it_ino,
+ flags,
nullptr, // block_buf
ProcessInodeAllBlocks,
&file.extents);
if (error) {
- LOG(ERROR) << "Failed to enumerate inode " << it_ino
- << " blocks (" << error << ")";
+ LOG(ERROR) << "Failed to enumerate inode " << it_ino << " blocks ("
+ << error << ")";
continue;
}
if (it_ino >= EXT2_GOOD_OLD_FIRST_INO) {
- ext2fs_block_iterate2(filsys_, it_ino, 0, nullptr,
- AddMetadataBlocks,
- &inode_blocks);
+ ext2fs_block_iterate2(
+ filsys_, it_ino, 0, nullptr, AddMetadataBlocks, &inode_blocks);
}
}
ext2fs_close_inode_scan(iscan);
@@ -273,9 +274,12 @@
}
ext2fs_free_mem(&dir_name);
- error = ext2fs_dir_iterate2(
- filsys_, dir_ino, 0, nullptr /* block_buf */,
- UpdateFileAndAppend, &priv_data);
+ error = ext2fs_dir_iterate2(filsys_,
+ dir_ino,
+ 0,
+ nullptr /* block_buf */,
+ UpdateFileAndAppend,
+ &priv_data);
if (error) {
LOG(WARNING) << "Failed to enumerate files in directory "
<< inodes[dir_ino].name << " (error " << error << ")";
@@ -328,9 +332,11 @@
bool Ext2Filesystem::LoadSettings(brillo::KeyValueStore* store) const {
// First search for the settings inode following symlinks if we find some.
ext2_ino_t ino_num = 0;
- errcode_t err = ext2fs_namei_follow(
- filsys_, EXT2_ROOT_INO /* root */, EXT2_ROOT_INO /* cwd */,
- "/etc/update_engine.conf", &ino_num);
+ errcode_t err = ext2fs_namei_follow(filsys_,
+ EXT2_ROOT_INO /* root */,
+ EXT2_ROOT_INO /* cwd */,
+ "/etc/update_engine.conf",
+ &ino_num);
if (err != 0)
return false;
@@ -340,7 +346,9 @@
// Load the list of blocks and then the contents of the inodes.
vector<Extent> extents;
- err = ext2fs_block_iterate2(filsys_, ino_num, BLOCK_FLAG_DATA_ONLY,
+ err = ext2fs_block_iterate2(filsys_,
+ ino_num,
+ BLOCK_FLAG_DATA_ONLY,
nullptr, // block_buf
ProcessInodeAllBlocks,
&extents);
@@ -352,8 +360,8 @@
// Sparse holes in the settings file are not supported.
if (EXT2_I_SIZE(&ino_data) > physical_size)
return false;
- if (!utils::ReadExtents(filename_, extents, &blob, physical_size,
- filsys_->blocksize))
+ if (!utils::ReadExtents(
+ filename_, extents, &blob, physical_size, filsys_->blocksize))
return false;
string text(blob.begin(), blob.begin() + EXT2_I_SIZE(&ino_data));
diff --git a/payload_generator/ext2_filesystem_unittest.cc b/payload_generator/ext2_filesystem_unittest.cc
index 5360e6c..54600e9 100644
--- a/payload_generator/ext2_filesystem_unittest.cc
+++ b/payload_generator/ext2_filesystem_unittest.cc
@@ -98,14 +98,13 @@
// "generate_image.sh" script. The expected conditions of each file in these
// images is encoded in the file name, as defined in the mentioned script.
TEST_F(Ext2FilesystemTest, ParseGeneratedImages) {
- const vector<string> kGeneratedImages = {
- "disk_ext2_1k.img",
- "disk_ext2_4k.img" };
+ const vector<string> kGeneratedImages = {"disk_ext2_1k.img",
+ "disk_ext2_4k.img"};
base::FilePath build_path = GetBuildArtifactsPath().Append("gen");
for (const string& fs_name : kGeneratedImages) {
LOG(INFO) << "Testing " << fs_name;
- unique_ptr<Ext2Filesystem> fs = Ext2Filesystem::CreateFromFile(
- build_path.Append(fs_name).value());
+ unique_ptr<Ext2Filesystem> fs =
+ Ext2Filesystem::CreateFromFile(build_path.Append(fs_name).value());
ASSERT_NE(nullptr, fs.get());
vector<FilesystemInterface::File> files;
diff --git a/payload_generator/extent_ranges.cc b/payload_generator/extent_ranges.cc
index 41e8f76..0e3f087 100644
--- a/payload_generator/extent_ranges.cc
+++ b/payload_generator/extent_ranges.cc
@@ -85,7 +85,8 @@
ExtentSet::iterator end_del = extent_set_.end();
uint64_t del_blocks = 0;
for (ExtentSet::iterator it = extent_set_.begin(), e = extent_set_.end();
- it != e; ++it) {
+ it != e;
+ ++it) {
if (ExtentsOverlapOrTouch(*it, extent)) {
end_del = it;
++end_del;
@@ -129,7 +130,8 @@
uint64_t del_blocks = 0;
ExtentSet new_extents;
for (ExtentSet::iterator it = extent_set_.begin(), e = extent_set_.end();
- it != e; ++it) {
+ it != e;
+ ++it) {
if (!ExtentsOverlap(*it, extent))
continue;
@@ -142,7 +144,8 @@
ExtentSet subtraction = SubtractOverlappingExtents(*it, extent);
for (ExtentSet::iterator jt = subtraction.begin(), je = subtraction.end();
- jt != je; ++jt) {
+ jt != je;
+ ++jt) {
new_extents.insert(*jt);
del_blocks -= jt->num_blocks();
}
@@ -154,41 +157,47 @@
void ExtentRanges::AddRanges(const ExtentRanges& ranges) {
for (ExtentSet::const_iterator it = ranges.extent_set_.begin(),
- e = ranges.extent_set_.end(); it != e; ++it) {
+ e = ranges.extent_set_.end();
+ it != e;
+ ++it) {
AddExtent(*it);
}
}
void ExtentRanges::SubtractRanges(const ExtentRanges& ranges) {
for (ExtentSet::const_iterator it = ranges.extent_set_.begin(),
- e = ranges.extent_set_.end(); it != e; ++it) {
+ e = ranges.extent_set_.end();
+ it != e;
+ ++it) {
SubtractExtent(*it);
}
}
void ExtentRanges::AddExtents(const vector<Extent>& extents) {
for (vector<Extent>::const_iterator it = extents.begin(), e = extents.end();
- it != e; ++it) {
+ it != e;
+ ++it) {
AddExtent(*it);
}
}
void ExtentRanges::SubtractExtents(const vector<Extent>& extents) {
for (vector<Extent>::const_iterator it = extents.begin(), e = extents.end();
- it != e; ++it) {
+ it != e;
+ ++it) {
SubtractExtent(*it);
}
}
void ExtentRanges::AddRepeatedExtents(
- const ::google::protobuf::RepeatedPtrField<Extent> &exts) {
+ const ::google::protobuf::RepeatedPtrField<Extent>& exts) {
for (int i = 0, e = exts.size(); i != e; ++i) {
AddExtent(exts.Get(i));
}
}
void ExtentRanges::SubtractRepeatedExtents(
- const ::google::protobuf::RepeatedPtrField<Extent> &exts) {
+ const ::google::protobuf::RepeatedPtrField<Extent>& exts) {
for (int i = 0, e = exts.size(); i != e; ++i) {
SubtractExtent(exts.Get(i));
}
@@ -214,8 +223,9 @@
void ExtentRanges::Dump() const {
LOG(INFO) << "ExtentRanges Dump. blocks: " << blocks_;
for (ExtentSet::const_iterator it = extent_set_.begin(),
- e = extent_set_.end();
- it != e; ++it) {
+ e = extent_set_.end();
+ it != e;
+ ++it) {
LOG(INFO) << "{" << it->start_block() << ", " << it->num_blocks() << "}";
}
}
@@ -235,16 +245,16 @@
return ExtentForRange(start_block, end_block - start_block);
}
-vector<Extent> ExtentRanges::GetExtentsForBlockCount(
- uint64_t count) const {
+vector<Extent> ExtentRanges::GetExtentsForBlockCount(uint64_t count) const {
vector<Extent> out;
if (count == 0)
return out;
uint64_t out_blocks = 0;
CHECK(count <= blocks_);
for (ExtentSet::const_iterator it = extent_set_.begin(),
- e = extent_set_.end();
- it != e; ++it) {
+ e = extent_set_.end();
+ it != e;
+ ++it) {
const uint64_t blocks_needed = count - out_blocks;
const Extent& extent = *it;
out.push_back(extent);
@@ -285,8 +295,8 @@
continue;
if (iter->start_block() <= extent.start_block()) {
// We need to cut blocks from the beginning of the |extent|.
- uint64_t cut_blocks = iter->start_block() + iter->num_blocks() -
- extent.start_block();
+ uint64_t cut_blocks =
+ iter->start_block() + iter->num_blocks() - extent.start_block();
if (cut_blocks >= extent.num_blocks()) {
extent.set_num_blocks(0);
break;
@@ -296,9 +306,8 @@
} else {
// We need to cut blocks on the middle of the extent, possible up to the
// end of it.
- result.push_back(
- ExtentForRange(extent.start_block(),
- iter->start_block() - extent.start_block()));
+ result.push_back(ExtentForRange(
+ extent.start_block(), iter->start_block() - extent.start_block()));
uint64_t new_start = iter->start_block() + iter->num_blocks();
uint64_t old_end = extent.start_block() + extent.num_blocks();
if (new_start >= old_end) {
diff --git a/payload_generator/extent_ranges.h b/payload_generator/extent_ranges.h
index 02cf8fc..62ffff4 100644
--- a/payload_generator/extent_ranges.h
+++ b/payload_generator/extent_ranges.h
@@ -57,9 +57,9 @@
void AddExtents(const std::vector<Extent>& extents);
void SubtractExtents(const std::vector<Extent>& extents);
void AddRepeatedExtents(
- const ::google::protobuf::RepeatedPtrField<Extent> &exts);
+ const ::google::protobuf::RepeatedPtrField<Extent>& exts);
void SubtractRepeatedExtents(
- const ::google::protobuf::RepeatedPtrField<Extent> &exts);
+ const ::google::protobuf::RepeatedPtrField<Extent>& exts);
void AddRanges(const ExtentRanges& ranges);
void SubtractRanges(const ExtentRanges& ranges);
diff --git a/payload_generator/extent_ranges_unittest.cc b/payload_generator/extent_ranges_unittest.cc
index d9dd467..2bcffed 100644
--- a/payload_generator/extent_ranges_unittest.cc
+++ b/payload_generator/extent_ranges_unittest.cc
@@ -51,73 +51,57 @@
}
}
-#define EXPECT_RANGE_EQ(ranges, var) \
- do { \
- ExpectRangeEq(ranges, var, arraysize(var), __LINE__); \
+#define EXPECT_RANGE_EQ(ranges, var) \
+ do { \
+ ExpectRangeEq(ranges, var, arraysize(var), __LINE__); \
} while (0)
-void ExpectRangesOverlapOrTouch(uint64_t a_start, uint64_t a_num,
- uint64_t b_start, uint64_t b_num) {
- EXPECT_TRUE(ExtentRanges::ExtentsOverlapOrTouch(ExtentForRange(a_start,
- a_num),
- ExtentForRange(b_start,
- b_num)));
- EXPECT_TRUE(ExtentRanges::ExtentsOverlapOrTouch(ExtentForRange(b_start,
- b_num),
- ExtentForRange(a_start,
- a_num)));
+void ExpectRangesOverlapOrTouch(uint64_t a_start,
+ uint64_t a_num,
+ uint64_t b_start,
+ uint64_t b_num) {
+ EXPECT_TRUE(ExtentRanges::ExtentsOverlapOrTouch(
+ ExtentForRange(a_start, a_num), ExtentForRange(b_start, b_num)));
+ EXPECT_TRUE(ExtentRanges::ExtentsOverlapOrTouch(
+ ExtentForRange(b_start, b_num), ExtentForRange(a_start, a_num)));
}
-void ExpectFalseRangesOverlapOrTouch(uint64_t a_start, uint64_t a_num,
- uint64_t b_start, uint64_t b_num) {
- EXPECT_FALSE(ExtentRanges::ExtentsOverlapOrTouch(ExtentForRange(a_start,
- a_num),
- ExtentForRange(b_start,
- b_num)));
- EXPECT_FALSE(ExtentRanges::ExtentsOverlapOrTouch(ExtentForRange(b_start,
- b_num),
- ExtentForRange(a_start,
- a_num)));
- EXPECT_FALSE(ExtentRanges::ExtentsOverlap(ExtentForRange(a_start,
- a_num),
- ExtentForRange(b_start,
- b_num)));
- EXPECT_FALSE(ExtentRanges::ExtentsOverlap(ExtentForRange(b_start,
- b_num),
- ExtentForRange(a_start,
- a_num)));
+void ExpectFalseRangesOverlapOrTouch(uint64_t a_start,
+ uint64_t a_num,
+ uint64_t b_start,
+ uint64_t b_num) {
+ EXPECT_FALSE(ExtentRanges::ExtentsOverlapOrTouch(
+ ExtentForRange(a_start, a_num), ExtentForRange(b_start, b_num)));
+ EXPECT_FALSE(ExtentRanges::ExtentsOverlapOrTouch(
+ ExtentForRange(b_start, b_num), ExtentForRange(a_start, a_num)));
+ EXPECT_FALSE(ExtentRanges::ExtentsOverlap(ExtentForRange(a_start, a_num),
+ ExtentForRange(b_start, b_num)));
+ EXPECT_FALSE(ExtentRanges::ExtentsOverlap(ExtentForRange(b_start, b_num),
+ ExtentForRange(a_start, a_num)));
}
-void ExpectRangesOverlap(uint64_t a_start, uint64_t a_num,
- uint64_t b_start, uint64_t b_num) {
- EXPECT_TRUE(ExtentRanges::ExtentsOverlap(ExtentForRange(a_start,
- a_num),
- ExtentForRange(b_start,
- b_num)));
- EXPECT_TRUE(ExtentRanges::ExtentsOverlap(ExtentForRange(b_start,
- b_num),
- ExtentForRange(a_start,
- a_num)));
- EXPECT_TRUE(ExtentRanges::ExtentsOverlapOrTouch(ExtentForRange(a_start,
- a_num),
- ExtentForRange(b_start,
- b_num)));
- EXPECT_TRUE(ExtentRanges::ExtentsOverlapOrTouch(ExtentForRange(b_start,
- b_num),
- ExtentForRange(a_start,
- a_num)));
+void ExpectRangesOverlap(uint64_t a_start,
+ uint64_t a_num,
+ uint64_t b_start,
+ uint64_t b_num) {
+ EXPECT_TRUE(ExtentRanges::ExtentsOverlap(ExtentForRange(a_start, a_num),
+ ExtentForRange(b_start, b_num)));
+ EXPECT_TRUE(ExtentRanges::ExtentsOverlap(ExtentForRange(b_start, b_num),
+ ExtentForRange(a_start, a_num)));
+ EXPECT_TRUE(ExtentRanges::ExtentsOverlapOrTouch(
+ ExtentForRange(a_start, a_num), ExtentForRange(b_start, b_num)));
+ EXPECT_TRUE(ExtentRanges::ExtentsOverlapOrTouch(
+ ExtentForRange(b_start, b_num), ExtentForRange(a_start, a_num)));
}
-void ExpectFalseRangesOverlap(uint64_t a_start, uint64_t a_num,
- uint64_t b_start, uint64_t b_num) {
- EXPECT_FALSE(ExtentRanges::ExtentsOverlap(ExtentForRange(a_start,
- a_num),
- ExtentForRange(b_start,
- b_num)));
- EXPECT_FALSE(ExtentRanges::ExtentsOverlap(ExtentForRange(b_start,
- b_num),
- ExtentForRange(a_start,
- a_num)));
+void ExpectFalseRangesOverlap(uint64_t a_start,
+ uint64_t a_num,
+ uint64_t b_start,
+ uint64_t b_num) {
+ EXPECT_FALSE(ExtentRanges::ExtentsOverlap(ExtentForRange(a_start, a_num),
+ ExtentForRange(b_start, b_num)));
+ EXPECT_FALSE(ExtentRanges::ExtentsOverlap(ExtentForRange(b_start, b_num),
+ ExtentForRange(a_start, a_num)));
}
} // namespace
@@ -179,35 +163,31 @@
ranges.AddExtent(ExtentForRange(i, 50));
}
{
- static const uint64_t expected[] = {
- 0, 2, 3, 1, 100, 50, 200, 50, 300, 50, 400, 50,
- 500, 50, 600, 50, 700, 50, 800, 50, 900, 50
- };
+ static const uint64_t expected[] = {0, 2, 3, 1, 100, 50, 200, 50,
+ 300, 50, 400, 50, 500, 50, 600, 50,
+ 700, 50, 800, 50, 900, 50};
EXPECT_RANGE_EQ(ranges, expected);
}
ranges.SubtractExtent(ExtentForRange(210, 410 - 210));
{
- static const uint64_t expected[] = {
- 0, 2, 3, 1, 100, 50, 200, 10, 410, 40, 500, 50,
- 600, 50, 700, 50, 800, 50, 900, 50
- };
+ static const uint64_t expected[] = {0, 2, 3, 1, 100, 50, 200,
+ 10, 410, 40, 500, 50, 600, 50,
+ 700, 50, 800, 50, 900, 50};
EXPECT_RANGE_EQ(ranges, expected);
}
ranges.AddExtent(ExtentForRange(100000, 0));
{
- static const uint64_t expected[] = {
- 0, 2, 3, 1, 100, 50, 200, 10, 410, 40, 500, 50,
- 600, 50, 700, 50, 800, 50, 900, 50
- };
+ static const uint64_t expected[] = {0, 2, 3, 1, 100, 50, 200,
+ 10, 410, 40, 500, 50, 600, 50,
+ 700, 50, 800, 50, 900, 50};
EXPECT_RANGE_EQ(ranges, expected);
}
ranges.SubtractExtent(ExtentForRange(3, 0));
{
- static const uint64_t expected[] = {
- 0, 2, 3, 1, 100, 50, 200, 10, 410, 40, 500, 50,
- 600, 50, 700, 50, 800, 50, 900, 50
- };
+ static const uint64_t expected[] = {0, 2, 3, 1, 100, 50, 200,
+ 10, 410, 40, 500, 50, 600, 50,
+ 700, 50, 800, 50, 900, 50};
EXPECT_RANGE_EQ(ranges, expected);
}
}
@@ -289,25 +269,20 @@
TEST(ExtentRangesTest, FilterExtentRangesEmptyRanges) {
ExtentRanges ranges;
- EXPECT_EQ(vector<Extent>(),
- FilterExtentRanges(vector<Extent>(), ranges));
- EXPECT_EQ(
- vector<Extent>{ ExtentForRange(50, 10) },
- FilterExtentRanges(vector<Extent>{ ExtentForRange(50, 10) }, ranges));
+ EXPECT_EQ(vector<Extent>(), FilterExtentRanges(vector<Extent>(), ranges));
+ EXPECT_EQ(vector<Extent>{ExtentForRange(50, 10)},
+ FilterExtentRanges(vector<Extent>{ExtentForRange(50, 10)}, ranges));
// Check that the empty Extents are ignored.
- EXPECT_EQ(
- (vector<Extent>{ ExtentForRange(10, 10), ExtentForRange(20, 10) }),
- FilterExtentRanges(vector<Extent>{
- ExtentForRange(10, 10),
- ExtentForRange(3, 0),
- ExtentForRange(20, 10) }, ranges));
+ EXPECT_EQ((vector<Extent>{ExtentForRange(10, 10), ExtentForRange(20, 10)}),
+ FilterExtentRanges(vector<Extent>{ExtentForRange(10, 10),
+ ExtentForRange(3, 0),
+ ExtentForRange(20, 10)},
+ ranges));
}
TEST(ExtentRangesTest, FilterExtentRangesMultipleRanges) {
// Two overlapping extents, with three ranges to remove.
- vector<Extent> extents {
- ExtentForRange(10, 100),
- ExtentForRange(30, 100) };
+ vector<Extent> extents{ExtentForRange(10, 100), ExtentForRange(30, 100)};
ExtentRanges ranges;
// This overlaps the beginning of the second extent.
ranges.AddExtent(ExtentForRange(28, 3));
@@ -315,19 +290,17 @@
ranges.AddExtent(ExtentForRange(70, 10));
// This overlaps the end of the second extent.
ranges.AddExtent(ExtentForRange(108, 6));
- EXPECT_EQ(
- (vector<Extent>{
- // For the first extent:
- ExtentForRange(10, 18),
- ExtentForRange(31, 19),
- ExtentForRange(60, 10),
- ExtentForRange(80, 28),
- // For the second extent:
- ExtentForRange(31, 19),
- ExtentForRange(60, 10),
- ExtentForRange(80, 28),
- ExtentForRange(114, 16)}),
- FilterExtentRanges(extents, ranges));
+ EXPECT_EQ((vector<Extent>{// For the first extent:
+ ExtentForRange(10, 18),
+ ExtentForRange(31, 19),
+ ExtentForRange(60, 10),
+ ExtentForRange(80, 28),
+ // For the second extent:
+ ExtentForRange(31, 19),
+ ExtentForRange(60, 10),
+ ExtentForRange(80, 28),
+ ExtentForRange(114, 16)}),
+ FilterExtentRanges(extents, ranges));
}
TEST(ExtentRangesTest, FilterExtentRangesOvelapping) {
@@ -336,10 +309,9 @@
ranges.AddExtent(ExtentForRange(20, 5));
// Requested extent overlaps with one of the ranges.
EXPECT_EQ(vector<Extent>(),
- FilterExtentRanges(vector<Extent>{
- ExtentForRange(10, 1),
- ExtentForRange(22, 1) },
- ranges));
+ FilterExtentRanges(
+ vector<Extent>{ExtentForRange(10, 1), ExtentForRange(22, 1)},
+ ranges));
}
} // namespace chromeos_update_engine
diff --git a/payload_generator/extent_utils.cc b/payload_generator/extent_utils.cc
index 47073f9..c0c7643 100644
--- a/payload_generator/extent_utils.cc
+++ b/payload_generator/extent_utils.cc
@@ -39,8 +39,9 @@
// First try to extend the last extent in |extents|, if any.
if (!extents->empty()) {
Extent& extent = extents->back();
- uint64_t next_block = extent.start_block() == kSparseHole ?
- kSparseHole : extent.start_block() + extent.num_blocks();
+ uint64_t next_block = extent.start_block() == kSparseHole
+ ? kSparseHole
+ : extent.start_block() + extent.num_blocks();
if (next_block == block) {
extent.set_num_blocks(extent.num_blocks() + 1);
return;
@@ -116,7 +117,8 @@
}
vector<Extent> ExtentsSublist(const vector<Extent>& extents,
- uint64_t block_offset, uint64_t block_count) {
+ uint64_t block_offset,
+ uint64_t block_count) {
vector<Extent> result;
uint64_t scanned_blocks = 0;
if (block_count == 0)
diff --git a/payload_generator/extent_utils.h b/payload_generator/extent_utils.h
index f5fbb0e..9763b1f 100644
--- a/payload_generator/extent_utils.h
+++ b/payload_generator/extent_utils.h
@@ -34,7 +34,7 @@
// Takes a collection (vector or RepeatedPtrField) of Extent and
// returns a vector of the blocks referenced, in order.
-template<typename T>
+template <typename T>
std::vector<uint64_t> ExpandExtents(const T& extents) {
std::vector<uint64_t> ret;
for (const auto& extent : extents) {
@@ -42,7 +42,8 @@
ret.resize(ret.size() + extent.num_blocks(), kSparseHole);
} else {
for (uint64_t block = extent.start_block();
- block < (extent.start_block() + extent.num_blocks()); block++) {
+ block < (extent.start_block() + extent.num_blocks());
+ block++) {
ret.push_back(block);
}
}
@@ -64,8 +65,8 @@
// Takes a pointer to extents |extents| and extents |extents_to_add|, and
// merges them by adding |extents_to_add| to |extents| and normalizing.
void ExtendExtents(
- google::protobuf::RepeatedPtrField<Extent>* extents,
- const google::protobuf::RepeatedPtrField<Extent>& extents_to_add);
+ google::protobuf::RepeatedPtrField<Extent>* extents,
+ const google::protobuf::RepeatedPtrField<Extent>& extents_to_add);
// Takes a vector of extents and normalizes those extents. Expects the extents
// to be sorted by start block. E.g. if |extents| is [(1, 2), (3, 5), (10, 2)]
@@ -77,7 +78,8 @@
// blocks. The returned list skips the first |block_offset| blocks from the
// |extents| and cotains |block_count| blocks (or less if |extents| is shorter).
std::vector<Extent> ExtentsSublist(const std::vector<Extent>& extents,
- uint64_t block_offset, uint64_t block_count);
+ uint64_t block_offset,
+ uint64_t block_count);
bool operator==(const Extent& a, const Extent& b);
diff --git a/payload_generator/extent_utils_unittest.cc b/payload_generator/extent_utils_unittest.cc
index eef4385..5467aa5 100644
--- a/payload_generator/extent_utils_unittest.cc
+++ b/payload_generator/extent_utils_unittest.cc
@@ -86,10 +86,10 @@
ExtendExtents(first_op.mutable_src_extents(), second_op.src_extents());
vector<Extent> first_op_vec;
ExtentsToVector(first_op.src_extents(), &first_op_vec);
- EXPECT_EQ((vector<Extent>{
- ExtentForRange(1, 1),
- ExtentForRange(3, 3),
- ExtentForRange(8, 2)}), first_op_vec);
+ EXPECT_EQ(
+ (vector<Extent>{
+ ExtentForRange(1, 1), ExtentForRange(3, 3), ExtentForRange(8, 2)}),
+ first_op_vec);
}
TEST(ExtentUtilsTest, NormalizeExtentsSimpleList) {
@@ -98,21 +98,19 @@
NormalizeExtents(&extents);
EXPECT_EQ(0U, extents.size());
- extents = { ExtentForRange(0, 3) };
+ extents = {ExtentForRange(0, 3)};
NormalizeExtents(&extents);
EXPECT_EQ(1U, extents.size());
EXPECT_EQ(ExtentForRange(0, 3), extents[0]);
}
TEST(ExtentUtilsTest, NormalizeExtentsTest) {
- vector<Extent> extents = {
- ExtentForRange(0, 3),
- ExtentForRange(3, 2),
- ExtentForRange(5, 1),
- ExtentForRange(8, 4),
- ExtentForRange(13, 1),
- ExtentForRange(14, 2)
- };
+ vector<Extent> extents = {ExtentForRange(0, 3),
+ ExtentForRange(3, 2),
+ ExtentForRange(5, 1),
+ ExtentForRange(8, 4),
+ ExtentForRange(13, 1),
+ ExtentForRange(14, 2)};
NormalizeExtents(&extents);
EXPECT_EQ(3U, extents.size());
EXPECT_EQ(ExtentForRange(0, 6), extents[0]);
@@ -122,42 +120,37 @@
TEST(ExtentUtilsTest, ExtentsSublistTest) {
vector<Extent> extents = {
- ExtentForRange(10, 10),
- ExtentForRange(30, 10),
- ExtentForRange(50, 10)
- };
+ ExtentForRange(10, 10), ExtentForRange(30, 10), ExtentForRange(50, 10)};
// Simple empty result cases.
- EXPECT_EQ(vector<Extent>(),
- ExtentsSublist(extents, 1000, 20));
- EXPECT_EQ(vector<Extent>(),
- ExtentsSublist(extents, 5, 0));
- EXPECT_EQ(vector<Extent>(),
- ExtentsSublist(extents, 30, 1));
+ EXPECT_EQ(vector<Extent>(), ExtentsSublist(extents, 1000, 20));
+ EXPECT_EQ(vector<Extent>(), ExtentsSublist(extents, 5, 0));
+ EXPECT_EQ(vector<Extent>(), ExtentsSublist(extents, 30, 1));
// Normal test cases.
- EXPECT_EQ(vector<Extent>{ ExtentForRange(13, 2) },
+ EXPECT_EQ(vector<Extent>{ExtentForRange(13, 2)},
ExtentsSublist(extents, 3, 2));
- EXPECT_EQ(vector<Extent>{ ExtentForRange(15, 5) },
+ EXPECT_EQ(vector<Extent>{ExtentForRange(15, 5)},
ExtentsSublist(extents, 5, 5));
- EXPECT_EQ((vector<Extent>{ ExtentForRange(15, 5), ExtentForRange(30, 5) }),
+ EXPECT_EQ((vector<Extent>{ExtentForRange(15, 5), ExtentForRange(30, 5)}),
ExtentsSublist(extents, 5, 10));
EXPECT_EQ((vector<Extent>{
- ExtentForRange(13, 7),
- ExtentForRange(30, 10),
- ExtentForRange(50, 3), }),
+ ExtentForRange(13, 7),
+ ExtentForRange(30, 10),
+ ExtentForRange(50, 3),
+ }),
ExtentsSublist(extents, 3, 20));
// Extact match case.
- EXPECT_EQ(vector<Extent>{ ExtentForRange(30, 10) },
+ EXPECT_EQ(vector<Extent>{ExtentForRange(30, 10)},
ExtentsSublist(extents, 10, 10));
- EXPECT_EQ(vector<Extent>{ ExtentForRange(50, 10) },
+ EXPECT_EQ(vector<Extent>{ExtentForRange(50, 10)},
ExtentsSublist(extents, 20, 10));
// Cases where the requested num_blocks is too big.
- EXPECT_EQ(vector<Extent>{ ExtentForRange(53, 7) },
+ EXPECT_EQ(vector<Extent>{ExtentForRange(53, 7)},
ExtentsSublist(extents, 23, 100));
- EXPECT_EQ((vector<Extent>{ ExtentForRange(34, 6), ExtentForRange(50, 10) }),
+ EXPECT_EQ((vector<Extent>{ExtentForRange(34, 6), ExtentForRange(50, 10)}),
ExtentsSublist(extents, 14, 100));
}
diff --git a/payload_generator/fake_filesystem.cc b/payload_generator/fake_filesystem.cc
index 234e2f6..7448286 100644
--- a/payload_generator/fake_filesystem.cc
+++ b/payload_generator/fake_filesystem.cc
@@ -20,10 +20,8 @@
namespace chromeos_update_engine {
-FakeFilesystem::FakeFilesystem(uint64_t block_size, uint64_t block_count) :
- block_size_(block_size),
- block_count_(block_count) {
-}
+FakeFilesystem::FakeFilesystem(uint64_t block_size, uint64_t block_count)
+ : block_size_(block_size), block_count_(block_count) {}
size_t FakeFilesystem::GetBlockSize() const {
return block_size_;
diff --git a/payload_generator/fake_filesystem.h b/payload_generator/fake_filesystem.h
index 1b13920..e41a7a2 100644
--- a/payload_generator/fake_filesystem.h
+++ b/payload_generator/fake_filesystem.h
@@ -47,9 +47,7 @@
// Sets the PAYLOAD_MINOR_VERSION key stored by LoadSettings(). Use a negative
// value to produce an error in LoadSettings().
- void SetMinorVersion(int minor_version) {
- minor_version_ = minor_version;
- }
+ void SetMinorVersion(int minor_version) { minor_version_ = minor_version; }
private:
FakeFilesystem() = default;
diff --git a/payload_generator/filesystem_interface.h b/payload_generator/filesystem_interface.h
index 08dfd19..d04295c 100644
--- a/payload_generator/filesystem_interface.h
+++ b/payload_generator/filesystem_interface.h
@@ -45,9 +45,7 @@
// all sort of files, like symlinks, hardlinks, directories and even a file
// entry representing the metadata, free space, journaling data, etc.
struct File {
- File() {
- memset(&file_stat, 0, sizeof(file_stat));
- }
+ File() { memset(&file_stat, 0, sizeof(file_stat)); }
// The stat struct for the file. This is invalid (inode 0) for some
// pseudo-files.
diff --git a/payload_generator/full_update_generator.cc b/payload_generator/full_update_generator.cc
index 98bb0f3..4d8b2f9 100644
--- a/payload_generator/full_update_generator.cc
+++ b/payload_generator/full_update_generator.cc
@@ -95,11 +95,8 @@
brillo::Blob buffer_in_(size_);
brillo::Blob op_blob;
ssize_t bytes_read = -1;
- TEST_AND_RETURN_FALSE(utils::PReadAll(fd_,
- buffer_in_.data(),
- buffer_in_.size(),
- offset_,
- &bytes_read));
+ TEST_AND_RETURN_FALSE(utils::PReadAll(
+ fd_, buffer_in_.data(), buffer_in_.size(), offset_, &bytes_read));
TEST_AND_RETURN_FALSE(bytes_read == static_cast<ssize_t>(size_));
InstallOperation_Type op_type;
@@ -140,10 +137,10 @@
size_t chunk_blocks = full_chunk_size / config.block_size;
size_t max_threads = diff_utils::GetMaxThreads();
- LOG(INFO) << "Compressing partition " << new_part.name
- << " from " << new_part.path << " splitting in chunks of "
- << chunk_blocks << " blocks (" << config.block_size
- << " bytes each) using " << max_threads << " threads";
+ LOG(INFO) << "Compressing partition " << new_part.name << " from "
+ << new_part.path << " splitting in chunks of " << chunk_blocks
+ << " blocks (" << config.block_size << " bytes each) using "
+ << max_threads << " threads";
int in_fd = open(new_part.path.c_str(), O_RDONLY, 0);
TEST_AND_RETURN_FALSE(in_fd >= 0);
@@ -161,14 +158,14 @@
for (size_t i = 0; i < num_chunks; ++i) {
size_t start_block = i * chunk_blocks;
// The last chunk could be smaller.
- size_t num_blocks = std::min(chunk_blocks,
- partition_blocks - i * chunk_blocks);
+ size_t num_blocks =
+ std::min(chunk_blocks, partition_blocks - i * chunk_blocks);
// Preset all the static information about the operations. The
// ChunkProcessor will set the rest.
AnnotatedOperation* aop = aops->data() + i;
- aop->name = base::StringPrintf("<%s-operation-%" PRIuS ">",
- new_part.name.c_str(), i);
+ aop->name = base::StringPrintf(
+ "<%s-operation-%" PRIuS ">", new_part.name.c_str(), i);
Extent* dst_extent = aop->op.add_dst_extents();
dst_extent->set_start_block(start_block);
dst_extent->set_num_blocks(num_blocks);
diff --git a/payload_generator/full_update_generator.h b/payload_generator/full_update_generator.h
index d722028..e17dd37 100644
--- a/payload_generator/full_update_generator.h
+++ b/payload_generator/full_update_generator.h
@@ -37,12 +37,11 @@
// must be a valid payload generation configuration for a full payload.
// Populates |aops|, with data about the update operations, and writes
// relevant data to |blob_file|.
- bool GenerateOperations(
- const PayloadGenerationConfig& config,
- const PartitionConfig& old_part,
- const PartitionConfig& new_part,
- BlobFileWriter* blob_file,
- std::vector<AnnotatedOperation>* aops) override;
+ bool GenerateOperations(const PayloadGenerationConfig& config,
+ const PartitionConfig& old_part,
+ const PartitionConfig& new_part,
+ BlobFileWriter* blob_file,
+ std::vector<AnnotatedOperation>* aops) override;
private:
DISALLOW_COPY_AND_ASSIGN(FullUpdateGenerator);
diff --git a/payload_generator/generate_delta_main.cc b/payload_generator/generate_delta_main.cc
index 05486c5..de0a091 100644
--- a/payload_generator/generate_delta_main.cc
+++ b/payload_generator/generate_delta_main.cc
@@ -56,17 +56,15 @@
void ParseSignatureSizes(const string& signature_sizes_flag,
vector<int>* signature_sizes) {
signature_sizes->clear();
- vector<string> split_strings =
- base::SplitString(signature_sizes_flag, ":", base::TRIM_WHITESPACE,
- base::SPLIT_WANT_ALL);
+ vector<string> split_strings = base::SplitString(
+ signature_sizes_flag, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for (const string& str : split_strings) {
int size = 0;
bool parsing_successful = base::StringToInt(str, &size);
- LOG_IF(FATAL, !parsing_successful)
- << "Invalid signature size: " << str;
+ LOG_IF(FATAL, !parsing_successful) << "Invalid signature size: " << str;
- LOG_IF(FATAL, size != (2048 / 8)) <<
- "Only signature sizes of 256 bytes are supported.";
+ LOG_IF(FATAL, size != (2048 / 8))
+ << "Only signature sizes of 256 bytes are supported.";
signature_sizes->push_back(size);
}
@@ -95,16 +93,16 @@
image_info->set_version(version);
image_info->set_key(key);
- image_info->set_build_channel(
- build_channel.empty() ? channel : build_channel);
+ image_info->set_build_channel(build_channel.empty() ? channel
+ : build_channel);
- image_info->set_build_version(
- build_version.empty() ? version : build_version);
+ image_info->set_build_version(build_version.empty() ? version
+ : build_version);
return true;
}
-void CalculateHashForSigning(const vector<int> &sizes,
+void CalculateHashForSigning(const vector<int>& sizes,
const string& out_hash_file,
const string& out_metadata_hash_file,
const string& in_file) {
@@ -115,12 +113,13 @@
<< "Must pass --out_hash_file to calculate hash for signing.";
brillo::Blob payload_hash, metadata_hash;
- CHECK(PayloadSigner::HashPayloadForSigning(in_file, sizes, &payload_hash,
- &metadata_hash));
- CHECK(utils::WriteFile(out_hash_file.c_str(), payload_hash.data(),
- payload_hash.size()));
+ CHECK(PayloadSigner::HashPayloadForSigning(
+ in_file, sizes, &payload_hash, &metadata_hash));
+ CHECK(utils::WriteFile(
+ out_hash_file.c_str(), payload_hash.data(), payload_hash.size()));
if (!out_metadata_hash_file.empty())
- CHECK(utils::WriteFile(out_metadata_hash_file.c_str(), metadata_hash.data(),
+ CHECK(utils::WriteFile(out_metadata_hash_file.c_str(),
+ metadata_hash.data(),
metadata_hash.size()));
LOG(INFO) << "Done calculating hash for signing.";
@@ -128,9 +127,8 @@
void SignatureFileFlagToBlobs(const string& signature_file_flag,
vector<brillo::Blob>* signatures) {
- vector<string> signature_files =
- base::SplitString(signature_file_flag, ":", base::TRIM_WHITESPACE,
- base::SPLIT_WANT_ALL);
+ vector<string> signature_files = base::SplitString(
+ signature_file_flag, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for (const string& signature_file : signature_files) {
brillo::Blob signature;
CHECK(utils::ReadFile(signature_file, &signature));
@@ -144,10 +142,8 @@
const string& metadata_signature_file,
const string& out_metadata_size_file) {
LOG(INFO) << "Signing payload.";
- LOG_IF(FATAL, in_file.empty())
- << "Must pass --in_file to sign payload.";
- LOG_IF(FATAL, out_file.empty())
- << "Must pass --out_file to sign payload.";
+ LOG_IF(FATAL, in_file.empty()) << "Must pass --in_file to sign payload.";
+ LOG_IF(FATAL, out_file.empty()) << "Must pass --out_file to sign payload.";
LOG_IF(FATAL, payload_signature_file.empty())
<< "Must pass --payload_signature_file to sign payload.";
vector<brillo::Blob> payload_signatures, metadata_signatures;
@@ -290,12 +286,14 @@
DEFINE_string(new_image, "", "Path to the new rootfs");
DEFINE_string(old_kernel, "", "Path to the old kernel partition image");
DEFINE_string(new_kernel, "", "Path to the new kernel partition image");
- DEFINE_string(old_partitions, "",
+ DEFINE_string(old_partitions,
+ "",
"Path to the old partitions. To pass multiple partitions, use "
"a single argument with a colon between paths, e.g. "
"/path/to/part:/path/to/part2::/path/to/last_part . Path can "
"be empty, but it has to match the order of partition_names.");
- DEFINE_string(new_partitions, "",
+ DEFINE_string(new_partitions,
+ "",
"Path to the new partitions. To pass multiple partitions, use "
"a single argument with a colon between paths, e.g. "
"/path/to/part:/path/to/part2:/path/to/last_part . Path has "
@@ -312,26 +310,27 @@
"Path to the .map files associated with the partition files "
"in the new partition, similar to the -old_mapfiles flag.");
DEFINE_string(partition_names,
- string(kPartitionNameRoot) + ":" +
- kPartitionNameKernel,
+ string(kPartitionNameRoot) + ":" + kPartitionNameKernel,
"Names of the partitions. To pass multiple names, use a single "
"argument with a colon between names, e.g. "
"name:name2:name3:last_name . Name can not be empty, and it "
"has to match the order of partitions.");
- DEFINE_string(in_file, "",
+ DEFINE_string(in_file,
+ "",
"Path to input delta payload file used to hash/sign payloads "
"and apply delta over old_image (for debugging)");
DEFINE_string(out_file, "", "Path to output delta payload file");
DEFINE_string(out_hash_file, "", "Path to output hash file");
- DEFINE_string(out_metadata_hash_file, "",
- "Path to output metadata hash file");
- DEFINE_string(out_metadata_size_file, "",
- "Path to output metadata size file");
+ DEFINE_string(
+ out_metadata_hash_file, "", "Path to output metadata hash file");
+ DEFINE_string(
+ out_metadata_size_file, "", "Path to output metadata size file");
DEFINE_string(private_key, "", "Path to private key in .pem format");
DEFINE_string(public_key, "", "Path to public key in .pem format");
- DEFINE_int32(public_key_version, -1,
- "DEPRECATED. Key-check version # of client");
- DEFINE_string(signature_size, "",
+ DEFINE_int32(
+ public_key_version, -1, "DEPRECATED. Key-check version # of client");
+ DEFINE_string(signature_size,
+ "",
"Raw signature size used for hash calculation. "
"You may pass in multiple sizes by colon separating them. E.g. "
"2048:2048:4096 will assume 3 signatures, the first two with "
@@ -343,22 +342,25 @@
"e.g. /path/to/sig:/path/to/next:/path/to/last_sig . Each "
"signature will be assigned a client version, starting from "
"kSignatureOriginalVersion.");
- DEFINE_string(metadata_signature_file, "",
+ DEFINE_string(metadata_signature_file,
+ "",
"Raw signature file with the signature of the metadata hash. "
"To pass multiple signatures, use a single argument with a "
"colon between paths, "
"e.g. /path/to/sig:/path/to/next:/path/to/last_sig .");
- DEFINE_int32(chunk_size, 200 * 1024 * 1024,
- "Payload chunk size (-1 for whole files)");
+ DEFINE_int32(
+ chunk_size, 200 * 1024 * 1024, "Payload chunk size (-1 for whole files)");
DEFINE_uint64(rootfs_partition_size,
- chromeos_update_engine::kRootFSPartitionSize,
- "RootFS partition size for the image once installed");
- DEFINE_uint64(major_version, 2,
- "The major version of the payload being generated.");
- DEFINE_int32(minor_version, -1,
+ chromeos_update_engine::kRootFSPartitionSize,
+ "RootFS partition size for the image once installed");
+ DEFINE_uint64(
+ major_version, 2, "The major version of the payload being generated.");
+ DEFINE_int32(minor_version,
+ -1,
"The minor version of the payload being generated "
"(-1 means autodetect).");
- DEFINE_string(properties_file, "",
+ DEFINE_string(properties_file,
+ "",
"If passed, dumps the payload properties of the payload passed "
"in --in_file and exits.");
DEFINE_int64(max_timestamp,
@@ -366,42 +368,53 @@
"The maximum timestamp of the OS allowed to apply this "
"payload.");
- DEFINE_string(old_channel, "",
+ DEFINE_string(old_channel,
+ "",
"The channel for the old image. 'dev-channel', 'npo-channel', "
"etc. Ignored, except during delta generation.");
- DEFINE_string(old_board, "",
+ DEFINE_string(old_board,
+ "",
"The board for the old image. 'x86-mario', 'lumpy', "
"etc. Ignored, except during delta generation.");
- DEFINE_string(old_version, "",
- "The build version of the old image. 1.2.3, etc.");
- DEFINE_string(old_key, "",
+ DEFINE_string(
+ old_version, "", "The build version of the old image. 1.2.3, etc.");
+ DEFINE_string(old_key,
+ "",
"The key used to sign the old image. 'premp', 'mp', 'mp-v3',"
" etc");
- DEFINE_string(old_build_channel, "",
+ DEFINE_string(old_build_channel,
+ "",
"The channel for the build of the old image. 'dev-channel', "
"etc, but will never contain special channels such as "
"'npo-channel'. Ignored, except during delta generation.");
- DEFINE_string(old_build_version, "",
+ DEFINE_string(old_build_version,
+ "",
"The version of the build containing the old image.");
- DEFINE_string(new_channel, "",
+ DEFINE_string(new_channel,
+ "",
"The channel for the new image. 'dev-channel', 'npo-channel', "
"etc. Ignored, except during delta generation.");
- DEFINE_string(new_board, "",
+ DEFINE_string(new_board,
+ "",
"The board for the new image. 'x86-mario', 'lumpy', "
"etc. Ignored, except during delta generation.");
- DEFINE_string(new_version, "",
- "The build version of the new image. 1.2.3, etc.");
- DEFINE_string(new_key, "",
+ DEFINE_string(
+ new_version, "", "The build version of the new image. 1.2.3, etc.");
+ DEFINE_string(new_key,
+ "",
"The key used to sign the new image. 'premp', 'mp', 'mp-v3',"
" etc");
- DEFINE_string(new_build_channel, "",
+ DEFINE_string(new_build_channel,
+ "",
"The channel for the build of the new image. 'dev-channel', "
"etc, but will never contain special channels such as "
"'npo-channel'. Ignored, except during delta generation.");
- DEFINE_string(new_build_version, "",
+ DEFINE_string(new_build_version,
+ "",
"The version of the build containing the new image.");
- DEFINE_string(new_postinstall_config_file, "",
+ DEFINE_string(new_postinstall_config_file,
+ "",
"A config file specifying postinstall related metadata. "
"Only allowed in major version 2 or newer.");
DEFINE_string(dynamic_partition_info_file,
@@ -409,7 +422,9 @@
"An info file specifying dynamic partition metadata. "
"Only allowed in major version 2 or newer.");
- brillo::FlagHelper::Init(argc, argv,
+ brillo::FlagHelper::Init(
+ argc,
+ argv,
"Generates a payload to provide to ChromeOS' update_engine.\n\n"
"This tool can create full payloads and also delta payloads if the src\n"
"image is provided. It also provides debugging options to apply, sign\n"
@@ -417,10 +432,10 @@
Terminator::Init();
logging::LoggingSettings log_settings;
- log_settings.log_file = "delta_generator.log";
+ log_settings.log_file = "delta_generator.log";
log_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
- log_settings.lock_log = logging::LOCK_LOG_FILE;
- log_settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE;
+ log_settings.lock_log = logging::LOCK_LOG_FILE;
+ log_settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE;
logging::InitLogging(log_settings);
@@ -432,8 +447,10 @@
if (!FLAGS_out_hash_file.empty() || !FLAGS_out_metadata_hash_file.empty()) {
CHECK(FLAGS_out_metadata_size_file.empty());
- CalculateHashForSigning(signature_sizes, FLAGS_out_hash_file,
- FLAGS_out_metadata_hash_file, FLAGS_in_file);
+ CalculateHashForSigning(signature_sizes,
+ FLAGS_out_hash_file,
+ FLAGS_out_metadata_hash_file,
+ FLAGS_in_file);
return 0;
}
if (!FLAGS_payload_signature_file.empty()) {
@@ -468,17 +485,17 @@
FLAGS_new_mapfiles, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
}
- partition_names =
- base::SplitString(FLAGS_partition_names, ":", base::TRIM_WHITESPACE,
- base::SPLIT_WANT_ALL);
+ partition_names = base::SplitString(
+ FLAGS_partition_names, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
CHECK(!partition_names.empty());
if (FLAGS_major_version == kChromeOSMajorPayloadVersion ||
FLAGS_new_partitions.empty()) {
LOG_IF(FATAL, partition_names.size() != 2)
<< "To support more than 2 partitions, please use the "
<< "--new_partitions flag and major version 2.";
- LOG_IF(FATAL, partition_names[0] != kPartitionNameRoot ||
- partition_names[1] != kPartitionNameKernel)
+ LOG_IF(FATAL,
+ partition_names[0] != kPartitionNameRoot ||
+ partition_names[1] != kPartitionNameKernel)
<< "To support non-default partition name, please use the "
<< "--new_partitions flag and major version 2.";
}
@@ -487,9 +504,8 @@
LOG_IF(FATAL, !FLAGS_new_image.empty() || !FLAGS_new_kernel.empty())
<< "--new_image and --new_kernel are deprecated, please use "
<< "--new_partitions for all partitions.";
- new_partitions =
- base::SplitString(FLAGS_new_partitions, ":", base::TRIM_WHITESPACE,
- base::SPLIT_WANT_ALL);
+ new_partitions = base::SplitString(
+ FLAGS_new_partitions, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
CHECK(partition_names.size() == new_partitions.size());
payload_config.is_delta = !FLAGS_old_partitions.empty();
@@ -501,8 +517,8 @@
LOG(WARNING) << "--new_partitions is empty, using deprecated --new_image "
<< "and --new_kernel flags.";
- payload_config.is_delta = !FLAGS_old_image.empty() ||
- !FLAGS_old_kernel.empty();
+ payload_config.is_delta =
+ !FLAGS_old_image.empty() || !FLAGS_old_kernel.empty();
LOG_IF(FATAL, !FLAGS_old_partitions.empty())
<< "Please use --new_partitions if you are using --old_partitions.";
}
@@ -517,9 +533,10 @@
if (payload_config.is_delta) {
if (!FLAGS_old_partitions.empty()) {
- old_partitions =
- base::SplitString(FLAGS_old_partitions, ":", base::TRIM_WHITESPACE,
- base::SPLIT_WANT_ALL);
+ old_partitions = base::SplitString(FLAGS_old_partitions,
+ ":",
+ base::TRIM_WHITESPACE,
+ base::SPLIT_WANT_ALL);
CHECK(old_partitions.size() == new_partitions.size());
} else {
old_partitions = {FLAGS_old_image, FLAGS_old_kernel};
@@ -638,10 +655,8 @@
}
uint64_t metadata_size;
- if (!GenerateUpdatePayloadFile(payload_config,
- FLAGS_out_file,
- FLAGS_private_key,
- &metadata_size)) {
+ if (!GenerateUpdatePayloadFile(
+ payload_config, FLAGS_out_file, FLAGS_private_key, &metadata_size)) {
return 1;
}
if (!FLAGS_out_metadata_size_file.empty()) {
diff --git a/payload_generator/graph_types.cc b/payload_generator/graph_types.cc
index 7da76f7..c03766d 100644
--- a/payload_generator/graph_types.cc
+++ b/payload_generator/graph_types.cc
@@ -20,4 +20,4 @@
const Vertex::Index Vertex::kInvalidIndex = static_cast<Vertex::Index>(-1);
-} // chromeos_update_engine
+} // namespace chromeos_update_engine
diff --git a/payload_generator/graph_types.h b/payload_generator/graph_types.h
index fee8575..f96b0f3 100644
--- a/payload_generator/graph_types.h
+++ b/payload_generator/graph_types.h
@@ -51,10 +51,7 @@
};
struct Vertex {
- Vertex() :
- valid(true),
- index(-1),
- lowlink(-1) {}
+ Vertex() : valid(true), index(-1), lowlink(-1) {}
bool valid;
typedef std::map<std::vector<Vertex>::size_type, EdgeProperties> EdgeMap;
diff --git a/payload_generator/graph_utils.cc b/payload_generator/graph_utils.cc
index 4829b21..7f5cf8f 100644
--- a/payload_generator/graph_utils.cc
+++ b/payload_generator/graph_utils.cc
@@ -39,17 +39,15 @@
uint64_t weight = 0;
const vector<Extent>& extents =
graph[edge.first].out_edges.find(edge.second)->second.extents;
- for (vector<Extent>::const_iterator it = extents.begin();
- it != extents.end(); ++it) {
+ for (vector<Extent>::const_iterator it = extents.begin(); it != extents.end();
+ ++it) {
if (it->start_block() != kSparseHole)
weight += it->num_blocks();
}
return weight;
}
-void AddReadBeforeDep(Vertex* src,
- Vertex::Index dst,
- uint64_t block) {
+void AddReadBeforeDep(Vertex* src, Vertex::Index dst, uint64_t block) {
Vertex::EdgeMap::iterator edge_it = src->out_edges.find(dst);
if (edge_it == src->out_edges.end()) {
// Must create new edge
@@ -66,11 +64,13 @@
const vector<Extent>& extents) {
// TODO(adlr): Be more efficient than adding each block individually.
for (vector<Extent>::const_iterator it = extents.begin(), e = extents.end();
- it != e; ++it) {
+ it != e;
+ ++it) {
const Extent& extent = *it;
for (uint64_t block = extent.start_block(),
- block_end = extent.start_block() + extent.num_blocks();
- block != block_end; ++block) {
+ block_end = extent.start_block() + extent.num_blocks();
+ block != block_end;
+ ++block) {
AddReadBeforeDep(src, dst, block);
}
}
@@ -79,7 +79,7 @@
void DropWriteBeforeDeps(Vertex::EdgeMap* edge_map) {
// Specially crafted for-loop for the map-iterate-delete dance.
for (Vertex::EdgeMap::iterator it = edge_map->begin();
- it != edge_map->end(); ) {
+ it != edge_map->end();) {
if (!it->second.write_extents.empty())
it->second.write_extents.clear();
if (it->second.extents.empty()) {
@@ -101,7 +101,7 @@
}
namespace {
-template<typename T>
+template <typename T>
void DumpExtents(const T& field, int prepend_space_count) {
string header(prepend_space_count, ' ');
for (const auto& extent : field) {
@@ -112,7 +112,9 @@
void DumpOutEdges(const Vertex::EdgeMap& out_edges) {
for (Vertex::EdgeMap::const_iterator it = out_edges.begin(),
- e = out_edges.end(); it != e; ++it) {
+ e = out_edges.end();
+ it != e;
+ ++it) {
LOG(INFO) << " " << it->first << " read-before:";
DumpExtents(it->second.extents, 6);
LOG(INFO) << " write-before:";
@@ -124,10 +126,9 @@
void DumpGraph(const Graph& graph) {
LOG(INFO) << "Graph length: " << graph.size();
for (Graph::size_type i = 0, e = graph.size(); i != e; ++i) {
- LOG(INFO) << i
- << (graph[i].valid ? "" : "-INV")
- << ": " << graph[i].aop.name
- << ": " << InstallOperationTypeName(graph[i].aop.op.type());
+ LOG(INFO) << i << (graph[i].valid ? "" : "-INV") << ": "
+ << graph[i].aop.name << ": "
+ << InstallOperationTypeName(graph[i].aop.op.type());
LOG(INFO) << " src_extents:";
DumpExtents(graph[i].aop.op.src_extents(), 4);
LOG(INFO) << " dst_extents:";
diff --git a/payload_generator/graph_utils.h b/payload_generator/graph_utils.h
index b32e666..7024215 100644
--- a/payload_generator/graph_utils.h
+++ b/payload_generator/graph_utils.h
@@ -35,9 +35,7 @@
// These add a read-before dependency from graph[src] -> graph[dst]. If the dep
// already exists, the block/s is/are added to the existing edge.
-void AddReadBeforeDep(Vertex* src,
- Vertex::Index dst,
- uint64_t block);
+void AddReadBeforeDep(Vertex* src, Vertex::Index dst, uint64_t block);
void AddReadBeforeDepExtents(Vertex* src,
Vertex::Index dst,
const std::vector<Extent>& extents);
diff --git a/payload_generator/graph_utils_unittest.cc b/payload_generator/graph_utils_unittest.cc
index dddf815..07e7664 100644
--- a/payload_generator/graph_utils_unittest.cc
+++ b/payload_generator/graph_utils_unittest.cc
@@ -56,7 +56,6 @@
EXPECT_EQ(4U, graph_utils::EdgeWeight(graph, make_pair(0, 1)));
}
-
TEST(GraphUtilsTest, DepsTest) {
Graph graph(3);
@@ -74,8 +73,8 @@
EXPECT_EQ(3U, extent.start_block());
EXPECT_EQ(2U, extent.num_blocks());
}
- graph_utils::AddReadBeforeDepExtents(&graph[2], 1,
- vector<Extent>(1, ExtentForRange(5, 2)));
+ graph_utils::AddReadBeforeDepExtents(
+ &graph[2], 1, vector<Extent>(1, ExtentForRange(5, 2)));
EXPECT_EQ(1U, graph[2].out_edges.size());
{
Extent& extent = graph[2].out_edges[1].extents[0];
diff --git a/payload_generator/inplace_generator.cc b/payload_generator/inplace_generator.cc
index 62608e5..ee19b62 100644
--- a/payload_generator/inplace_generator.cc
+++ b/payload_generator/inplace_generator.cc
@@ -86,7 +86,7 @@
class IndexedInstallOperationsDstComparator {
public:
explicit IndexedInstallOperationsDstComparator(Graph* graph)
- : graph_(graph) {}
+ : graph_(graph) {}
// Compares the operations in the vertex a and b of graph_.
bool operator()(size_t a, size_t b) const {
@@ -106,27 +106,25 @@
}
}
-void InplaceGenerator::SubstituteBlocks(
- Vertex* vertex,
- const vector<Extent>& remove_extents,
- const vector<Extent>& replace_extents) {
+void InplaceGenerator::SubstituteBlocks(Vertex* vertex,
+ const vector<Extent>& remove_extents,
+ const vector<Extent>& replace_extents) {
// First, expand out the blocks that op reads from
- vector<uint64_t> read_blocks =
- ExpandExtents(vertex->aop.op.src_extents());
+ vector<uint64_t> read_blocks = ExpandExtents(vertex->aop.op.src_extents());
{
// Expand remove_extents and replace_extents
vector<uint64_t> remove_extents_expanded = ExpandExtents(remove_extents);
vector<uint64_t> replace_extents_expanded = ExpandExtents(replace_extents);
CHECK_EQ(remove_extents_expanded.size(), replace_extents_expanded.size());
map<uint64_t, uint64_t> conversion;
- for (vector<uint64_t>::size_type i = 0;
- i < replace_extents_expanded.size(); i++) {
+ for (vector<uint64_t>::size_type i = 0; i < replace_extents_expanded.size();
+ i++) {
conversion[remove_extents_expanded[i]] = replace_extents_expanded[i];
}
ApplyMap(&read_blocks, conversion);
for (auto& edge_prop_pair : vertex->out_edges) {
- vector<uint64_t> write_before_deps_expanded = ExpandExtents(
- edge_prop_pair.second.write_extents);
+ vector<uint64_t> write_before_deps_expanded =
+ ExpandExtents(edge_prop_pair.second.write_extents);
ApplyMap(&write_before_deps_expanded, conversion);
edge_prop_pair.second.write_extents =
CompressExtents(write_before_deps_expanded);
@@ -170,8 +168,8 @@
<< "Can't cut edge that has write-before relationship.";
// make node depend on the copy operation
- (*graph)[edge.first].out_edges.insert(make_pair(graph->size() - 1,
- cut_edge_properties));
+ (*graph)[edge.first].out_edges.insert(
+ make_pair(graph->size() - 1, cut_edge_properties));
// Set src/dst extents and other proto variables for copy operation
graph->back().aop.op.set_type(InstallOperation::MOVE);
@@ -179,15 +177,14 @@
graph->back().aop.op.mutable_src_extents());
StoreExtents(cuts.back().tmp_extents,
graph->back().aop.op.mutable_dst_extents());
- graph->back().aop.op.set_src_length(
- graph_utils::EdgeWeight(*graph, edge) * kBlockSize);
+ graph->back().aop.op.set_src_length(graph_utils::EdgeWeight(*graph, edge) *
+ kBlockSize);
graph->back().aop.op.set_dst_length(graph->back().aop.op.src_length());
// make the dest node read from the scratch space
- SubstituteBlocks(
- &((*graph)[edge.second]),
- (*graph)[edge.first].out_edges[edge.second].extents,
- cuts.back().tmp_extents);
+ SubstituteBlocks(&((*graph)[edge.second]),
+ (*graph)[edge.first].out_edges[edge.second].extents,
+ cuts.back().tmp_extents);
// delete the old edge
CHECK_EQ(static_cast<Graph::size_type>(1),
@@ -206,11 +203,8 @@
// Creates all the edges for the graph. Writers of a block point to
// readers of the same block. This is because for an edge A->B, B
// must complete before A executes.
-void InplaceGenerator::CreateEdges(
- Graph* graph,
- const vector<Block>& blocks) {
- for (vector<Block>::size_type i = 0;
- i < blocks.size(); i++) {
+void InplaceGenerator::CreateEdges(Graph* graph, const vector<Block>& blocks) {
+ for (vector<Block>::size_type i = 0; i < blocks.size(); i++) {
// Blocks with both a reader and writer get an edge
if (blocks[i].reader == Vertex::kInvalidIndex ||
blocks[i].writer == Vertex::kInvalidIndex)
@@ -242,6 +236,7 @@
bool operator()(const CutEdgeVertexes& a, const CutEdgeVertexes& b) {
return table_[a.old_dst] < table_[b.old_dst];
}
+
private:
const vector<vector<Vertex::Index>::size_type>& table_;
};
@@ -252,8 +247,8 @@
const vector<Vertex::Index>& op_indexes,
vector<vector<Vertex::Index>::size_type>* reverse_op_indexes) {
vector<vector<Vertex::Index>::size_type> table(op_indexes.size());
- for (vector<Vertex::Index>::size_type i = 0, e = op_indexes.size();
- i != e; ++i) {
+ for (vector<Vertex::Index>::size_type i = 0, e = op_indexes.size(); i != e;
+ ++i) {
Vertex::Index node = op_indexes[i];
if (table.size() < (node + 1)) {
table.resize(node + 1);
@@ -264,8 +259,7 @@
}
void InplaceGenerator::SortCutsByTopoOrder(
- const vector<Vertex::Index>& op_indexes,
- vector<CutEdgeVertexes>* cuts) {
+ const vector<Vertex::Index>& op_indexes, vector<CutEdgeVertexes>* cuts) {
// first, make a reverse lookup table.
vector<vector<Vertex::Index>::size_type> table;
GenerateReverseTopoOrderMap(op_indexes, &table);
@@ -274,8 +268,7 @@
}
void InplaceGenerator::MoveAndSortFullOpsToBack(
- Graph* graph,
- vector<Vertex::Index>* op_indexes) {
+ Graph* graph, vector<Vertex::Index>* op_indexes) {
vector<Vertex::Index> ret;
vector<Vertex::Index> full_ops;
ret.reserve(op_indexes->size());
@@ -291,7 +284,8 @@
LOG(INFO) << "Stats: " << full_ops.size() << " full ops out of "
<< (full_ops.size() + ret.size()) << " total ops.";
// Sort full ops according to their dst_extents.
- sort(full_ops.begin(), full_ops.end(),
+ sort(full_ops.begin(),
+ full_ops.end(),
IndexedInstallOperationsDstComparator(graph));
ret.insert(ret.end(), full_ops.begin(), full_ops.end());
op_indexes->swap(ret);
@@ -299,7 +293,7 @@
namespace {
-template<typename T>
+template <typename T>
bool TempBlocksExistInExtents(const T& extents) {
for (const auto& extent : extents) {
uint64_t start = extent.start_block();
@@ -331,11 +325,8 @@
CHECK(!cuts.empty());
set<Vertex::Index> deleted_nodes;
for (const CutEdgeVertexes& cut : cuts) {
- TEST_AND_RETURN_FALSE(InplaceGenerator::ConvertCutToFullOp(
- graph,
- cut,
- new_part,
- blob_file));
+ TEST_AND_RETURN_FALSE(
+ InplaceGenerator::ConvertCutToFullOp(graph, cut, new_part, blob_file));
deleted_nodes.insert(cut.new_vertex);
}
deleted_nodes.insert(cuts[0].old_dst);
@@ -387,22 +378,25 @@
SupplierVector block_suppliers;
uint64_t scratch_blocks_found = 0;
for (vector<Vertex::Index>::size_type i = (*reverse_op_indexes)[old_dst] + 1,
- e = op_indexes->size(); i < e; ++i) {
+ e = op_indexes->size();
+ i < e;
+ ++i) {
Vertex::Index test_node = (*op_indexes)[i];
if (!(*graph)[test_node].valid)
continue;
// See if this node has sufficient blocks
ExtentRanges ranges;
ranges.AddRepeatedExtents((*graph)[test_node].aop.op.dst_extents());
- ranges.SubtractExtent(ExtentForRange(
- kTempBlockStart, kSparseHole - kTempBlockStart));
+ ranges.SubtractExtent(
+ ExtentForRange(kTempBlockStart, kSparseHole - kTempBlockStart));
ranges.SubtractRepeatedExtents((*graph)[test_node].aop.op.src_extents());
// For now, for simplicity, subtract out all blocks in read-before
// dependencies.
- for (Vertex::EdgeMap::const_iterator edge_i =
- (*graph)[test_node].out_edges.begin(),
+ for (Vertex::EdgeMap::const_iterator
+ edge_i = (*graph)[test_node].out_edges.begin(),
edge_e = (*graph)[test_node].out_edges.end();
- edge_i != edge_e; ++edge_i) {
+ edge_i != edge_e;
+ ++edge_i) {
ranges.SubtractExtents(edge_i->second.extents);
}
@@ -418,8 +412,8 @@
if (ranges.blocks() + scratch_blocks_found > blocks_needed) {
// trim down ranges
- vector<Extent> new_ranges = ranges.GetExtentsForBlockCount(
- blocks_needed - scratch_blocks_found);
+ vector<Extent> new_ranges =
+ ranges.GetExtentsForBlockCount(blocks_needed - scratch_blocks_found);
ranges = ExtentRanges();
ranges.AddExtents(new_ranges);
}
@@ -431,12 +425,8 @@
}
if (scratch_ranges.blocks() < blocks_needed) {
LOG(INFO) << "Unable to find sufficient scratch";
- TEST_AND_RETURN_FALSE(ConvertCutsToFull(graph,
- new_part,
- blob_file,
- op_indexes,
- reverse_op_indexes,
- cuts));
+ TEST_AND_RETURN_FALSE(ConvertCutsToFull(
+ graph, new_part, blob_file, op_indexes, reverse_op_indexes, cuts));
return true;
}
// Use the scratch we found
@@ -459,9 +449,8 @@
scratch_ranges.SubtractExtents(real_extents);
// Fix the old dest node w/ the real blocks
- InplaceGenerator::SubstituteBlocks(&(*graph)[old_dst],
- cut.tmp_extents,
- real_extents);
+ InplaceGenerator::SubstituteBlocks(
+ &(*graph)[old_dst], cut.tmp_extents, real_extents);
// Fix the new node w/ the real blocks. Since the new node is just a
// copy operation, we can replace all the dest extents w/ the real
@@ -487,12 +476,12 @@
// group of cuts w/ the same old_dst:
vector<CutEdgeVertexes> cuts_group;
- for (vector<CutEdgeVertexes>::size_type i = cuts.size() - 1, e = 0;
- true ; --i) {
+ for (vector<CutEdgeVertexes>::size_type i = cuts.size() - 1, e = 0; true;
+ --i) {
LOG(INFO) << "Fixing temp blocks in cut " << i
- << ": old dst: " << cuts[i].old_dst << " new vertex: "
- << cuts[i].new_vertex << " path: "
- << (*graph)[cuts[i].old_dst].aop.name;
+ << ": old dst: " << cuts[i].old_dst
+ << " new vertex: " << cuts[i].new_vertex
+ << " path: " << (*graph)[cuts[i].old_dst].aop.name;
if (cuts_group.empty() || (cuts_group[0].old_dst == cuts[i].old_dst)) {
cuts_group.push_back(cuts[i]);
@@ -514,12 +503,8 @@
}
}
CHECK(!cuts_group.empty());
- TEST_AND_RETURN_FALSE(AssignBlockForAdjoiningCuts(graph,
- new_part,
- blob_file,
- op_indexes,
- reverse_op_indexes,
- cuts_group));
+ TEST_AND_RETURN_FALSE(AssignBlockForAdjoiningCuts(
+ graph, new_part, blob_file, op_indexes, reverse_op_indexes, cuts_group));
return true;
}
@@ -566,8 +551,7 @@
// |new_extents| list of blocks and update the graph.
vector<AnnotatedOperation> new_aop;
vector<Extent> new_extents;
- ExtentsToVector((*graph)[cut.old_dst].aop.op.dst_extents(),
- &new_extents);
+ ExtentsToVector((*graph)[cut.old_dst].aop.op.dst_extents(), &new_extents);
TEST_AND_RETURN_FALSE(diff_utils::DeltaReadFile(
&new_aop,
"", // old_part
@@ -582,7 +566,7 @@
blob_file));
TEST_AND_RETURN_FALSE(new_aop.size() == 1);
TEST_AND_RETURN_FALSE(AddInstallOpToGraph(
- graph, cut.old_dst, nullptr, new_aop.front().op, new_aop.front().name));
+ graph, cut.old_dst, nullptr, new_aop.front().op, new_aop.front().name));
(*graph)[cut.old_dst].out_edges = out_edges;
@@ -636,12 +620,8 @@
SortCutsByTopoOrder(*final_order, &cuts);
if (!cuts.empty())
- TEST_AND_RETURN_FALSE(AssignTempBlocks(graph,
- new_part,
- blob_file,
- final_order,
- &inverse_final_order,
- cuts));
+ TEST_AND_RETURN_FALSE(AssignTempBlocks(
+ graph, new_part, blob_file, final_order, &inverse_final_order, cuts));
LOG(INFO) << "Making sure all temp blocks have been allocated";
// Remove the scratch node, if any
@@ -683,19 +663,19 @@
const char* past_participle = (field == READER) ? "read" : "written";
const google::protobuf::RepeatedPtrField<Extent>& extents =
(field == READER) ? operation.src_extents() : operation.dst_extents();
- Vertex::Index Block::*access_type = (field == READER) ?
- &Block::reader : &Block::writer;
+ Vertex::Index Block::*access_type =
+ (field == READER) ? &Block::reader : &Block::writer;
for (const Extent& extent : extents) {
for (uint64_t block = extent.start_block();
- block < (extent.start_block() + extent.num_blocks()); block++) {
+ block < (extent.start_block() + extent.num_blocks());
+ block++) {
if ((*blocks)[block].*access_type != Vertex::kInvalidIndex) {
- LOG(FATAL) << "Block " << block << " is already "
- << past_participle << " by "
- << (*blocks)[block].*access_type << "("
+ LOG(FATAL) << "Block " << block << " is already " << past_participle
+ << " by " << (*blocks)[block].*access_type << "("
<< graph[(*blocks)[block].*access_type].aop.name
- << ") and also " << vertex << "("
- << graph[vertex].aop.name << ")";
+ << ") and also " << vertex << "(" << graph[vertex].aop.name
+ << ")";
}
(*blocks)[block].*access_type = vertex;
}
@@ -720,10 +700,7 @@
if (blocks)
TEST_AND_RETURN_FALSE(InplaceGenerator::AddInstallOpToBlocksVector(
- (*graph)[vertex].aop.op,
- *graph,
- vertex,
- blocks));
+ (*graph)[vertex].aop.op, *graph, vertex, blocks));
return true;
}
@@ -771,11 +748,7 @@
vector<Vertex::Index> final_order;
TEST_AND_RETURN_FALSE(ConvertGraphToDag(
- &graph,
- new_part.path,
- blob_file,
- &final_order,
- scratch_vertex));
+ &graph, new_part.path, blob_file, &final_order, scratch_vertex));
// Copy operations over to the |aops| vector in the final_order generated by
// the topological sort.
@@ -788,18 +761,19 @@
return true;
}
-bool InplaceGenerator::GenerateOperations(
- const PayloadGenerationConfig& config,
- const PartitionConfig& old_part,
- const PartitionConfig& new_part,
- BlobFileWriter* blob_file,
- vector<AnnotatedOperation>* aops) {
+bool InplaceGenerator::GenerateOperations(const PayloadGenerationConfig& config,
+ const PartitionConfig& old_part,
+ const PartitionConfig& new_part,
+ BlobFileWriter* blob_file,
+ vector<AnnotatedOperation>* aops) {
TEST_AND_RETURN_FALSE(old_part.name == new_part.name);
TEST_AND_RETURN_FALSE(config.version.major == kInPlacePayloadVersion.major);
TEST_AND_RETURN_FALSE(config.version.minor == kInPlacePayloadVersion.minor);
- ssize_t hard_chunk_blocks = (config.hard_chunk_size == -1 ? -1 :
- config.hard_chunk_size / config.block_size);
+ ssize_t hard_chunk_blocks =
+ (config.hard_chunk_size == -1
+ ? -1
+ : config.hard_chunk_size / config.block_size);
size_t soft_chunk_blocks = config.soft_chunk_size / config.block_size;
uint64_t partition_size = new_part.size;
if (new_part.name == kPartitionNameRoot)
diff --git a/payload_generator/inplace_generator.h b/payload_generator/inplace_generator.h
index f108639..e7298d2 100644
--- a/payload_generator/inplace_generator.h
+++ b/payload_generator/inplace_generator.h
@@ -97,8 +97,7 @@
// Creates all the edges for the graph. Writers of a block point to
// readers of the same block. This is because for an edge A->B, B
// must complete before A executes.
- static void CreateEdges(Graph* graph,
- const std::vector<Block>& blocks);
+ static void CreateEdges(Graph* graph, const std::vector<Block>& blocks);
// Takes |op_indexes|, which is effectively a mapping from order in
// which the op is performed -> graph vertex index, and produces the
@@ -109,15 +108,14 @@
// Sorts the vector |cuts| by its |cuts[].old_dest| member. Order is
// determined by the order of elements in op_indexes.
- static void SortCutsByTopoOrder(
- const std::vector<Vertex::Index>& op_indexes,
- std::vector<CutEdgeVertexes>* cuts);
+ static void SortCutsByTopoOrder(const std::vector<Vertex::Index>& op_indexes,
+ std::vector<CutEdgeVertexes>* cuts);
// Given a topologically sorted graph |op_indexes| and |graph|, alters
// |op_indexes| to move all the full operations to the end of the vector.
// Full operations should not be depended on, so this is safe.
static void MoveAndSortFullOpsToBack(Graph* graph,
- std::vector<Vertex::Index>* op_indexes);
+ std::vector<Vertex::Index>* op_indexes);
// Returns true iff there are no extents in the graph that refer to temp
// blocks. Temp blocks are in the range [kTempBlockStart, kSparseHole).
@@ -227,12 +225,11 @@
// a delta update with the minor version kInPlaceMinorPayloadVersion.
// The operations are stored in |aops|. All the offsets in the operations
// reference the data written to |blob_file|.
- bool GenerateOperations(
- const PayloadGenerationConfig& config,
- const PartitionConfig& old_part,
- const PartitionConfig& new_part,
- BlobFileWriter* blob_file,
- std::vector<AnnotatedOperation>* aops) override;
+ bool GenerateOperations(const PayloadGenerationConfig& config,
+ const PartitionConfig& old_part,
+ const PartitionConfig& new_part,
+ BlobFileWriter* blob_file,
+ std::vector<AnnotatedOperation>* aops) override;
private:
DISALLOW_COPY_AND_ASSIGN(InplaceGenerator);
diff --git a/payload_generator/inplace_generator_unittest.cc b/payload_generator/inplace_generator_unittest.cc
index 20ac50b..ab3b867 100644
--- a/payload_generator/inplace_generator_unittest.cc
+++ b/payload_generator/inplace_generator_unittest.cc
@@ -17,6 +17,7 @@
#include "update_engine/payload_generator/inplace_generator.h"
#include <map>
+#include <memory>
#include <set>
#include <sstream>
#include <string>
@@ -77,11 +78,12 @@
return ret;
}
-template<typename T>
+template <typename T>
void DumpVect(const vector<T>& vect) {
stringstream ss(stringstream::out);
for (typename vector<T>::const_iterator it = vect.begin(), e = vect.end();
- it != e; ++it) {
+ it != e;
+ ++it) {
ss << *it << ", ";
}
LOG(INFO) << "{" << ss.str() << "}";
@@ -241,8 +243,8 @@
cycle_breaker.BreakCycles(graph, &cut_edges);
EXPECT_EQ(1U, cut_edges.size());
- EXPECT_TRUE(cut_edges.end() != cut_edges.find(
- std::pair<Vertex::Index, Vertex::Index>(1, 0)));
+ EXPECT_TRUE(cut_edges.end() !=
+ cut_edges.find(std::pair<Vertex::Index, Vertex::Index>(1, 0)));
vector<CutEdgeVertexes> cuts;
EXPECT_TRUE(InplaceGenerator::CutEdges(&graph, cut_edges, &cuts));
@@ -274,8 +276,8 @@
// Ensure it only depends on the next node and the new temp node
EXPECT_EQ(2U, graph[0].out_edges.size());
EXPECT_TRUE(graph[0].out_edges.end() != graph[0].out_edges.find(1));
- EXPECT_TRUE(graph[0].out_edges.end() != graph[0].out_edges.find(graph.size() -
- 1));
+ EXPECT_TRUE(graph[0].out_edges.end() !=
+ graph[0].out_edges.find(graph.size() - 1));
// Check second node has unchanged extents
EXPECT_EQ(2, graph[1].aop.op.src_extents_size());
@@ -737,8 +739,8 @@
if (aop.op.type() == InstallOperation::MOVE) {
move_ops++;
for (const Extent& extent : aop.op.dst_extents()) {
- EXPECT_LE(7U, extent.start_block()) << "On dst extents for aop: "
- << aop;
+ EXPECT_LE(7U, extent.start_block())
+ << "On dst extents for aop: " << aop;
}
}
}
diff --git a/payload_generator/operations_generator.h b/payload_generator/operations_generator.h
index 9127d7b..4d7322b 100644
--- a/payload_generator/operations_generator.h
+++ b/payload_generator/operations_generator.h
@@ -40,12 +40,11 @@
// The operations generated will refer to offsets in the file |blob_file|,
// where this function stores the output, but not necessarily in the same
// order as they appear in the |aops|.
- virtual bool GenerateOperations(
- const PayloadGenerationConfig& config,
- const PartitionConfig& old_part,
- const PartitionConfig& new_part,
- BlobFileWriter* blob_file,
- std::vector<AnnotatedOperation>* aops) = 0;
+ virtual bool GenerateOperations(const PayloadGenerationConfig& config,
+ const PartitionConfig& old_part,
+ const PartitionConfig& new_part,
+ BlobFileWriter* blob_file,
+ std::vector<AnnotatedOperation>* aops) = 0;
protected:
OperationsGenerator() = default;
diff --git a/payload_generator/payload_file.cc b/payload_generator/payload_file.cc
index d0aa71e..775a509 100644
--- a/payload_generator/payload_file.cc
+++ b/payload_generator/payload_file.cc
@@ -41,10 +41,8 @@
struct DeltaObject {
DeltaObject(const string& in_name, const int in_type, const off_t in_size)
- : name(in_name),
- type(in_type),
- size(in_size) {}
- bool operator <(const DeltaObject& object) const {
+ : name(in_name), type(in_type), size(in_size) {}
+ bool operator<(const DeltaObject& object) const {
return (size != object.size) ? (size < object.size) : (name < object.name);
}
string name;
@@ -90,8 +88,8 @@
const vector<AnnotatedOperation>& aops) {
// Check partitions order for Chrome OS
if (major_version_ == kChromeOSMajorPayloadVersion) {
- const vector<const char*> part_order = { kPartitionNameRoot,
- kPartitionNameKernel };
+ const vector<const char*> part_order = {kPartitionNameRoot,
+ kPartitionNameKernel};
TEST_AND_RETURN_FALSE(part_vec_.size() < part_order.size());
TEST_AND_RETURN_FALSE(new_conf.name == part_order[part_vec_.size()]);
}
@@ -102,10 +100,10 @@
part.verity = new_conf.verity;
// Initialize the PartitionInfo objects if present.
if (!old_conf.path.empty())
- TEST_AND_RETURN_FALSE(diff_utils::InitializePartitionInfo(old_conf,
- &part.old_info));
- TEST_AND_RETURN_FALSE(diff_utils::InitializePartitionInfo(new_conf,
- &part.new_info));
+ TEST_AND_RETURN_FALSE(
+ diff_utils::InitializePartitionInfo(old_conf, &part.old_info));
+ TEST_AND_RETURN_FALSE(
+ diff_utils::InitializePartitionInfo(new_conf, &part.new_info));
part_vec_.push_back(std::move(part));
return true;
}
@@ -117,9 +115,7 @@
// Reorder the data blobs with the manifest_.
string ordered_blobs_path;
TEST_AND_RETURN_FALSE(utils::MakeTempFile(
- "CrAU_temp_data.ordered.XXXXXX",
- &ordered_blobs_path,
- nullptr));
+ "CrAU_temp_data.ordered.XXXXXX", &ordered_blobs_path, nullptr));
ScopedPathUnlinker ordered_blobs_unlinker(ordered_blobs_path);
TEST_AND_RETURN_FALSE(ReorderDataBlobs(data_blobs_path, ordered_blobs_path));
@@ -130,8 +126,8 @@
if (!aop.op.has_data_offset())
continue;
if (aop.op.data_offset() != next_blob_offset) {
- LOG(FATAL) << "bad blob offset! " << aop.op.data_offset() << " != "
- << next_blob_offset;
+ LOG(FATAL) << "bad blob offset! " << aop.op.data_offset()
+ << " != " << next_blob_offset;
}
next_blob_offset += aop.op.data_length();
}
@@ -200,12 +196,13 @@
// manifest_.
uint64_t signature_blob_length = 0;
if (!private_key_path.empty()) {
- TEST_AND_RETURN_FALSE(
- PayloadSigner::SignatureBlobLength(vector<string>(1, private_key_path),
- &signature_blob_length));
+ TEST_AND_RETURN_FALSE(PayloadSigner::SignatureBlobLength(
+ vector<string>(1, private_key_path), &signature_blob_length));
PayloadSigner::AddSignatureToManifest(
- next_blob_offset, signature_blob_length,
- major_version_ == kChromeOSMajorPayloadVersion, &manifest_);
+ next_blob_offset,
+ signature_blob_length,
+ major_version_ == kChromeOSMajorPayloadVersion,
+ &manifest_);
}
// Serialize protobuf
@@ -229,8 +226,8 @@
TEST_AND_RETURN_FALSE(WriteUint64AsBigEndian(&writer, major_version_));
// Write protobuf length
- TEST_AND_RETURN_FALSE(WriteUint64AsBigEndian(&writer,
- serialized_manifest.size()));
+ TEST_AND_RETURN_FALSE(
+ WriteUint64AsBigEndian(&writer, serialized_manifest.size()));
// Write metadata signature size.
uint32_t metadata_signature_size = 0;
@@ -255,9 +252,8 @@
if (major_version_ == kBrilloMajorPayloadVersion &&
!private_key_path.empty()) {
brillo::Blob metadata_hash, metadata_signature;
- TEST_AND_RETURN_FALSE(HashCalculator::RawHashOfFile(payload_file,
- metadata_size,
- &metadata_hash));
+ TEST_AND_RETURN_FALSE(HashCalculator::RawHashOfFile(
+ payload_file, metadata_size, &metadata_hash));
TEST_AND_RETURN_FALSE(
PayloadSigner::SignHashWithKeys(metadata_hash,
vector<string>(1, private_key_path),
@@ -302,9 +298,8 @@
return true;
}
-bool PayloadFile::ReorderDataBlobs(
- const string& data_blobs_path,
- const string& new_data_blobs_path) {
+bool PayloadFile::ReorderDataBlobs(const string& data_blobs_path,
+ const string& new_data_blobs_path) {
int in_fd = open(data_blobs_path.c_str(), O_RDONLY, 0);
TEST_AND_RETURN_FALSE_ERRNO(in_fd >= 0);
ScopedFdCloser in_fd_closer(&in_fd);
diff --git a/payload_generator/payload_generation_config.cc b/payload_generator/payload_generation_config.cc
index e7d8ae5..694c71f 100644
--- a/payload_generator/payload_generation_config.cc
+++ b/payload_generator/payload_generation_config.cc
@@ -198,12 +198,10 @@
}
bool ImageConfig::ImageInfoIsEmpty() const {
- return image_info.board().empty()
- && image_info.key().empty()
- && image_info.channel().empty()
- && image_info.version().empty()
- && image_info.build_channel().empty()
- && image_info.build_version().empty();
+ return image_info.board().empty() && image_info.key().empty() &&
+ image_info.channel().empty() && image_info.version().empty() &&
+ image_info.build_channel().empty() &&
+ image_info.build_version().empty();
}
PayloadVersion::PayloadVersion(uint64_t major_version, uint32_t minor_version) {
diff --git a/payload_generator/payload_signer.cc b/payload_generator/payload_signer.cc
index 35a0c3f..2d0489a 100644
--- a/payload_generator/payload_signer.cc
+++ b/payload_generator/payload_signer.cc
@@ -67,9 +67,8 @@
// Serialize protobuf
string serialized;
TEST_AND_RETURN_FALSE(out_message.AppendToString(&serialized));
- out_signature_blob->insert(out_signature_blob->end(),
- serialized.begin(),
- serialized.end());
+ out_signature_blob->insert(
+ out_signature_blob->end(), serialized.begin(), serialized.end());
LOG(INFO) << "Signature blob size: " << out_signature_blob->size();
return true;
}
@@ -103,7 +102,8 @@
// Write metadata signature size in header.
uint32_t metadata_signature_size_be =
htobe32(metadata_signature_blob.size());
- memcpy(payload.data() + manifest_offset, &metadata_signature_size_be,
+ memcpy(payload.data() + manifest_offset,
+ &metadata_signature_size_be,
sizeof(metadata_signature_size_be));
manifest_offset += sizeof(metadata_signature_size_be);
// Replace metadata signature.
@@ -159,8 +159,8 @@
LOG(INFO) << "Updated payload size: " << payload.size();
LOG(INFO) << "Updated metadata size: " << metadata_size;
}
- uint64_t signatures_offset = metadata_size + metadata_signature_size +
- manifest.signatures_offset();
+ uint64_t signatures_offset =
+ metadata_size + metadata_signature_size + manifest.signatures_offset();
LOG(INFO) << "Signature Blob Offset: " << signatures_offset;
payload.resize(signatures_offset);
payload.insert(payload.begin() + signatures_offset,
@@ -186,9 +186,8 @@
brillo::Blob* out_metadata_hash) {
if (out_metadata_hash) {
// Calculates the hash on the manifest.
- TEST_AND_RETURN_FALSE(
- HashCalculator::RawHashOfBytes(payload.data(), metadata_size,
- out_metadata_hash));
+ TEST_AND_RETURN_FALSE(HashCalculator::RawHashOfBytes(
+ payload.data(), metadata_size, out_metadata_hash));
}
if (out_hash_data) {
// Calculates the hash on the updated payload. Note that we skip metadata
@@ -319,8 +318,8 @@
TEST_AND_RETURN_FALSE(SignHash(hash_data, path, &signature));
signatures.push_back(signature);
}
- TEST_AND_RETURN_FALSE(ConvertSignatureToProtobufBlob(signatures,
- out_signature_blob));
+ TEST_AND_RETURN_FALSE(
+ ConvertSignatureToProtobufBlob(signatures, out_signature_blob));
return true;
}
@@ -339,9 +338,8 @@
signatures_offset,
&hash_data,
nullptr));
- TEST_AND_RETURN_FALSE(SignHashWithKeys(hash_data,
- private_key_paths,
- out_signature_blob));
+ TEST_AND_RETURN_FALSE(
+ SignHashWithKeys(hash_data, private_key_paths, out_signature_blob));
return true;
}
@@ -349,9 +347,8 @@
uint64_t* out_length) {
DCHECK(out_length);
brillo::Blob x_blob(1, 'x'), hash_blob, sig_blob;
- TEST_AND_RETURN_FALSE(HashCalculator::RawHashOfBytes(x_blob.data(),
- x_blob.size(),
- &hash_blob));
+ TEST_AND_RETURN_FALSE(
+ HashCalculator::RawHashOfBytes(x_blob.data(), x_blob.size(), &hash_blob));
TEST_AND_RETURN_FALSE(
SignHashWithKeys(hash_blob, private_key_paths, &sig_blob));
*out_length = sig_blob.size();
@@ -369,8 +366,8 @@
signatures.emplace_back(signature_size, 0);
}
brillo::Blob signature_blob;
- TEST_AND_RETURN_FALSE(ConvertSignatureToProtobufBlob(signatures,
- &signature_blob));
+ TEST_AND_RETURN_FALSE(
+ ConvertSignatureToProtobufBlob(signatures, &signature_blob));
brillo::Blob payload;
uint64_t metadata_size, signatures_offset;
@@ -397,17 +394,16 @@
const vector<brillo::Blob>& payload_signatures,
const vector<brillo::Blob>& metadata_signatures,
const string& signed_payload_path,
- uint64_t *out_metadata_size) {
+ uint64_t* out_metadata_size) {
// TODO(petkov): Reduce memory usage -- the payload is manipulated in memory.
// Loads the payload and adds the signature op to it.
brillo::Blob signature_blob, metadata_signature_blob;
- TEST_AND_RETURN_FALSE(ConvertSignatureToProtobufBlob(payload_signatures,
- &signature_blob));
+ TEST_AND_RETURN_FALSE(
+ ConvertSignatureToProtobufBlob(payload_signatures, &signature_blob));
if (!metadata_signatures.empty()) {
- TEST_AND_RETURN_FALSE(
- ConvertSignatureToProtobufBlob(metadata_signatures,
- &metadata_signature_blob));
+ TEST_AND_RETURN_FALSE(ConvertSignatureToProtobufBlob(
+ metadata_signatures, &metadata_signature_blob));
}
brillo::Blob payload;
uint64_t signatures_offset;
@@ -421,9 +417,8 @@
&signatures_offset));
LOG(INFO) << "Signed payload size: " << payload.size();
- TEST_AND_RETURN_FALSE(utils::WriteFile(signed_payload_path.c_str(),
- payload.data(),
- payload.size()));
+ TEST_AND_RETURN_FALSE(utils::WriteFile(
+ signed_payload_path.c_str(), payload.data(), payload.size()));
return true;
}
@@ -434,14 +429,11 @@
// Calculates the hash on the updated payload. Note that the payload includes
// the signature op but doesn't include the signature blob at the end.
brillo::Blob metadata_hash;
- TEST_AND_RETURN_FALSE(HashCalculator::RawHashOfBytes(metadata,
- metadata_size,
- &metadata_hash));
+ TEST_AND_RETURN_FALSE(
+ HashCalculator::RawHashOfBytes(metadata, metadata_size, &metadata_hash));
brillo::Blob signature;
- TEST_AND_RETURN_FALSE(SignHash(metadata_hash,
- private_key_path,
- &signature));
+ TEST_AND_RETURN_FALSE(SignHash(metadata_hash, private_key_path, &signature));
*out_signature = brillo::data_encoding::Base64Encode(signature);
return true;
diff --git a/payload_generator/payload_signer.h b/payload_generator/payload_signer.h
index 38c673c..b2d6606 100644
--- a/payload_generator/payload_signer.h
+++ b/payload_generator/payload_signer.h
@@ -77,8 +77,7 @@
// Returns the length of out_signature_blob that will result in a call
// to SignPayload with the given private keys. Returns true on success.
static bool SignatureBlobLength(
- const std::vector<std::string>& private_key_paths,
- uint64_t* out_length);
+ const std::vector<std::string>& private_key_paths, uint64_t* out_length);
// Given an unsigned payload in |payload_path|,
// this method does two things:
diff --git a/payload_generator/payload_signer_unittest.cc b/payload_generator/payload_signer_unittest.cc
index a6ef38d..52d51bc 100644
--- a/payload_generator/payload_signer_unittest.cc
+++ b/payload_generator/payload_signer_unittest.cc
@@ -51,12 +51,10 @@
// Generated by:
// echo -n 'This is some data to sign.' | openssl dgst -sha256 -binary |
// hexdump -v -e '" " 8/1 "0x%02x, " "\n"'
-const uint8_t kDataHash[] = {
- 0x7a, 0x07, 0xa6, 0x44, 0x08, 0x86, 0x20, 0xa6,
- 0xc1, 0xf8, 0xd9, 0x02, 0x05, 0x63, 0x0d, 0xb7,
- 0xfc, 0x2b, 0xa0, 0xa9, 0x7c, 0x9d, 0x1d, 0x8c,
- 0x01, 0xf5, 0x78, 0x6d, 0xc5, 0x11, 0xb4, 0x06
-};
+const uint8_t kDataHash[] = {0x7a, 0x07, 0xa6, 0x44, 0x08, 0x86, 0x20, 0xa6,
+ 0xc1, 0xf8, 0xd9, 0x02, 0x05, 0x63, 0x0d, 0xb7,
+ 0xfc, 0x2b, 0xa0, 0xa9, 0x7c, 0x9d, 0x1d, 0x8c,
+ 0x01, 0xf5, 0x78, 0x6d, 0xc5, 0x11, 0xb4, 0x06};
// Generated with openssl 1.0, which at the time of this writing, you need
// to download and install yourself. Here's my command:
@@ -64,39 +62,28 @@
// ~/local/bin/openssl pkeyutl -sign -inkey unittest_key.pem -pkeyopt
// digest:sha256 | hexdump -v -e '" " 8/1 "0x%02x, " "\n"'
const uint8_t kDataSignature[] = {
- 0x9f, 0x86, 0x25, 0x8b, 0xf3, 0xcc, 0xe3, 0x95,
- 0x5f, 0x45, 0x83, 0xb2, 0x66, 0xf0, 0x2a, 0xcf,
- 0xb7, 0xaa, 0x52, 0x25, 0x7a, 0xdd, 0x9d, 0x65,
- 0xe5, 0xd6, 0x02, 0x4b, 0x37, 0x99, 0x53, 0x06,
- 0xc2, 0xc9, 0x37, 0x36, 0x25, 0x62, 0x09, 0x4f,
- 0x6b, 0x22, 0xf8, 0xb3, 0x89, 0x14, 0x98, 0x1a,
- 0xbc, 0x30, 0x90, 0x4a, 0x43, 0xf5, 0xea, 0x2e,
- 0xf0, 0xa4, 0xba, 0xc3, 0xa7, 0xa3, 0x44, 0x70,
- 0xd6, 0xc4, 0x89, 0xd8, 0x45, 0x71, 0xbb, 0xee,
- 0x59, 0x87, 0x3d, 0xd5, 0xe5, 0x40, 0x22, 0x3d,
- 0x73, 0x7e, 0x2a, 0x58, 0x93, 0x8e, 0xcb, 0x9c,
- 0xf2, 0xbb, 0x4a, 0xc9, 0xd2, 0x2c, 0x52, 0x42,
- 0xb0, 0xd1, 0x13, 0x22, 0xa4, 0x78, 0xc7, 0xc6,
- 0x3e, 0xf1, 0xdc, 0x4c, 0x7b, 0x2d, 0x40, 0xda,
- 0x58, 0xac, 0x4a, 0x11, 0x96, 0x3d, 0xa0, 0x01,
- 0xf6, 0x96, 0x74, 0xf6, 0x6c, 0x0c, 0x49, 0x69,
- 0x4e, 0xc1, 0x7e, 0x9f, 0x2a, 0x42, 0xdd, 0x15,
- 0x6b, 0x37, 0x2e, 0x3a, 0xa7, 0xa7, 0x6d, 0x91,
- 0x13, 0xe8, 0x59, 0xde, 0xfe, 0x99, 0x07, 0xd9,
- 0x34, 0x0f, 0x17, 0xb3, 0x05, 0x4c, 0xd2, 0xc6,
- 0x82, 0xb7, 0x38, 0x36, 0x63, 0x1d, 0x9e, 0x21,
- 0xa6, 0x32, 0xef, 0xf1, 0x65, 0xe6, 0xed, 0x95,
- 0x25, 0x9b, 0x61, 0xe0, 0xba, 0x86, 0xa1, 0x7f,
- 0xf8, 0xa5, 0x4a, 0x32, 0x1f, 0x15, 0x20, 0x8a,
- 0x41, 0xc5, 0xb0, 0xd9, 0x4a, 0xda, 0x85, 0xf3,
- 0xdc, 0xa0, 0x98, 0x5d, 0x1d, 0x18, 0x9d, 0x2e,
- 0x42, 0xea, 0x69, 0x13, 0x74, 0x3c, 0x74, 0xf7,
- 0x6d, 0x43, 0xb0, 0x63, 0x90, 0xdb, 0x04, 0xd5,
- 0x05, 0xc9, 0x73, 0x1f, 0x6c, 0xd6, 0xfa, 0x46,
- 0x4e, 0x0f, 0x33, 0x58, 0x5b, 0x0d, 0x1b, 0x55,
- 0x39, 0xb9, 0x0f, 0x43, 0x37, 0xc0, 0x06, 0x0c,
- 0x29, 0x93, 0x43, 0xc7, 0x43, 0xb9, 0xab, 0x7d
-};
+ 0x9f, 0x86, 0x25, 0x8b, 0xf3, 0xcc, 0xe3, 0x95, 0x5f, 0x45, 0x83, 0xb2,
+ 0x66, 0xf0, 0x2a, 0xcf, 0xb7, 0xaa, 0x52, 0x25, 0x7a, 0xdd, 0x9d, 0x65,
+ 0xe5, 0xd6, 0x02, 0x4b, 0x37, 0x99, 0x53, 0x06, 0xc2, 0xc9, 0x37, 0x36,
+ 0x25, 0x62, 0x09, 0x4f, 0x6b, 0x22, 0xf8, 0xb3, 0x89, 0x14, 0x98, 0x1a,
+ 0xbc, 0x30, 0x90, 0x4a, 0x43, 0xf5, 0xea, 0x2e, 0xf0, 0xa4, 0xba, 0xc3,
+ 0xa7, 0xa3, 0x44, 0x70, 0xd6, 0xc4, 0x89, 0xd8, 0x45, 0x71, 0xbb, 0xee,
+ 0x59, 0x87, 0x3d, 0xd5, 0xe5, 0x40, 0x22, 0x3d, 0x73, 0x7e, 0x2a, 0x58,
+ 0x93, 0x8e, 0xcb, 0x9c, 0xf2, 0xbb, 0x4a, 0xc9, 0xd2, 0x2c, 0x52, 0x42,
+ 0xb0, 0xd1, 0x13, 0x22, 0xa4, 0x78, 0xc7, 0xc6, 0x3e, 0xf1, 0xdc, 0x4c,
+ 0x7b, 0x2d, 0x40, 0xda, 0x58, 0xac, 0x4a, 0x11, 0x96, 0x3d, 0xa0, 0x01,
+ 0xf6, 0x96, 0x74, 0xf6, 0x6c, 0x0c, 0x49, 0x69, 0x4e, 0xc1, 0x7e, 0x9f,
+ 0x2a, 0x42, 0xdd, 0x15, 0x6b, 0x37, 0x2e, 0x3a, 0xa7, 0xa7, 0x6d, 0x91,
+ 0x13, 0xe8, 0x59, 0xde, 0xfe, 0x99, 0x07, 0xd9, 0x34, 0x0f, 0x17, 0xb3,
+ 0x05, 0x4c, 0xd2, 0xc6, 0x82, 0xb7, 0x38, 0x36, 0x63, 0x1d, 0x9e, 0x21,
+ 0xa6, 0x32, 0xef, 0xf1, 0x65, 0xe6, 0xed, 0x95, 0x25, 0x9b, 0x61, 0xe0,
+ 0xba, 0x86, 0xa1, 0x7f, 0xf8, 0xa5, 0x4a, 0x32, 0x1f, 0x15, 0x20, 0x8a,
+ 0x41, 0xc5, 0xb0, 0xd9, 0x4a, 0xda, 0x85, 0xf3, 0xdc, 0xa0, 0x98, 0x5d,
+ 0x1d, 0x18, 0x9d, 0x2e, 0x42, 0xea, 0x69, 0x13, 0x74, 0x3c, 0x74, 0xf7,
+ 0x6d, 0x43, 0xb0, 0x63, 0x90, 0xdb, 0x04, 0xd5, 0x05, 0xc9, 0x73, 0x1f,
+ 0x6c, 0xd6, 0xfa, 0x46, 0x4e, 0x0f, 0x33, 0x58, 0x5b, 0x0d, 0x1b, 0x55,
+ 0x39, 0xb9, 0x0f, 0x43, 0x37, 0xc0, 0x06, 0x0c, 0x29, 0x93, 0x43, 0xc7,
+ 0x43, 0xb9, 0xab, 0x7d};
namespace {
void SignSampleData(brillo::Blob* out_signature_blob,
@@ -107,13 +94,10 @@
EXPECT_TRUE(PayloadSigner::SignatureBlobLength(private_keys, &length));
EXPECT_GT(length, 0U);
brillo::Blob hash_blob;
- EXPECT_TRUE(HashCalculator::RawHashOfBytes(data_blob.data(),
- data_blob.size(),
- &hash_blob));
+ EXPECT_TRUE(HashCalculator::RawHashOfBytes(
+ data_blob.data(), data_blob.size(), &hash_blob));
EXPECT_TRUE(PayloadSigner::SignHashWithKeys(
- hash_blob,
- private_keys,
- out_signature_blob));
+ hash_blob, private_keys, out_signature_blob));
EXPECT_EQ(length, out_signature_blob->size());
}
} // namespace
@@ -134,8 +118,8 @@
// Check the signature itself
Signatures signatures;
- EXPECT_TRUE(signatures.ParseFromArray(signature_blob.data(),
- signature_blob.size()));
+ EXPECT_TRUE(
+ signatures.ParseFromArray(signature_blob.data(), signature_blob.size()));
EXPECT_EQ(1, signatures.signatures_size());
const Signatures_Signature& signature = signatures.signatures(0);
EXPECT_EQ(1U, signature.version());
diff --git a/payload_generator/raw_filesystem.cc b/payload_generator/raw_filesystem.cc
index 2fb1400..f1f0890 100644
--- a/payload_generator/raw_filesystem.cc
+++ b/payload_generator/raw_filesystem.cc
@@ -16,6 +16,8 @@
#include "update_engine/payload_generator/raw_filesystem.h"
+#include <memory>
+
#include "update_engine/common/utils.h"
#include "update_engine/payload_generator/extent_ranges.h"
#include "update_engine/update_metadata.pb.h"
@@ -24,8 +26,9 @@
namespace chromeos_update_engine {
-unique_ptr<RawFilesystem> RawFilesystem::Create(
- const std::string& filename, uint64_t block_size, uint64_t block_count) {
+unique_ptr<RawFilesystem> RawFilesystem::Create(const std::string& filename,
+ uint64_t block_size,
+ uint64_t block_count) {
unique_ptr<RawFilesystem> result(new RawFilesystem());
result->filename_ = filename;
result->block_size_ = block_size;
@@ -45,7 +48,7 @@
files->clear();
File file;
file.name = filename_;
- file.extents = { ExtentForRange(0, block_count_) };
+ file.extents = {ExtentForRange(0, block_count_)};
files->push_back(file);
return true;
}
diff --git a/payload_generator/raw_filesystem.h b/payload_generator/raw_filesystem.h
index 0aecd81..0ecbc9c 100644
--- a/payload_generator/raw_filesystem.h
+++ b/payload_generator/raw_filesystem.h
@@ -22,6 +22,7 @@
#include "update_engine/payload_generator/filesystem_interface.h"
+#include <memory>
#include <string>
#include <vector>
@@ -29,8 +30,9 @@
class RawFilesystem : public FilesystemInterface {
public:
- static std::unique_ptr<RawFilesystem> Create(
- const std::string& filename, uint64_t block_size, uint64_t block_count);
+ static std::unique_ptr<RawFilesystem> Create(const std::string& filename,
+ uint64_t block_size,
+ uint64_t block_count);
virtual ~RawFilesystem() = default;
// FilesystemInterface overrides.
diff --git a/payload_generator/tarjan.cc b/payload_generator/tarjan.cc
index d99ae12..2d4ca31 100644
--- a/payload_generator/tarjan.cc
+++ b/payload_generator/tarjan.cc
@@ -52,15 +52,16 @@
index_++;
stack_.push_back(vertex);
for (Vertex::EdgeMap::iterator it = (*graph)[vertex].out_edges.begin();
- it != (*graph)[vertex].out_edges.end(); ++it) {
+ it != (*graph)[vertex].out_edges.end();
+ ++it) {
Vertex::Index vertex_next = it->first;
if ((*graph)[vertex_next].index == kInvalidIndex) {
Tarjan(vertex_next, graph);
- (*graph)[vertex].lowlink = min((*graph)[vertex].lowlink,
- (*graph)[vertex_next].lowlink);
+ (*graph)[vertex].lowlink =
+ min((*graph)[vertex].lowlink, (*graph)[vertex_next].lowlink);
} else if (base::ContainsValue(stack_, vertex_next)) {
- (*graph)[vertex].lowlink = min((*graph)[vertex].lowlink,
- (*graph)[vertex_next].index);
+ (*graph)[vertex].lowlink =
+ min((*graph)[vertex].lowlink, (*graph)[vertex_next].index);
}
}
if ((*graph)[vertex].lowlink == (*graph)[vertex].index) {
diff --git a/payload_generator/tarjan.h b/payload_generator/tarjan.h
index 50cf563..39ac4e4 100644
--- a/payload_generator/tarjan.h
+++ b/payload_generator/tarjan.h
@@ -38,6 +38,7 @@
void Execute(Vertex::Index vertex,
Graph* graph,
std::vector<Vertex::Index>* out);
+
private:
void Tarjan(Vertex::Index vertex, Graph* graph);
diff --git a/payload_generator/topological_sort.cc b/payload_generator/topological_sort.cc
index f164336..0abd708 100644
--- a/payload_generator/topological_sort.cc
+++ b/payload_generator/topological_sort.cc
@@ -37,7 +37,8 @@
visited_nodes->insert(node);
// Visit all children.
for (Vertex::EdgeMap::const_iterator it = graph[node].out_edges.begin();
- it != graph[node].out_edges.end(); ++it) {
+ it != graph[node].out_edges.end();
+ ++it) {
TopologicalSortVisit(graph, visited_nodes, nodes, it->first);
}
// Visit this node.
diff --git a/payload_generator/topological_sort_unittest.cc b/payload_generator/topological_sort_unittest.cc
index 1d866a7..aa296d8 100644
--- a/payload_generator/topological_sort_unittest.cc
+++ b/payload_generator/topological_sort_unittest.cc
@@ -33,7 +33,7 @@
namespace {
// Returns true if the value is found in vect. If found, the index is stored
// in out_index if out_index is not null.
-template<typename T>
+template <typename T>
bool IndexOf(const vector<T>& vect,
const T& value,
typename vector<T>::size_type* out_index) {
@@ -84,7 +84,8 @@
vector<Vertex::Index>::size_type src_index = 0;
EXPECT_TRUE(IndexOf(sorted, i, &src_index));
for (Vertex::EdgeMap::const_iterator it = graph[i].out_edges.begin();
- it != graph[i].out_edges.end(); ++it) {
+ it != graph[i].out_edges.end();
+ ++it) {
vector<Vertex::Index>::size_type dst_index = 0;
EXPECT_TRUE(IndexOf(sorted, it->first, &dst_index));
EXPECT_LT(dst_index, src_index);