diff options
author | Andreas Gampe <agampe@google.com> | 2016-09-13 16:37:46 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-09-13 16:37:47 +0000 |
commit | a721faee570a215b1e9f965c6b07d7e438393f6a (patch) | |
tree | 906b69044d7074effbdfc9d8044a37c3015b763a | |
parent | e373a97bd767a9b0a9b80fdfdb6996e2ed410cae (diff) | |
parent | 3964da0636624ff9af42d1f316bed0752e37c490 (diff) | |
download | native-a721faee570a215b1e9f965c6b07d7e438393f6a.tar.gz |
Merge "Installd: Add a delete_odex command" into nyc-mr1-dev
-rw-r--r-- | cmds/installd/commands.cpp | 30 | ||||
-rw-r--r-- | cmds/installd/commands.h | 3 | ||||
-rw-r--r-- | cmds/installd/installd.cpp | 6 |
3 files changed, 39 insertions, 0 deletions
diff --git a/cmds/installd/commands.cpp b/cmds/installd/commands.cpp index 31f9d7e4da..5b47b3e500 100644 --- a/cmds/installd/commands.cpp +++ b/cmds/installd/commands.cpp @@ -2202,5 +2202,35 @@ int move_ab(const char* apk_path, const char* instruction_set, const char* oat_d return success ? 0 : -1; } +bool delete_odex(const char *apk_path, const char *instruction_set, const char *oat_dir) { + // Delete the oat/odex file. + char out_path[PKG_PATH_MAX]; + if (!create_oat_out_path(apk_path, instruction_set, oat_dir, out_path)) { + return false; + } + + // In case of a permission failure report the issue. Otherwise just print a warning. + auto unlink_and_check = [](const char* path) -> bool { + int result = unlink(path); + if (result != 0) { + if (errno == EACCES || errno == EPERM) { + PLOG(ERROR) << "Could not unlink " << path; + return false; + } + PLOG(WARNING) << "Could not unlink " << path; + } + return true; + }; + + // Delete the oat/odex file. + bool return_value_oat = unlink_and_check(out_path); + + // Derive and delete the app image. + bool return_value_art = unlink_and_check(create_image_filename(out_path).c_str()); + + // Report success. + return return_value_oat && return_value_art; +} + } // namespace installd } // namespace android diff --git a/cmds/installd/commands.h b/cmds/installd/commands.h index e990f1b695..ba275170a8 100644 --- a/cmds/installd/commands.h +++ b/cmds/installd/commands.h @@ -85,6 +85,9 @@ int link_file(const char *relative_path, const char *from_base, const char *to_b // Move a B version over to the A location. Only works for oat_dir != nullptr. int move_ab(const char *apk_path, const char *instruction_set, const char* oat_dir); +// Delete odex files generated by dexopt. +bool delete_odex(const char *apk_path, const char *instruction_set, const char *oat_dir); + } // namespace installd } // namespace android diff --git a/cmds/installd/installd.cpp b/cmds/installd/installd.cpp index facbc724ec..8f883db050 100644 --- a/cmds/installd/installd.cpp +++ b/cmds/installd/installd.cpp @@ -418,6 +418,11 @@ static int do_move_ab(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) { return move_ab(arg[0], arg[1], arg[2]); } +static int do_delete_odex(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) { + // apk_path, instruction_set, oat_dir + return delete_odex(arg[0], arg[1], arg[2]) ? 0 : -1; +} + struct cmdinfo { const char *name; unsigned numargs; @@ -453,6 +458,7 @@ struct cmdinfo cmds[] = { { "move_ab", 3, do_move_ab }, { "merge_profiles", 2, do_merge_profiles }, { "dump_profiles", 3, do_dump_profiles }, + { "delete_odex", 3, do_delete_odex }, }; static int readx(int s, void *_buf, int count) |