OSDN Git Service

Don't require three-character extensions for dex locations.
authorRichard Uhler <ruhler@google.com>
Thu, 26 Feb 2015 19:08:57 +0000 (11:08 -0800)
committerRichard Uhler <ruhler@google.com>
Thu, 26 Feb 2015 19:08:57 +0000 (11:08 -0800)
Bug: 19437875
Change-Id: Ib62b4c691b04f27c5d499affd5a7fd4d9f0c64f9

runtime/utils.cc
runtime/utils.h
runtime/utils_test.cc

index 6afc373..d09f27a 100644 (file)
@@ -1519,14 +1519,16 @@ std::string GetSystemImageFilename(const char* location, const InstructionSet is
 std::string DexFilenameToOdexFilename(const std::string& location, const InstructionSet isa) {
   // location = /foo/bar/baz.jar
   // odex_location = /foo/bar/<isa>/baz.odex
-
-  CHECK_GE(location.size(), 4U) << location;  // must be at least .123
   std::string odex_location(location);
   InsertIsaDirectory(isa, &odex_location);
-  size_t dot_index = odex_location.size() - 3 - 1;  // 3=dex or zip or apk
-  CHECK_EQ('.', odex_location[dot_index]) << location;
+  size_t dot_index = odex_location.rfind('.');
+
+  // The location must have an extension, otherwise it's not clear what we
+  // should return.
+  CHECK_NE(dot_index, std::string::npos) << odex_location;
+  CHECK_EQ(std::string::npos, odex_location.find('/', dot_index)) << odex_location;
+
   odex_location.resize(dot_index + 1);
-  CHECK_EQ('.', odex_location[odex_location.size()-1]) << location << " " << odex_location;
   odex_location += "odex";
   return odex_location;
 }
index 698d686..9d04d35 100644 (file)
@@ -516,8 +516,9 @@ std::string GetDalvikCacheFilenameOrDie(const char* file_location,
 // Returns the system location for an image
 std::string GetSystemImageFilename(const char* location, InstructionSet isa);
 
-// Returns an .odex file name next adjacent to the dex location.
+// Returns an .odex file name adjacent to the dex location.
 // For example, for "/foo/bar/baz.jar", return "/foo/bar/<isa>/baz.odex".
+// The dex location must include a directory component and have an extension.
 // Note: does not support multidex location strings.
 std::string DexFilenameToOdexFilename(const std::string& location, InstructionSet isa);
 
index a3dd13c..5465762 100644 (file)
@@ -374,6 +374,8 @@ TEST_F(UtilsTest, GetSystemImageFilename) {
 TEST_F(UtilsTest, DexFilenameToOdexFilename) {
   EXPECT_STREQ("/foo/bar/arm/baz.odex",
                DexFilenameToOdexFilename("/foo/bar/baz.jar", kArm).c_str());
+  EXPECT_STREQ("/foo/bar/arm/baz.odex",
+               DexFilenameToOdexFilename("/foo/bar/baz.funnyext", kArm).c_str());
 }
 
 TEST_F(UtilsTest, ExecSuccess) {