Filter duplicate mount points

This prevents umounting existing overlay mount points
This commit is contained in:
LoveSy 2023-03-02 23:16:02 +08:00 committed by John Wu
parent 2285f5e888
commit f59fbd5dca

View File

@ -1,3 +1,4 @@
#include <set>
#include <sys/mount.h>
#include <magisk.hpp>
@ -13,14 +14,24 @@ static void lazy_unmount(const char* mountpoint) {
}
void revert_unmount() {
vector<string> targets;
set<string> targets;
// Unmount dummy skeletons and MAGISKTMP
// since mirror nodes are always mounted under skeleton, we don't have to specifically unmount
for (auto &info: parse_mount_info("self")) {
if (info.source == "magisk" || info.source == "worker" || // magisktmp tmpfs
info.root.starts_with("/adb/modules")) { // bind mount from data partition
targets.push_back(info.target);
targets.insert(info.target);
}
}
if (targets.empty()) return;
for (auto last_target = targets.cbegin(), iter = next(targets.cbegin()); iter != targets.cend();) {
if (iter->starts_with(*last_target)) {
iter = targets.erase(iter);
} else {
last_target = iter++;
}
}