summaryrefslogtreecommitdiff
path: root/cmds/installd/utils.cpp
diff options
context:
space:
mode:
author Alex Buynytskyy <alexbuy@google.com> 2022-02-14 13:15:53 -0800
committer Alex Buynytskyy <alexbuy@google.com> 2022-02-14 14:41:50 -0800
commit58a7309e9d8ea1e34f7d7db99718a93ac55cdfbb (patch)
tree1fc8cbf0f6e15cfd6716097986162de620a750a6 /cmds/installd/utils.cpp
parent0a258b89c7182b3794604dad13b87a25b6876aaa (diff)
Per user, per storage type cleanup to match PM behavior.
Bug: 162757029 Test: atest installd_service_test installd_cache_test installd_utils_test installd_dexopt_test installd_otapreopt_test installd_file_test Change-Id: I7941396fb2120f6636601e45b71490d86d2c4831
Diffstat (limited to 'cmds/installd/utils.cpp')
-rw-r--r--cmds/installd/utils.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp
index a4a21b720c..8a00be9193 100644
--- a/cmds/installd/utils.cpp
+++ b/cmds/installd/utils.cpp
@@ -652,7 +652,7 @@ static auto open_dir(const char* dir) {
return std::unique_ptr<DIR, DirCloser>(::opendir(dir));
}
-void find_and_delete_renamed_deleted_dirs_under_path(const std::string& pathname) {
+void cleanup_invalid_package_dirs_under_path(const std::string& pathname) {
auto dir = open_dir(pathname.c_str());
if (!dir) {
return;
@@ -668,14 +668,21 @@ void find_and_delete_renamed_deleted_dirs_under_path(const std::string& pathname
if (de->d_type != DT_DIR) {
continue;
}
- const char* name = de->d_name;
- if (is_renamed_deleted_dir({name})) {
- LOG(INFO) << "Deleting renamed data directory: " << name;
+
+ std::string name{de->d_name};
+ // always skip "." and ".."
+ if (name == "." || name == "..") {
+ continue;
+ }
+
+ if (is_renamed_deleted_dir(name) || !is_valid_filename(name) ||
+ !is_valid_package_name(name)) {
+ ALOGI("Deleting renamed or invalid data directory: %s\n", name.c_str());
// Deleting the content.
- delete_dir_contents_fd(dfd, name);
+ delete_dir_contents_fd(dfd, name.c_str());
// Deleting the directory
- if (unlinkat(dfd, name, AT_REMOVEDIR) < 0) {
- ALOGE("Couldn't unlinkat %s: %s\n", name, strerror(errno));
+ if (unlinkat(dfd, name.c_str(), AT_REMOVEDIR) < 0) {
+ ALOGE("Couldn't unlinkat %s: %s\n", name.c_str(), strerror(errno));
}
}
}