Files
oxmc 4744864afa recovery_toolkit/twrpinstall: add wipe_cache.cpp -- WipeCache copied directly, libinstall collides with our own install.cpp
libinstall (the real stock module WipeCache lives in) also bundles its
own install.cpp, which duplicates twrpinstall's intentionally-customized
copy -- same class of problem as libotautil/verifier.cpp earlier.
WipeData() (same upstream file) intentionally not copied: nothing calls
it, and it needs install/snapshot_utils.h (Virtual A/B), out of scope for
PawletOS's non-VAB targets. ui parameter null-guarded throughout: the
real call site (install.cpp's WipeCache(nullptr, nullptr)) predates this
function gaining a RecoveryUI* parameter and only ever intended skipping
the confirm callback, not the UI.
2026-09-30 18:13:03 -07:00

94 lines
3.3 KiB
C++

/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// WipeCache + its EraseVolume() helper, copied from
// system/extras (bootable/recovery/install/wipe_data.cpp). install.cpp
// (twrpinstall) is the only caller in this port. WipeData() from the same
// upstream file intentionally NOT copied -- nothing here calls it, and it
// pulls in install/snapshot_utils.h (Virtual A/B merge handling), which
// doesn't apply to PawletOS's rpi4/rpi5 targets (no dynamic partitions,
// see notes/ota-non-a-ab-research-work.md). libinstall itself (the real
// stock module both functions live in) can't be whole_static_libs'd here:
// it also bundles its own install.cpp, which collides with twrpinstall's
// own (intentionally customized) install.cpp -- same class of problem as
// the earlier libotautil/verifier.cpp collision. See notes/recovery-work.md.
#include <string.h>
#include <functional>
#include <string_view>
#include <vector>
#include <android-base/logging.h>
#include "recovery_ui/ui.h"
#include "recovery_utils/logging.h"
#include "recovery_utils/roots.h"
constexpr const char* CACHE_ROOT = "/cache";
static bool EraseVolume(const char* volume, RecoveryUI* ui, std::string_view new_fstype) {
LOG(INFO) << "Erasing volume " << volume << " with new filesystem type " << new_fstype;
bool is_cache = (strcmp(volume, CACHE_ROOT) == 0);
std::vector<saved_log_file> log_files;
if (is_cache) {
log_files = ReadLogFilesToMemory();
}
if (ui) ui->Print("Formatting %s...\n", volume);
ensure_path_unmounted(volume);
int result = format_volume(volume, "", new_fstype);
if (is_cache) {
RestoreLogFilesAfterFormat(log_files);
}
return (result == 0);
}
// ui is null-guarded throughout: install.cpp's real call site
// (WipeCache(nullptr, nullptr)) predates this function gaining a
// RecoveryUI* parameter -- the original call only ever intended "no
// confirm callback", not "no UI". TWRP's GUI reports progress through its
// own DataManager/gui_print() mechanism independently, so skipping these
// particular Print() calls when there's no UI handed in is safe, not a
// silent behavior loss.
bool WipeCache(RecoveryUI* ui, const std::function<bool()>& confirm_func,
std::string_view new_fstype) {
bool has_cache = volume_for_mount_point("/cache") != nullptr;
if (!has_cache) {
if (ui) ui->Print("No /cache partition found.\n");
return false;
}
if (confirm_func && !confirm_func()) {
return false;
}
if (ui) {
ui->Print("\n-- Wiping cache...\n");
ui->SetBackground(RecoveryUI::ERASING);
ui->SetProgressType(RecoveryUI::INDETERMINATE);
}
bool success = EraseVolume("/cache", ui, new_fstype);
if (ui) ui->Print("Cache wipe %s.\n", success ? "complete" : "failed");
return success;
}