MCPcopy Create free account
hub / github.com/comaps/comaps / ApplyDiffVersion0

Function ApplyDiffVersion0

libs/mwm_diff/diff.cpp:57–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57generator::mwm_diff::DiffApplicationResult ApplyDiffVersion0(FileReader & oldReader, FileWriter & newWriter,
58 ReaderSource<FileReader> & diffFileSource,
59 base::Cancellable const & cancellable)
60{
61 using generator::mwm_diff::DiffApplicationResult;
62
63 std::vector<uint8_t> deflatedDiff(base::checked_cast<size_t>(diffFileSource.Size()));
64 diffFileSource.Read(deflatedDiff.data(), deflatedDiff.size());
65
66 using Inflate = coding::ZLib::Inflate;
67 Inflate inflate(Inflate::Format::ZLib);
68 std::vector<uint8_t> diffBuf;
69 inflate(deflatedDiff.data(), deflatedDiff.size(), back_inserter(diffBuf));
70
71 // Our bsdiff assumes that both the old mwm and the diff files are correct and
72 // does no checks when using its readers.
73 // Yet sometimes we observe corrupted files in the logs, and to avoid
74 // crashes from such files the exception-throwing version of MemReader is used here.
75 // |oldReader| is a FileReader so it throws exceptions too but we
76 // are more confident in the uncorrupted status of the old file because
77 // its checksum is compared to the one stored in the diff file.
78 MemReaderWithExceptions diffMemReader(diffBuf.data(), diffBuf.size());
79
80 auto const status = bsdiff::ApplyBinaryPatch(oldReader, newWriter, diffMemReader, cancellable);
81
82 if (status == bsdiff::BSDiffStatus::CANCELLED)
83 {
84 LOG(LDEBUG, ("Diff application has been cancelled"));
85 return DiffApplicationResult::Cancelled;
86 }
87
88 if (status == bsdiff::BSDiffStatus::OK)
89 return DiffApplicationResult::Ok;
90
91 LOG(LERROR, ("Could not apply patch with bsdiff:", status));
92 return DiffApplicationResult::Failed;
93}
94} // namespace
95
96namespace generator

Callers 1

ApplyDiffFunction · 0.85

Calls 5

ApplyBinaryPatchFunction · 0.85
SizeMethod · 0.45
ReadMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected