diff options
Diffstat (limited to 'applypatch')
-rw-r--r-- | applypatch/applypatch.cpp | 10 | ||||
-rw-r--r-- | applypatch/freecache.cpp | 8 | ||||
-rw-r--r-- | applypatch/imgpatch.cpp | 24 |
3 files changed, 32 insertions, 10 deletions
diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index db7530be9..39b8030d9 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -40,7 +40,7 @@ #include "edify/expr.h" #include "otafault/ota_io.h" -#include "otautil/cache_location.h" +#include "otautil/paths.h" #include "otautil/print_sha1.h" static int LoadPartitionContents(const std::string& filename, FileContents* file); @@ -403,7 +403,7 @@ int applypatch_check(const char* filename, const std::vector<std::string>& patch // If the source file is missing or corrupted, it might be because we were killed in the middle // of patching it. A copy of it should have been made in cache_temp_source. If that file // exists and matches the sha1 we're looking for, the check still passes. - if (LoadFileContents(CacheLocation::location().cache_temp_source().c_str(), &file) != 0) { + if (LoadFileContents(Paths::Get().cache_temp_source().c_str(), &file) != 0) { printf("failed to load cache file\n"); return 1; } @@ -525,7 +525,7 @@ int applypatch(const char* source_filename, const char* target_filename, printf("source file is bad; trying copy\n"); FileContents copy_file; - if (LoadFileContents(CacheLocation::location().cache_temp_source().c_str(), ©_file) < 0) { + if (LoadFileContents(Paths::Get().cache_temp_source().c_str(), ©_file) < 0) { printf("failed to read copy file\n"); return 1; } @@ -620,7 +620,7 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr printf("not enough free space on /cache\n"); return 1; } - if (SaveFileContents(CacheLocation::location().cache_temp_source().c_str(), &source_file) < 0) { + if (SaveFileContents(Paths::Get().cache_temp_source().c_str(), &source_file) < 0) { printf("failed to back up source file\n"); return 1; } @@ -685,7 +685,7 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr } // Delete the backup copy of the source. - unlink(CacheLocation::location().cache_temp_source().c_str()); + unlink(Paths::Get().cache_temp_source().c_str()); // Success! return 0; diff --git a/applypatch/freecache.cpp b/applypatch/freecache.cpp index cfab0f6db..dbd4b72b1 100644 --- a/applypatch/freecache.cpp +++ b/applypatch/freecache.cpp @@ -38,7 +38,7 @@ #include <android-base/strings.h> #include "applypatch/applypatch.h" -#include "otautil/cache_location.h" +#include "otautil/paths.h" static int EliminateOpenFiles(const std::string& dirname, std::set<std::string>* files) { std::unique_ptr<DIR, decltype(&closedir)> d(opendir("/proc"), closedir); @@ -95,7 +95,7 @@ static std::vector<std::string> FindExpendableFiles( // We can't delete cache_temp_source; if it's there we might have restarted during // installation and could be depending on it to be there. - if (path == CacheLocation::location().cache_temp_source()) { + if (path == Paths::Get().cache_temp_source()) { continue; } @@ -142,7 +142,7 @@ int MakeFreeSpaceOnCache(size_t bytes_needed) { return 0; #endif - std::vector<std::string> dirs = { "/cache", CacheLocation::location().cache_log_directory() }; + std::vector<std::string> dirs = { "/cache", Paths::Get().cache_log_directory() }; for (const auto& dirname : dirs) { if (RemoveFilesInDirectory(bytes_needed, dirname, FreeSpaceForFile)) { return 0; @@ -172,7 +172,7 @@ bool RemoveFilesInDirectory(size_t bytes_needed, const std::string& dirname, } std::vector<std::string> files; - if (dirname == CacheLocation::location().cache_log_directory()) { + if (dirname == Paths::Get().cache_log_directory()) { // Deletes the log files only. auto log_filter = [](const std::string& file_name) { return android::base::StartsWith(file_name, "last_log") || diff --git a/applypatch/imgpatch.cpp b/applypatch/imgpatch.cpp index 9794a4878..b06a64f21 100644 --- a/applypatch/imgpatch.cpp +++ b/applypatch/imgpatch.cpp @@ -38,6 +38,7 @@ #include <zlib.h> #include "edify/expr.h" +#include "otautil/print_sha1.h" static inline int64_t Read8(const void *address) { return android::base::get_unaligned<int64_t>(address); @@ -76,8 +77,10 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_ size_t actual_target_length = 0; size_t total_written = 0; static constexpr size_t buffer_size = 32768; + SHA_CTX sha_ctx; + SHA1_Init(&sha_ctx); auto compression_sink = [&strm, &actual_target_length, &expected_target_length, &total_written, - &ret, &sink](const uint8_t* data, size_t len) -> size_t { + &ret, &sink, &sha_ctx](const uint8_t* data, size_t len) -> size_t { // The input patch length for an update never exceeds INT_MAX. strm.avail_in = len; strm.next_in = data; @@ -98,6 +101,20 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_ size_t have = buffer_size - strm.avail_out; total_written += have; + + // TODO(b/67849209) Remove after debugging the unit test flakiness. + if (android::base::GetMinimumLogSeverity() <= android::base::LogSeverity::DEBUG && + have != 0) { + SHA1_Update(&sha_ctx, data, len - strm.avail_in); + SHA_CTX temp_ctx; + memcpy(&temp_ctx, &sha_ctx, sizeof(SHA_CTX)); + uint8_t digest_so_far[SHA_DIGEST_LENGTH]; + SHA1_Final(digest_so_far, &temp_ctx); + LOG(DEBUG) << "Processed " << actual_target_length + len - strm.avail_in + << " bytes input data in the sink function, sha1 so far: " + << short_sha1(digest_so_far); + } + if (sink(buffer.data(), have) != have) { LOG(ERROR) << "Failed to write " << have << " compressed bytes to output."; return 0; @@ -111,6 +128,11 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_ int bspatch_result = ApplyBSDiffPatch(src_data, src_len, patch, patch_offset, compression_sink); deflateEnd(&strm); + if (android::base::GetMinimumLogSeverity() <= android::base::LogSeverity::DEBUG) { + uint8_t digest[SHA_DIGEST_LENGTH]; + SHA1_Final(digest, &sha_ctx); + LOG(DEBUG) << "sha1 of " << actual_target_length << " bytes input data: " << short_sha1(digest); + } if (bspatch_result != 0) { return false; } |