Always unlink the out_vdex_file.
Even if we pass the same vdex file as input and output to
dex2oat, make sure we unlink it if dex2oat failed.
bug:38113240
Test: manual, killing dex2oat invocation
Change-Id: I406014f97a2c3b2bd646e13b5d86dfa0eaa2692f
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp
index 007505c..797cc15 100644
--- a/cmds/installd/dexopt.cpp
+++ b/cmds/installd/dexopt.cpp
@@ -1209,7 +1209,11 @@
if (dexopt_action == DEX2OAT_FOR_BOOT_IMAGE &&
in_vdex_wrapper_fd->get() != -1 &&
in_vdex_path_str == out_vdex_path_str) {
- out_vdex_wrapper_fd->reset(in_vdex_wrapper_fd->get());
+ // We unlink the file in case the invocation of dex2oat fails, to ensure we don't
+ // have bogus stale vdex files.
+ out_vdex_wrapper_fd->reset(
+ in_vdex_wrapper_fd->get(),
+ [out_vdex_path_str]() { unlink(out_vdex_path_str.c_str()); });
// Disable auto close for the in wrapper fd (it will be done when destructing the out
// wrapper).
in_vdex_wrapper_fd->DisableAutoClose();