blob: 0fcbad6ff0f2b1b72e171d5cd8d9847d2b2baa59 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2017 The Chromium Authors
Etienne Pierre-Doray455d1ae2017-08-24 01:17:542// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Samuel Huang577ef6c2018-03-13 18:19:345#ifndef COMPONENTS_ZUCCHINI_ZUCCHINI_INTEGRATION_H_
6#define COMPONENTS_ZUCCHINI_ZUCCHINI_INTEGRATION_H_
Etienne Pierre-Doray455d1ae2017-08-24 01:17:547
Samuel Huang9f0f3252018-06-21 15:50:228#include <string>
9
Calder Kitagawaab7fbfb2018-02-09 18:06:0210#include "base/files/file.h"
Etienne Pierre-Doray455d1ae2017-08-24 01:17:5411#include "base/files/file_path.h"
Samuel Huang577ef6c2018-03-13 18:19:3412#include "components/zucchini/zucchini.h"
Etienne Pierre-Doray455d1ae2017-08-24 01:17:5413
Samuel Huang9f0f3252018-06-21 15:50:2214// Zucchini integration interface to wrap core Zucchini library with file I/O.
15
Etienne Pierre-Doray455d1ae2017-08-24 01:17:5416namespace zucchini {
17
Samuel Huang9f0f3252018-06-21 15:50:2218// Generates a patch to transform |old_file| to |new_file|, and writes the
19// result to |patch_file|. Since this uses memory mapped files, crashes are
20// expected in case of I/O errors. On Windows, |patch_file| is kept iff returned
Samuel Huang21879c32018-03-21 18:54:0321// code is kStatusSuccess or if |force_keep == true|, and is deleted otherwise.
22// For UNIX systems the caller needs to do cleanup since it has ownership of the
Samuel Huang9f0f3252018-06-21 15:50:2223// base::File params, and Zucchini has no knowledge of which base::FilePath to
24// delete. If |is_raw == true| then uses Raw Zucchini. If |imposed_matches| is
25// non-empty, then overrides default element detection and matching heuristics
26// with custom element matching encoded in |imposed_matches|, which should be
27// formatted as:
28// "#+#=#+#,#+#=#+#,..." (e.g., "1+2=3+4", "1+2=3+4,5+6=7+8"),
29// where "#+#=#+#" encodes a match as 4 unsigned integers:
30// [offset in "old", size in "old", offset in "new", size in "new"].
31status::Code Generate(base::File old_file,
32 base::File new_file,
33 base::File patch_file,
34 bool force_keep = false,
35 bool is_raw = false,
36 std::string imposed_matches = "");
37
38// Alternative Generate() interface that takes base::FilePath as arguments.
39// Performs proper cleanup in Windows and UNIX if failure occurs.
40status::Code Generate(const base::FilePath& old_path,
41 const base::FilePath& new_path,
42 const base::FilePath& patch_path,
43 bool force_keep = false,
44 bool is_raw = false,
45 std::string imposed_matches = "");
46
47// Applies the patch in |patch_file| to |old_file|, and writes the result to
48// |new_file|. Since this uses memory mapped files, crashes are expected in case
49// of I/O errors. On Windows, |new_file| is kept iff returned code is
50// kStatusSuccess or if |force_keep == true|, and is deleted otherwise. For UNIX
51// systems the caller needs to do cleanup since it has ownership of the
52// base::File params, and Zucchini has no knowledge of which base::FilePath to
Samuel Huang21879c32018-03-21 18:54:0353// delete.
Samuel Huang9f0f3252018-06-21 15:50:2254status::Code Apply(base::File old_file,
55 base::File patch_file,
56 base::File new_file,
Samuel Huang21879c32018-03-21 18:54:0357 bool force_keep = false);
Calder Kitagawaab7fbfb2018-02-09 18:06:0258
Samuel Huang9f0f3252018-06-21 15:50:2259// Alternative Apply() interface that takes base::FilePath as arguments.
60// Performs proper cleanup in Windows and UNIX if failure occurs.
Etienne Pierre-Doray455d1ae2017-08-24 01:17:5461status::Code Apply(const base::FilePath& old_path,
62 const base::FilePath& patch_path,
Samuel Huang21879c32018-03-21 18:54:0363 const base::FilePath& new_path,
64 bool force_keep = false);
Etienne Pierre-Doray455d1ae2017-08-24 01:17:5465
Etienne Pierre-doray559d77a2021-10-28 21:16:0466// Verifies the patch format in |patch_file| and returns
67// Code::kStatusPatchReadError if the patch is malformed or version is
68// unsupported. Since this uses memory mapped files, crashes are expected in
69// case of I/O errors.
70status::Code VerifyPatch(base::File patch_file);
71
72// Alternative VerifyPatch() interface that takes base::FilePath as arguments.
73// Performs proper cleanup in Windows and UNIX if failure occurs.
74status::Code VerifyPatch(const base::FilePath& patch_path);
75
Etienne Pierre-Doray455d1ae2017-08-24 01:17:5476} // namespace zucchini
77
Samuel Huang577ef6c2018-03-13 18:19:3478#endif // COMPONENTS_ZUCCHINI_ZUCCHINI_INTEGRATION_H_