From 5ee25666cc819e9ebc9b72c7a44c4bc9bab9e4e3 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 11 Jul 2018 15:55:32 -0700 Subject: applypatch: Consolidate CacheSizeCheck() and MakeFreeSpaceOnCache(). They are doing exactly the same thing, except for the slightly different error return value (1 vs -1). int CacheSizeCheck(size_t bytes); int MakeFreeSpaceOnCache(size_t bytes_needed); This CL consolidates the two functions and uses bool as its return type. // Checks whether /cache partition has at least 'bytes'-byte free space. Returns true immediately // if so. Otherwise, it will try to free some space by removing older logs, checks again and // returns the checking result. bool CheckAndFreeSpaceOnCache(size_t bytes); Test: Run recovery_unit_test and recovery_component_test on marlin. Change-Id: I94a96934d2b18713f8f39ad5aa96a02c98d87963 --- applypatch/applypatch.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'applypatch/applypatch.cpp') diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 13e4b1ae0..12e139930 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -420,14 +420,6 @@ static size_t FileSink(const unsigned char* data, size_t len, int fd) { return done; } -int CacheSizeCheck(size_t bytes) { - if (MakeFreeSpaceOnCache(bytes) < 0) { - LOG(ERROR) << "Failed to make " << bytes << " bytes available on /cache"; - return 1; - } - return 0; -} - int applypatch(const char* source_filename, const char* target_filename, const char* target_sha1_str, size_t /* target_size */, const std::vector& patch_sha1s, @@ -562,8 +554,8 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr CHECK(android::base::StartsWith(target_filename, "EMMC:")); - // We still write the original source to cache, in case the partition write is interrupted. - if (MakeFreeSpaceOnCache(source_file.data.size()) < 0) { + // We write the original source to cache, in case the partition write is interrupted. + if (!CheckAndFreeSpaceOnCache(source_file.data.size())) { LOG(ERROR) << "Not enough free space on /cache"; return 1; } -- cgit v1.2.3