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. |
Andrew de los Reyes | e573399 | 2009-12-08 13:34:00 -0800 | [diff] [blame] | 36 | // If non-empty, the device at force_compress_dev_path will be compressed. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 37 | static bool EncodeDataToDeltaFile(DeltaArchiveManifest* archive, |
| 38 | const std::string& old_path, |
| 39 | const std::string& new_path, |
Andrew de los Reyes | e573399 | 2009-12-08 13:34:00 -0800 | [diff] [blame] | 40 | const std::string& out_file, |
| 41 | const std::string& force_compress_dev_path); |
| 42 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 43 | private: |
| 44 | // These functions encode all the data about a file that's not already |
| 45 | // stored in the DeltaArchiveManifest message into the vector 'out'. |
| 46 | // They all return true on success. |
| 47 | |
| 48 | // EncodeLink stores the path the symlink points to. |
| 49 | static bool EncodeLink(const std::string& path, std::vector<char>* out); |
| 50 | // EncodeDev stores the major and minor device numbers. |
| 51 | // Specifically it writes a LinuxDevice message. |
Andrew de los Reyes | e573399 | 2009-12-08 13:34:00 -0800 | [diff] [blame] | 52 | static bool EncodeDev( |
| 53 | const struct stat& stbuf, std::vector<char>* out, |
| 54 | DeltaArchiveManifest_File_DataFormat* format, |
| 55 | bool force_compression); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 56 | // EncodeFile stores the full data, gzipped data, or a binary diff from |
| 57 | // the old data. out_data_format will be set to the method used. |
| 58 | static bool EncodeFile(const std::string& old_dir, |
| 59 | const std::string& new_dir, |
| 60 | const std::string& file_name, |
| 61 | DeltaArchiveManifest_File_DataFormat* out_data_format, |
| 62 | std::vector<char>* out); |
| 63 | |
Andrew de los Reyes | e573399 | 2009-12-08 13:34:00 -0800 | [diff] [blame] | 64 | // If non-empty, the device at force_compress_dev_path will be compressed. |
| 65 | static bool WriteFileDiffsToDeltaFile( |
| 66 | DeltaArchiveManifest* archive, |
| 67 | DeltaArchiveManifest_File* file, |
| 68 | const std::string& file_name, |
| 69 | const std::string& old_path, |
| 70 | const std::string& new_path, |
| 71 | FileWriter* out_file_writer, |
| 72 | int* out_file_length, |
| 73 | const std::string& force_compress_dev_path); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 74 | |
| 75 | // This should never be constructed |
| 76 | DISALLOW_IMPLICIT_CONSTRUCTORS(DeltaDiffGenerator); |
| 77 | }; |
| 78 | |
| 79 | }; // namespace chromeos_update_engine |
| 80 | |
| 81 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ |