OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ |
| 7 |
| 8 #include <inttypes.h> |
| 9 #include <vector> |
| 10 #include <google/protobuf/repeated_field.h> |
| 11 #include "update_engine/file_writer.h" |
| 12 #include "update_engine/update_metadata.pb.h" |
| 13 |
| 14 namespace chromeos_update_engine { |
| 15 |
| 16 // This class performs the actions in a delta update synchronously. The delta |
| 17 // update itself should be passed in in chunks as it is received. |
| 18 |
| 19 class DeltaPerformer : public FileWriter { |
| 20 public: |
| 21 DeltaPerformer() |
| 22 : fd_(-1), |
| 23 manifest_valid_(false), |
| 24 next_operation_(0), |
| 25 buffer_offset_(0), |
| 26 block_size_(0) {} |
| 27 // flags and mode ignored. Once Close()d, a DeltaPerformer can't be |
| 28 // Open()ed again. |
| 29 int Open(const char* path, int flags, mode_t mode); |
| 30 |
| 31 // Wrapper around write. Returns bytes written on success or |
| 32 // -errno on error. |
| 33 int Write(const void* bytes, size_t count); |
| 34 |
| 35 // Wrapper around close. Returns 0 on success or -errno on error. |
| 36 int Close(); |
| 37 |
| 38 // Converts an ordered collection of Extent objects which contain data of |
| 39 // length full_length to a comma-separated string. For each Extent, the |
| 40 // string will have the start offset and then the length in bytes. |
| 41 // The length value of the last extent in the string may be short, since |
| 42 // the full length of all extents in the string is capped to full_length. |
| 43 // Also, an extent starting at kSparseHole, appears as -1 in the string. |
| 44 // For example, if the Extents are {1, 1}, {4, 2}, {kSparseHole, 1}, |
| 45 // {0, 1}, block_size is 4096, and full_length is 5 * block_size - 13, |
| 46 // the resulting string will be: "4096:4096,16384:8192,-1:4096,0:4083" |
| 47 static bool ExtentsToBsdiffPositionsString( |
| 48 const google::protobuf::RepeatedPtrField<Extent>& extents, |
| 49 uint64_t block_size, |
| 50 uint64_t full_length, |
| 51 std::string* positions_string); |
| 52 |
| 53 private: |
| 54 // Returns true if enough of the delta file has been passed via Write() |
| 55 // to be able to perform a given install operation. |
| 56 bool CanPerformInstallOperation( |
| 57 const DeltaArchiveManifest_InstallOperation& operation); |
| 58 |
| 59 // Returns true on success. |
| 60 bool PerformInstallOperation( |
| 61 const DeltaArchiveManifest_InstallOperation& operation); |
| 62 |
| 63 // These perform a specific type of operation and return true on success. |
| 64 bool PerformReplaceOperation( |
| 65 const DeltaArchiveManifest_InstallOperation& operation); |
| 66 bool PerformMoveOperation( |
| 67 const DeltaArchiveManifest_InstallOperation& operation); |
| 68 bool PerformBsdiffOperation( |
| 69 const DeltaArchiveManifest_InstallOperation& operation); |
| 70 |
| 71 // File descriptor of open device. |
| 72 int fd_; |
| 73 |
| 74 std::string path_; // Path that fd_ refers to |
| 75 |
| 76 DeltaArchiveManifest manifest_; |
| 77 bool manifest_valid_; |
| 78 |
| 79 // Index of the next operation to perform in the manifest. |
| 80 int next_operation_; |
| 81 |
| 82 // buffer_ is a window of the data that's been downloaded. At first, |
| 83 // it contains the beginning of the download, but after the protobuf |
| 84 // has been downloaded and parsed, it contains a sliding window of |
| 85 // data blobs. |
| 86 std::vector<char> buffer_; |
| 87 // Offset of buffer_ in the binary blobs section of the update. |
| 88 uint64_t buffer_offset_; |
| 89 |
| 90 // The block size (parsed from the manifest). |
| 91 uint32_t block_size_; |
| 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(DeltaPerformer); |
| 94 }; |
| 95 |
| 96 } // namespace chromeos_update_engine |
| 97 |
| 98 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ |
OLD | NEW |