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 --- updater/blockimg.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'updater/blockimg.cpp') diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp index 6a6236b1b..2a2ab19a3 100644 --- a/updater/blockimg.cpp +++ b/updater/blockimg.cpp @@ -827,7 +827,7 @@ static int WriteStash(const std::string& base, const std::string& id, int blocks return -1; } - if (checkspace && CacheSizeCheck(blocks * BLOCKSIZE) != 0) { + if (checkspace && !CheckAndFreeSpaceOnCache(blocks * BLOCKSIZE)) { LOG(ERROR) << "not enough space to write stash"; return -1; } @@ -919,7 +919,7 @@ static int CreateStash(State* state, size_t maxblocks, const std::string& base) return -1; } - if (CacheSizeCheck(max_stash_size) != 0) { + if (!CheckAndFreeSpaceOnCache(max_stash_size)) { ErrorAbort(state, kStashCreationFailure, "not enough space for stash (%zu needed)", max_stash_size); return -1; @@ -951,7 +951,7 @@ static int CreateStash(State* state, size_t maxblocks, const std::string& base) if (max_stash_size > existing) { size_t needed = max_stash_size - existing; - if (CacheSizeCheck(needed) != 0) { + if (!CheckAndFreeSpaceOnCache(needed)) { ErrorAbort(state, kStashCreationFailure, "not enough space for stash (%zu more needed)", needed); return -1; -- cgit v1.2.3