summaryrefslogtreecommitdiff
path: root/apexd/apexd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'apexd/apexd.cpp')
-rw-r--r--apexd/apexd.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/apexd/apexd.cpp b/apexd/apexd.cpp
index 5c0a471..a2f56cf 100644
--- a/apexd/apexd.cpp
+++ b/apexd/apexd.cpp
@@ -908,14 +908,15 @@ Result<void> Unmount(const MountedApexData& data) {
return android::apex::Unmount(data);
}
-bool IsMounted(const std::string& name, const std::string& full_path) {
+bool IsMounted(const std::string& full_path) {
bool found_mounted = false;
- gMountedApexes.ForallMountedApexes(
- name, [&](const MountedApexData& data, bool latest ATTRIBUTE_UNUSED) {
- if (full_path == data.full_path) {
- found_mounted = true;
- }
- });
+ gMountedApexes.ForallMountedApexes([&](const std::string&,
+ const MountedApexData& data,
+ [[maybe_unused]] bool latest) {
+ if (full_path == data.full_path) {
+ found_mounted = true;
+ }
+ });
return found_mounted;
}
@@ -2116,9 +2117,14 @@ void RemoveOrphanedApexes() {
for (const auto& path : *data_apexes) {
auto apex = ApexFile::Open(path);
if (!apex.ok()) {
- LOG(DEBUG) << "Removing corrupt APEX " << path << " : " << apex.error();
- if (unlink(path.c_str()) != 0) {
- PLOG(ERROR) << "Failed to unlink " << path;
+ LOG(DEBUG) << "Failed to open APEX " << path << " : " << apex.error();
+ // before removing, double-check if the path is active or not
+ // just in case ApexFile::Open() fails with valid APEX
+ if (!apexd_private::IsMounted(path)) {
+ LOG(DEBUG) << "Removing corrupt APEX " << path;
+ if (unlink(path.c_str()) != 0) {
+ PLOG(ERROR) << "Failed to unlink " << path;
+ }
}
continue;
}