Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "update_engine/delta_performer.h" | 5 #include "update_engine/delta_performer.h" |
| 6 | 6 |
| 7 #include <endian.h> | 7 #include <endian.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 if (close(fd_) == -1) { | 158 if (close(fd_) == -1) { |
| 159 err = errno; | 159 err = errno; |
| 160 PLOG(ERROR) << "Unable to close rootfs fd:"; | 160 PLOG(ERROR) << "Unable to close rootfs fd:"; |
| 161 } | 161 } |
| 162 LOG_IF(ERROR, !hash_calculator_.Finalize()) << "Unable to finalize the hash."; | 162 LOG_IF(ERROR, !hash_calculator_.Finalize()) << "Unable to finalize the hash."; |
| 163 fd_ = -2; // Set so that isn't not valid AND calls to Open() will fail. | 163 fd_ = -2; // Set so that isn't not valid AND calls to Open() will fail. |
| 164 path_ = ""; | 164 path_ = ""; |
| 165 return -err; | 165 return -err; |
| 166 } | 166 } |
| 167 | 167 |
| 168 namespace { | |
| 169 void LogPartitionInfoHash(const PartitionInfo& info, const string& tag) { | |
| 170 string sha256; | |
| 171 if (OmahaHashCalculator::Base64Encode(info.hash().data(), | |
| 172 info.hash().size(), | |
| 173 &sha256)) { | |
| 174 LOG(INFO) << "PartitionInfo " << tag << " sha256:" << sha256 | |
| 175 << " length:" << tag.size(); | |
| 176 } else { | |
| 177 LOG(ERROR) << "Base64Encode failed for tag: " << tag; | |
| 178 } | |
| 179 } | |
| 180 void LogPartitionInfo(const DeltaArchiveManifest& manifest) { | |
|
petkov
2010/10/22 20:15:16
add blank line before
adlr
2010/10/22 20:40:18
Done.
| |
| 181 if (manifest.has_old_kernel_info()) | |
| 182 LogPartitionInfoHash(manifest.old_kernel_info(), "old_kernel_info"); | |
| 183 if (manifest.has_old_rootfs_info()) | |
| 184 LogPartitionInfoHash(manifest.old_rootfs_info(), "old_rootfs_info"); | |
| 185 if (manifest.has_new_kernel_info()) | |
| 186 LogPartitionInfoHash(manifest.new_kernel_info(), "new_kernel_info"); | |
| 187 if (manifest.has_new_rootfs_info()) | |
| 188 LogPartitionInfoHash(manifest.new_rootfs_info(), "new_rootfs_info"); | |
| 189 } | |
| 190 } // namespace {} | |
| 191 | |
| 168 // Wrapper around write. Returns bytes written on success or | 192 // Wrapper around write. Returns bytes written on success or |
| 169 // -errno on error. | 193 // -errno on error. |
| 170 // This function performs as many actions as it can, given the amount of | 194 // This function performs as many actions as it can, given the amount of |
| 171 // data received thus far. | 195 // data received thus far. |
| 172 ssize_t DeltaPerformer::Write(const void* bytes, size_t count) { | 196 ssize_t DeltaPerformer::Write(const void* bytes, size_t count) { |
| 173 const char* c_bytes = reinterpret_cast<const char*>(bytes); | 197 const char* c_bytes = reinterpret_cast<const char*>(bytes); |
| 174 buffer_.insert(buffer_.end(), c_bytes, c_bytes + count); | 198 buffer_.insert(buffer_.end(), c_bytes, c_bytes + count); |
| 175 | 199 |
| 176 if (!manifest_valid_) { | 200 if (!manifest_valid_) { |
| 177 // See if we have enough bytes for the manifest yet | 201 // See if we have enough bytes for the manifest yet |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 200 } | 224 } |
| 201 // Remove protobuf and header info from buffer_, so buffer_ contains | 225 // Remove protobuf and header info from buffer_, so buffer_ contains |
| 202 // just data blobs | 226 // just data blobs |
| 203 manifest_metadata_size_ = strlen(kDeltaMagic) + kDeltaVersionLength + | 227 manifest_metadata_size_ = strlen(kDeltaMagic) + kDeltaVersionLength + |
| 204 kDeltaProtobufLengthLength + protobuf_length; | 228 kDeltaProtobufLengthLength + protobuf_length; |
| 205 DiscardBufferHeadBytes(manifest_metadata_size_); | 229 DiscardBufferHeadBytes(manifest_metadata_size_); |
| 206 LOG_IF(WARNING, !prefs_->SetInt64(kPrefsManifestMetadataSize, | 230 LOG_IF(WARNING, !prefs_->SetInt64(kPrefsManifestMetadataSize, |
| 207 manifest_metadata_size_)) | 231 manifest_metadata_size_)) |
| 208 << "Unable to save the manifest metadata size."; | 232 << "Unable to save the manifest metadata size."; |
| 209 manifest_valid_ = true; | 233 manifest_valid_ = true; |
| 234 LogPartitionInfo(manifest_); | |
| 210 if (!PrimeUpdateState()) { | 235 if (!PrimeUpdateState()) { |
| 211 LOG(ERROR) << "Unable to prime the update state."; | 236 LOG(ERROR) << "Unable to prime the update state."; |
| 212 return -EINVAL; | 237 return -EINVAL; |
| 213 } | 238 } |
| 214 } | 239 } |
| 215 ssize_t total_operations = manifest_.install_operations_size() + | 240 ssize_t total_operations = manifest_.install_operations_size() + |
| 216 manifest_.kernel_install_operations_size(); | 241 manifest_.kernel_install_operations_size(); |
| 217 while (next_operation_num_ < total_operations) { | 242 while (next_operation_num_ < total_operations) { |
| 218 const DeltaArchiveManifest_InstallOperation &op = | 243 const DeltaArchiveManifest_InstallOperation &op = |
| 219 next_operation_num_ < manifest_.install_operations_size() ? | 244 next_operation_num_ < manifest_.install_operations_size() ? |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 716 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { | 741 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { |
| 717 resumed_update_failures++; | 742 resumed_update_failures++; |
| 718 } else { | 743 } else { |
| 719 resumed_update_failures = 1; | 744 resumed_update_failures = 1; |
| 720 } | 745 } |
| 721 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); | 746 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); |
| 722 return true; | 747 return true; |
| 723 } | 748 } |
| 724 | 749 |
| 725 } // namespace chromeos_update_engine | 750 } // namespace chromeos_update_engine |
| OLD | NEW |