Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 74687141 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Per user, per storage type cleanup to match PM behavior."

parents 0a258b89 58a7309e
Loading
Loading
Loading
Loading
+10 −6
Original line number Original line Diff line number Diff line
@@ -3176,16 +3176,20 @@ binder::Status InstalldNativeService::migrateLegacyObbData() {
    return ok();
    return ok();
}
}


binder::Status InstalldNativeService::cleanupDeletedDirs(const std::optional<std::string>& uuid) {
binder::Status InstalldNativeService::cleanupInvalidPackageDirs(
        const std::optional<std::string>& uuid, int32_t userId, int32_t flags) {
    const char* uuid_cstr = uuid ? uuid->c_str() : nullptr;
    const char* uuid_cstr = uuid ? uuid->c_str() : nullptr;
    const auto users = get_known_users(uuid_cstr);

    for (auto userId : users) {
    if (flags & FLAG_STORAGE_CE) {
        auto ce_path = create_data_user_ce_path(uuid_cstr, userId);
        auto ce_path = create_data_user_ce_path(uuid_cstr, userId);
        auto de_path = create_data_user_de_path(uuid_cstr, userId);
        cleanup_invalid_package_dirs_under_path(ce_path);
    }


        find_and_delete_renamed_deleted_dirs_under_path(ce_path);
    if (flags & FLAG_STORAGE_DE) {
        find_and_delete_renamed_deleted_dirs_under_path(de_path);
        auto de_path = create_data_user_de_path(uuid_cstr, userId);
        cleanup_invalid_package_dirs_under_path(de_path);
    }
    }

    return ok();
    return ok();
}
}


+2 −1
Original line number Original line Diff line number Diff line
@@ -184,7 +184,8 @@ public:


    binder::Status migrateLegacyObbData();
    binder::Status migrateLegacyObbData();


    binder::Status cleanupDeletedDirs(const std::optional<std::string>& uuid);
    binder::Status cleanupInvalidPackageDirs(const std::optional<std::string>& uuid, int32_t userId,
                                             int32_t flags);


private:
private:
    std::recursive_mutex mLock;
    std::recursive_mutex mLock;
+1 −1
Original line number Original line Diff line number Diff line
@@ -126,7 +126,7 @@ interface IInstalld {


    void migrateLegacyObbData();
    void migrateLegacyObbData();


    void cleanupDeletedDirs(@nullable @utf8InCpp String uuid);
    void cleanupInvalidPackageDirs(@nullable @utf8InCpp String uuid, int userId, int flags);


    const int FLAG_STORAGE_DE = 0x1;
    const int FLAG_STORAGE_DE = 0x1;
    const int FLAG_STORAGE_CE = 0x2;
    const int FLAG_STORAGE_CE = 0x2;
+16 −16
Original line number Original line Diff line number Diff line
@@ -275,8 +275,8 @@ TEST_F(ServiceTest, DestroyAppData) {
    EXPECT_FALSE(exists_renamed_deleted_dir());
    EXPECT_FALSE(exists_renamed_deleted_dir());
}
}


TEST_F(ServiceTest, CleanupDeletedDirs) {
TEST_F(ServiceTest, CleanupInvalidPackageDirs) {
    LOG(INFO) << "CleanupDeletedDirs";
    LOG(INFO) << "CleanupInvalidPackageDirs";


    mkdir("5b14b6458a44==deleted==", 10000, 10000, 0700);
    mkdir("5b14b6458a44==deleted==", 10000, 10000, 0700);
    mkdir("5b14b6458a44==deleted==/foo", 10000, 10000, 0700);
    mkdir("5b14b6458a44==deleted==/foo", 10000, 10000, 0700);
@@ -286,11 +286,11 @@ TEST_F(ServiceTest, CleanupDeletedDirs) {


    auto fd = create("5b14b6458a44==deleted==/bar/opened_file", 10000, 20000, 0700);
    auto fd = create("5b14b6458a44==deleted==/bar/opened_file", 10000, 20000, 0700);


    mkdir("5b14b6458a44==NOTdeleted==", 10000, 10000, 0700);
    mkdir("b14b6458a44NOTdeleted", 10000, 10000, 0700);
    mkdir("5b14b6458a44==NOTdeleted==/foo", 10000, 10000, 0700);
    mkdir("b14b6458a44NOTdeleted/foo", 10000, 10000, 0700);
    touch("5b14b6458a44==NOTdeleted==/foo/file", 10000, 20000, 0700);
    touch("b14b6458a44NOTdeleted/foo/file", 10000, 20000, 0700);
    mkdir("5b14b6458a44==NOTdeleted==/bar", 10000, 20000, 0700);
    mkdir("b14b6458a44NOTdeleted/bar", 10000, 20000, 0700);
    touch("5b14b6458a44==NOTdeleted==/bar/file", 10000, 20000, 0700);
    touch("b14b6458a44NOTdeleted/bar/file", 10000, 20000, 0700);


    mkdir("com.example", 10000, 10000, 0700);
    mkdir("com.example", 10000, 10000, 0700);
    mkdir("com.example/foo", 10000, 10000, 0700);
    mkdir("com.example/foo", 10000, 10000, 0700);
@@ -310,10 +310,10 @@ TEST_F(ServiceTest, CleanupDeletedDirs) {
    EXPECT_TRUE(exists("5b14b6458a44==deleted==/bar/file"));
    EXPECT_TRUE(exists("5b14b6458a44==deleted==/bar/file"));
    EXPECT_TRUE(exists("5b14b6458a44==deleted==/bar/opened_file"));
    EXPECT_TRUE(exists("5b14b6458a44==deleted==/bar/opened_file"));


    EXPECT_TRUE(exists("5b14b6458a44==NOTdeleted==/foo"));
    EXPECT_TRUE(exists("b14b6458a44NOTdeleted/foo"));
    EXPECT_TRUE(exists("5b14b6458a44==NOTdeleted==/foo/file"));
    EXPECT_TRUE(exists("b14b6458a44NOTdeleted/foo/file"));
    EXPECT_TRUE(exists("5b14b6458a44==NOTdeleted==/bar"));
    EXPECT_TRUE(exists("b14b6458a44NOTdeleted/bar"));
    EXPECT_TRUE(exists("5b14b6458a44==NOTdeleted==/bar/file"));
    EXPECT_TRUE(exists("b14b6458a44NOTdeleted/bar/file"));


    EXPECT_TRUE(exists("com.example/foo"));
    EXPECT_TRUE(exists("com.example/foo"));
    EXPECT_TRUE(exists("com.example/foo/file"));
    EXPECT_TRUE(exists("com.example/foo/file"));
@@ -327,7 +327,7 @@ TEST_F(ServiceTest, CleanupDeletedDirs) {


    EXPECT_TRUE(exists_renamed_deleted_dir());
    EXPECT_TRUE(exists_renamed_deleted_dir());


    service->cleanupDeletedDirs(testUuid);
    service->cleanupInvalidPackageDirs(testUuid, 0, FLAG_STORAGE_CE | FLAG_STORAGE_DE);


    EXPECT_EQ(::close(fd), 0);
    EXPECT_EQ(::close(fd), 0);


@@ -337,10 +337,10 @@ TEST_F(ServiceTest, CleanupDeletedDirs) {
    EXPECT_FALSE(exists("5b14b6458a44==deleted==/bar/file"));
    EXPECT_FALSE(exists("5b14b6458a44==deleted==/bar/file"));
    EXPECT_FALSE(exists("5b14b6458a44==deleted==/bar/opened_file"));
    EXPECT_FALSE(exists("5b14b6458a44==deleted==/bar/opened_file"));


    EXPECT_TRUE(exists("5b14b6458a44==NOTdeleted==/foo"));
    EXPECT_TRUE(exists("b14b6458a44NOTdeleted/foo"));
    EXPECT_TRUE(exists("5b14b6458a44==NOTdeleted==/foo/file"));
    EXPECT_TRUE(exists("b14b6458a44NOTdeleted/foo/file"));
    EXPECT_TRUE(exists("5b14b6458a44==NOTdeleted==/bar"));
    EXPECT_TRUE(exists("b14b6458a44NOTdeleted/bar"));
    EXPECT_TRUE(exists("5b14b6458a44==NOTdeleted==/bar/file"));
    EXPECT_TRUE(exists("b14b6458a44NOTdeleted/bar/file"));


    EXPECT_TRUE(exists("com.example/foo"));
    EXPECT_TRUE(exists("com.example/foo"));
    EXPECT_TRUE(exists("com.example/foo/file"));
    EXPECT_TRUE(exists("com.example/foo/file"));
+14 −7
Original line number Original line Diff line number Diff line
@@ -652,7 +652,7 @@ static auto open_dir(const char* dir) {
    return std::unique_ptr<DIR, DirCloser>(::opendir(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());
    auto dir = open_dir(pathname.c_str());
    if (!dir) {
    if (!dir) {
        return;
        return;
@@ -668,14 +668,21 @@ void find_and_delete_renamed_deleted_dirs_under_path(const std::string& pathname
        if (de->d_type != DT_DIR) {
        if (de->d_type != DT_DIR) {
            continue;
            continue;
        }
        }
        const char* name = de->d_name;

        if (is_renamed_deleted_dir({name})) {
        std::string name{de->d_name};
            LOG(INFO) << "Deleting renamed data directory: " << 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.
            // Deleting the content.
            delete_dir_contents_fd(dfd, name);
            delete_dir_contents_fd(dfd, name.c_str());
            // Deleting the directory
            // Deleting the directory
            if (unlinkat(dfd, name, AT_REMOVEDIR) < 0) {
            if (unlinkat(dfd, name.c_str(), AT_REMOVEDIR) < 0) {
                ALOGE("Couldn't unlinkat %s: %s\n", name, strerror(errno));
                ALOGE("Couldn't unlinkat %s: %s\n", name.c_str(), strerror(errno));
            }
            }
        }
        }
    }
    }
Loading