diff options
Diffstat (limited to 'zucchini_integration.cc')
-rw-r--r-- | zucchini_integration.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/zucchini_integration.cc b/zucchini_integration.cc index ff7e792..bf28b3c 100644 --- a/zucchini_integration.cc +++ b/zucchini_integration.cc @@ -146,6 +146,22 @@ status::Code ApplyCommon(base::File old_file, return status::kStatusSuccess; } +status::Code VerifyPatchCommon(base::File patch_file, + base::FilePath patch_name) { + MappedFileReader mapped_patch(std::move(patch_file)); + if (mapped_patch.HasError()) { + LOG(ERROR) << "Error with file " << patch_name.value() << ": " + << mapped_patch.error(); + return status::kStatusFileReadError; + } + auto patch_reader = EnsemblePatchReader::Create(mapped_patch.region()); + if (!patch_reader.has_value()) { + LOG(ERROR) << "Error reading patch header."; + return status::kStatusPatchReadError; + } + return status::kStatusSuccess; +} + } // namespace status::Code Generate(base::File old_file, @@ -206,4 +222,15 @@ status::Code Apply(const base::FilePath& old_path, std::move(new_file), file_names, force_keep); } +status::Code VerifyPatch(base::File patch_file) { + return VerifyPatchCommon(std::move(patch_file), base::FilePath()); +} + +status::Code VerifyPatch(const base::FilePath& patch_path) { + using base::File; + File patch_file(patch_path, File::FLAG_OPEN | File::FLAG_READ | + base::File::FLAG_SHARE_DELETE); + return VerifyPatchCommon(std::move(patch_file), patch_path); +} + } // namespace zucchini |