blob: 5d422c34f424523d0e712624f2c86963303ef22a [file] [log] [blame]
adlr@google.com3defe6a2009-12-04 20:57:17 +00001// 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 Reyes4fe15d02009-12-10 19:01:36 -080010#include <set>
adlr@google.com3defe6a2009-12-04 20:57:17 +000011#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
17namespace chromeos_update_engine {
18
19class 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 Reyes4fe15d02009-12-10 19:01:36 -080036 // 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.com3defe6a2009-12-04 20:57:17 +000039 // Returns true on success.
Andrew de los Reyese5733992009-12-08 13:34:00 -080040 // If non-empty, the device at force_compress_dev_path will be compressed.
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080041 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.com3defe6a2009-12-04 20:57:17 +000049 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 Reyese5733992009-12-08 13:34:00 -080058 static bool EncodeDev(
59 const struct stat& stbuf, std::vector<char>* out,
60 DeltaArchiveManifest_File_DataFormat* format,
61 bool force_compression);
adlr@google.com3defe6a2009-12-04 20:57:17 +000062 // 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 Reyes4fe15d02009-12-10 19:01:36 -080067 const bool avoid_diff,
adlr@google.com3defe6a2009-12-04 20:57:17 +000068 DeltaArchiveManifest_File_DataFormat* out_data_format,
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080069 std::vector<char>* out,
70 bool* no_change);
adlr@google.com3defe6a2009-12-04 20:57:17 +000071
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080072 // 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 Reyese5733992009-12-08 13:34:00 -080076 // 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 Reyes4fe15d02009-12-10 19:01:36 -080085 std::set<std::string> always_full_target_paths,
Andrew de los Reyese5733992009-12-08 13:34:00 -080086 const std::string& force_compress_dev_path);
adlr@google.com3defe6a2009-12-04 20:57:17 +000087
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__