adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame^] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ |
| 7 | |
| 8 | #include <sys/types.h> |
| 9 | #include <sys/stat.h> |
| 10 | #include <string> |
| 11 | #include <vector> |
| 12 | #include "base/basictypes.h" |
| 13 | #include "update_engine/file_writer.h" |
| 14 | #include "update_engine/update_metadata.pb.h" |
| 15 | |
| 16 | namespace chromeos_update_engine { |
| 17 | |
| 18 | class DeltaDiffGenerator { |
| 19 | public: |
| 20 | // Encodes the metadata at new_path recursively into a DeltaArchiveManifest |
| 21 | // protobuf object. This will only read the filesystem. Children will |
| 22 | // be recorded recursively iff they are on the same device as their |
| 23 | // parent. |
| 24 | // This will set all fields in the DeltaArchiveManifest except for |
| 25 | // DeltaArchiveManifest_File_data_* as those are set only when writing |
| 26 | // the actual delta file to disk. |
| 27 | // Caller is responsible for freeing the returned value. |
| 28 | // Returns NULL on failure. |
| 29 | static DeltaArchiveManifest* EncodeMetadataToProtoBuffer( |
| 30 | const char* new_path); |
| 31 | |
| 32 | // Takes a DeltaArchiveManifest as given from EncodeMetadataToProtoBuffer(), |
| 33 | // fill in the missing fields (DeltaArchiveManifest_File_data_*), and |
| 34 | // write the full delta out to the output file. |
| 35 | // Returns true on success. |
| 36 | static bool EncodeDataToDeltaFile(DeltaArchiveManifest* archive, |
| 37 | const std::string& old_path, |
| 38 | const std::string& new_path, |
| 39 | const std::string& out_file); |
| 40 | private: |
| 41 | // These functions encode all the data about a file that's not already |
| 42 | // stored in the DeltaArchiveManifest message into the vector 'out'. |
| 43 | // They all return true on success. |
| 44 | |
| 45 | // EncodeLink stores the path the symlink points to. |
| 46 | static bool EncodeLink(const std::string& path, std::vector<char>* out); |
| 47 | // EncodeDev stores the major and minor device numbers. |
| 48 | // Specifically it writes a LinuxDevice message. |
| 49 | static bool EncodeDev(const struct stat& stbuf, std::vector<char>* out); |
| 50 | // EncodeFile stores the full data, gzipped data, or a binary diff from |
| 51 | // the old data. out_data_format will be set to the method used. |
| 52 | static bool EncodeFile(const std::string& old_dir, |
| 53 | const std::string& new_dir, |
| 54 | const std::string& file_name, |
| 55 | DeltaArchiveManifest_File_DataFormat* out_data_format, |
| 56 | std::vector<char>* out); |
| 57 | |
| 58 | static bool WriteFileDiffsToDeltaFile(DeltaArchiveManifest* archive, |
| 59 | DeltaArchiveManifest_File* file, |
| 60 | const std::string& file_name, |
| 61 | const std::string& old_path, |
| 62 | const std::string& new_path, |
| 63 | FileWriter* out_file_writer, |
| 64 | int* out_file_length); |
| 65 | |
| 66 | // This should never be constructed |
| 67 | DISALLOW_IMPLICIT_CONSTRUCTORS(DeltaDiffGenerator); |
| 68 | }; |
| 69 | |
| 70 | }; // namespace chromeos_update_engine |
| 71 | |
| 72 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ |