diff options
author | 2016-03-25 16:56:20 +0000 | |
---|---|---|
committer | 2016-03-25 16:56:21 +0000 | |
commit | d1a6a2495ff82893728571136f4f080164c8dae5 (patch) | |
tree | 9c339340eb11f04ce0c093210c96417a8de4b435 | |
parent | 830f5004da53a83e23b4102ba9b72e4cb366cb34 (diff) | |
parent | edae669f18eb99b9316891fdde627e2f385c3c64 (diff) |
Merge "Do not clean profiles unconditonally during app data clean up" into nyc-dev
-rw-r--r-- | cmds/installd/commands.cpp | 59 | ||||
-rw-r--r-- | cmds/installd/commands.h | 3 | ||||
-rw-r--r-- | cmds/installd/installd.cpp | 13 |
3 files changed, 48 insertions, 27 deletions
diff --git a/cmds/installd/commands.cpp b/cmds/installd/commands.cpp index c0e0214030..8350da76a7 100644 --- a/cmds/installd/commands.cpp +++ b/cmds/installd/commands.cpp @@ -173,35 +173,43 @@ static bool unlink_reference_profile(const char* pkgname) { return true; } +static bool unlink_current_profile(const char* pkgname, userid_t user) { + std::string profile_dir = create_data_user_profile_package_path(user, pkgname); + std::string profile = create_primary_profile(profile_dir); + if (unlink(profile.c_str()) != 0) { + if (errno != ENOENT) { + PLOG(WARNING) << "Could not unlink " << profile; + return false; + } + } + return true; +} + static bool unlink_current_profiles(const char* pkgname) { bool success = true; std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr); for (auto user : users) { - std::string profile_dir = create_data_user_profile_package_path(user, pkgname); - std::string profile = create_primary_profile(profile_dir); - if (unlink(profile.c_str()) != 0) { - if (errno != ENOENT) { - PLOG(WARNING) << "Could not unlink " << profile; - success = false; - } - } + success &= unlink_current_profile(pkgname, user); } return success; } -static bool unlink_all_profiles(const char* pkgname) { +int clear_app_profiles(const char* pkgname) { bool success = true; success &= unlink_reference_profile(pkgname); success &= unlink_current_profiles(pkgname); - return success; + return success ? 0 : -1; } int clear_app_data(const char *uuid, const char *pkgname, userid_t userid, int flags) { std::string suffix = ""; + bool only_cache = false; if (flags & FLAG_CLEAR_CACHE_ONLY) { suffix = CACHE_DIR_POSTFIX; + only_cache = true; } else if (flags & FLAG_CLEAR_CODE_CACHE_ONLY) { suffix = CODE_CACHE_DIR_POSTFIX; + only_cache = true; } int res = 0; @@ -217,17 +225,27 @@ int clear_app_data(const char *uuid, const char *pkgname, userid_t userid, int f // TODO: include result once 25796509 is fixed delete_dir_contents(path); } - unlink_all_profiles(pkgname); + if (!only_cache) { + if (!unlink_current_profile(pkgname, userid)) { + res |= -1; + } + } } return res; } -static int destroy_app_profiles(const char *pkgname, userid_t userid) { - // TODO: this doesn't destroy the marks for foreign dex use yet. - int res = 0; - res |= delete_dir_contents_and_dir(create_data_user_profile_package_path( userid, pkgname)); - res |= delete_dir_contents_and_dir(create_data_ref_profile_package_path(pkgname)); - return res; +static int destroy_app_current_profiles(const char *pkgname, userid_t userid) { + return delete_dir_contents_and_dir(create_data_user_profile_package_path(userid, pkgname)); +} + +int destroy_app_profiles(const char *pkgname) { + int result = 0; + std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr); + for (auto user : users) { + result |= destroy_app_current_profiles(pkgname, user); + } + result |= delete_dir_contents_and_dir(create_data_ref_profile_package_path(pkgname)); + return result; } int destroy_app_data(const char *uuid, const char *pkgname, userid_t userid, int flags) { @@ -239,8 +257,8 @@ int destroy_app_data(const char *uuid, const char *pkgname, userid_t userid, int if (flags & FLAG_STORAGE_DE) { res |= delete_dir_contents_and_dir( create_data_user_de_package_path(uuid, userid, pkgname)); - res |= destroy_app_profiles(pkgname, userid); } + destroy_app_current_profiles(pkgname, userid); return res; } @@ -1780,11 +1798,6 @@ int rm_package_dir(const char* apk_path) return delete_dir_contents(apk_path, 1 /* also_delete_dir */ , NULL /* exclusion_predicate */); } -int rm_profiles(const char* pkgname) -{ - return unlink_all_profiles(pkgname) ? 0 : -1; -} - int link_file(const char* relative_path, const char* from_base, const char* to_base) { char from_path[PKG_PATH_MAX]; char to_path[PKG_PATH_MAX]; diff --git a/cmds/installd/commands.h b/cmds/installd/commands.h index 70cb410907..13143c55c9 100644 --- a/cmds/installd/commands.h +++ b/cmds/installd/commands.h @@ -59,7 +59,8 @@ int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int u int idmap(const char *target_path, const char *overlay_path, uid_t uid); int create_oat_dir(const char* oat_dir, const char *instruction_set); int rm_package_dir(const char* apk_path); -int rm_profiles(const char* pkgname); +int clear_app_profiles(const char* pkgname); +int destroy_app_profiles(const char* pkgname); int link_file(const char *relative_path, const char *from_base, const char *to_base); // Move a B version over to the A location. Only works for oat_dir != nullptr. diff --git a/cmds/installd/installd.cpp b/cmds/installd/installd.cpp index dc3418a6a3..de3f54ab6d 100644 --- a/cmds/installd/installd.cpp +++ b/cmds/installd/installd.cpp @@ -358,10 +358,16 @@ static int do_rm_package_dir(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) return rm_package_dir(arg[0]); } -static int do_rm_profiles(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) +static int do_clear_app_profiles(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) { /* package_name */ - return rm_profiles(arg[0]); + return clear_app_profiles(arg[0]); +} + +static int do_destroy_app_profiles(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) +{ + /* package_name */ + return destroy_app_profiles(arg[0]); } static int do_link_file(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) @@ -402,7 +408,8 @@ struct cmdinfo cmds[] = { { "idmap", 3, do_idmap }, { "createoatdir", 2, do_create_oat_dir }, { "rmpackagedir", 1, do_rm_package_dir }, - { "rmprofiles", 1, do_rm_profiles }, + { "clear_app_profiles", 1, do_clear_app_profiles }, + { "destroy_app_profiles", 1, do_destroy_app_profiles }, { "linkfile", 3, do_link_file }, { "move_ab", 3, do_move_ab }, { "merge_profiles", 2, do_merge_profiles }, |