Make files writable on the installd path as well

Bug: 9618388
Change-Id: Iabfdfe2bbc44de1fec733269c08a243af75c7dcd
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index b6a7683..3848b6d 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -420,10 +420,6 @@
       LOG(WARNING) << "Failed to open .dex from file '" << dex_filename << "'\n";
       ++failure_count;
     } else {
-      // Ensure writable for dex-to-dex transformations.
-      if (!dex_file->EnableWrite()) {
-        PLOG(ERROR) << "Failed to make .dex file writeable '" << dex_filename << "'\n";
-      }
       dex_files.push_back(dex_file);
     }
   }
@@ -923,6 +919,13 @@
         return EXIT_FAILURE;
       }
     }
+
+    // Ensure opened dex files are writable for dex-to-dex transformations.
+    for (const auto& dex_file : dex_files) {
+      if (!dex_file->EnableWrite()) {
+        PLOG(ERROR) << "Failed to make .dex file writeable '" << dex_file->GetLocation() << "'\n";
+      }
+    }
   }
 
   /*