OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ |
7 | 7 |
8 #include <sys/types.h> | |
9 #include <sys/stat.h> | |
10 #include <set> | |
11 #include <string> | |
12 #include <vector> | |
13 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
14 #include "update_engine/file_writer.h" | |
15 #include "update_engine/update_metadata.pb.h" | |
16 | 9 |
17 namespace chromeos_update_engine { | 10 namespace chromeos_update_engine { |
18 | 11 |
19 class DeltaDiffGenerator { | 12 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. | |
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. | |
39 // Returns true on success. | |
40 // If non-empty, the device at force_compress_dev_path will be compressed. | |
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 | |
49 private: | 13 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. | |
58 static bool EncodeDev( | |
59 const struct stat& stbuf, std::vector<char>* out, | |
60 DeltaArchiveManifest_File_DataFormat* format, | |
61 bool force_compression); | |
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, | |
67 const bool avoid_diff, | |
68 DeltaArchiveManifest_File_DataFormat* out_data_format, | |
69 std::vector<char>* out, | |
70 bool* no_change); | |
71 | |
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. | |
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, | |
85 std::set<std::string> always_full_target_paths, | |
86 const std::string& force_compress_dev_path); | |
87 | |
88 // This should never be constructed | 14 // This should never be constructed |
89 DISALLOW_IMPLICIT_CONSTRUCTORS(DeltaDiffGenerator); | 15 DISALLOW_IMPLICIT_CONSTRUCTORS(DeltaDiffGenerator); |
90 }; | 16 }; |
91 | 17 |
92 }; // namespace chromeos_update_engine | 18 }; // namespace chromeos_update_engine |
93 | 19 |
94 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ | 20 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ |
OLD | NEW |