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> |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame^] | 10 | #include <set> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 11 | #include <string> |
| 12 | #include <vector> |
| 13 | #include "base/basictypes.h" |
| 14 | #include "update_engine/file_writer.h" |
| 15 | #include "update_engine/update_metadata.pb.h" |
| 16 | |
| 17 | namespace chromeos_update_engine { |
| 18 | |
| 19 | class DeltaDiffGenerator { |
| 20 | public: |
| 21 | // Encodes the metadata at new_path recursively into a DeltaArchiveManifest |
| 22 | // protobuf object. This will only read the filesystem. Children will |
| 23 | // be recorded recursively iff they are on the same device as their |
| 24 | // parent. |
| 25 | // This will set all fields in the DeltaArchiveManifest except for |
| 26 | // DeltaArchiveManifest_File_data_* as those are set only when writing |
| 27 | // the actual delta file to disk. |
| 28 | // Caller is responsible for freeing the returned value. |
| 29 | // Returns NULL on failure. |
| 30 | static DeltaArchiveManifest* EncodeMetadataToProtoBuffer( |
| 31 | const char* new_path); |
| 32 | |
| 33 | // Takes a DeltaArchiveManifest as given from EncodeMetadataToProtoBuffer(), |
| 34 | // fill in the missing fields (DeltaArchiveManifest_File_data_*), and |
| 35 | // write the full delta out to the output file. |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame^] | 36 | // Any paths in nondiff_paths will be included in full, rather than |
| 37 | // as a diff. This is useful for files that change during postinstall, since |
| 38 | // future updates can't depend on them having remaining unchanged. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 39 | // Returns true on success. |
Andrew de los Reyes | e573399 | 2009-12-08 13:34:00 -0800 | [diff] [blame] | 40 | // If non-empty, the device at force_compress_dev_path will be compressed. |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame^] | 41 | static bool EncodeDataToDeltaFile( |
| 42 | DeltaArchiveManifest* archive, |
| 43 | const std::string& old_path, |
| 44 | const std::string& new_path, |
| 45 | const std::string& out_file, |
| 46 | const std::set<std::string>& nondiff_paths, |
| 47 | const std::string& force_compress_dev_path); |
| 48 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 49 | private: |
| 50 | // These functions encode all the data about a file that's not already |
| 51 | // stored in the DeltaArchiveManifest message into the vector 'out'. |
| 52 | // They all return true on success. |
| 53 | |
| 54 | // EncodeLink stores the path the symlink points to. |
| 55 | static bool EncodeLink(const std::string& path, std::vector<char>* out); |
| 56 | // EncodeDev stores the major and minor device numbers. |
| 57 | // Specifically it writes a LinuxDevice message. |
Andrew de los Reyes | e573399 | 2009-12-08 13:34:00 -0800 | [diff] [blame] | 58 | static bool EncodeDev( |
| 59 | const struct stat& stbuf, std::vector<char>* out, |
| 60 | DeltaArchiveManifest_File_DataFormat* format, |
| 61 | bool force_compression); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 62 | // EncodeFile stores the full data, gzipped data, or a binary diff from |
| 63 | // the old data. out_data_format will be set to the method used. |
| 64 | static bool EncodeFile(const std::string& old_dir, |
| 65 | const std::string& new_dir, |
| 66 | const std::string& file_name, |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame^] | 67 | const bool avoid_diff, |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 68 | DeltaArchiveManifest_File_DataFormat* out_data_format, |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame^] | 69 | std::vector<char>* out, |
| 70 | bool* no_change); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 71 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame^] | 72 | // nondiff_paths is passed in to EncodeDataToDeltaFile() with |
| 73 | // paths relative to the installed system (e.g. /etc/fstab), but |
| 74 | // WriteFileDiffsToDeltaFile requires always_full_target_paths to be |
| 75 | // the entire path of the new file. |
Andrew de los Reyes | e573399 | 2009-12-08 13:34:00 -0800 | [diff] [blame] | 76 | // If non-empty, the device at force_compress_dev_path will be compressed. |
| 77 | static bool WriteFileDiffsToDeltaFile( |
| 78 | DeltaArchiveManifest* archive, |
| 79 | DeltaArchiveManifest_File* file, |
| 80 | const std::string& file_name, |
| 81 | const std::string& old_path, |
| 82 | const std::string& new_path, |
| 83 | FileWriter* out_file_writer, |
| 84 | int* out_file_length, |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame^] | 85 | std::set<std::string> always_full_target_paths, |
Andrew de los Reyes | e573399 | 2009-12-08 13:34:00 -0800 | [diff] [blame] | 86 | const std::string& force_compress_dev_path); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 87 | |
| 88 | // This should never be constructed |
| 89 | DISALLOW_IMPLICIT_CONSTRUCTORS(DeltaDiffGenerator); |
| 90 | }; |
| 91 | |
| 92 | }; // namespace chromeos_update_engine |
| 93 | |
| 94 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ |