OSDN Git Service

Do not return an error if the dalvik-cache odex is missing
authorCalin Juravle <calin@google.com>
Thu, 4 May 2017 00:22:27 +0000 (17:22 -0700)
committerCalin Juravle <calin@google.com>
Mon, 8 May 2017 21:21:02 +0000 (14:21 -0700)
Test: adb shell /data/nativetest/installd_service_test/installd_service_test
      Tried uninstalling an updated version of prebuilt app.
      Didn't find the error message in the logcat.
Bug: 35804241
Change-Id: Iec045fa9c9ac8f036785fe5cbd0f7e43f2b680c1

cmds/installd/InstalldNativeService.cpp
cmds/installd/tests/installd_service_test.cpp

index 49a3b23..25dbe98 100644 (file)
@@ -1089,10 +1089,13 @@ binder::Status InstalldNativeService::rmdex(const std::string& codePath,
 
     ALOGV("unlink %s\n", dex_path);
     if (unlink(dex_path) < 0) {
-        return error(StringPrintf("Failed to unlink %s", dex_path));
-    } else {
-        return ok();
+        // It's ok if we don't have a dalvik cache path. Report error only when the path exists
+        // but could not be unlinked.
+        if (errno != ENOENT) {
+            return error(StringPrintf("Failed to unlink %s", dex_path));
+        }
     }
+    return ok();
 }
 
 struct stats {
index 4a1f333..34818f6 100644 (file)
@@ -54,10 +54,12 @@ bool calculate_odex_file_path(char path[PKG_PATH_MAX] ATTRIBUTE_UNUSED,
     return false;
 }
 
-bool create_cache_path(char path[PKG_PATH_MAX] ATTRIBUTE_UNUSED,
-        const char *src ATTRIBUTE_UNUSED,
-        const char *instruction_set ATTRIBUTE_UNUSED) {
-    return false;
+bool create_cache_path(char path[PKG_PATH_MAX],
+        const char *src,
+        const char *instruction_set) {
+    // Not really a valid path but it's good enough for testing.
+    sprintf(path,"/data/dalvik-cache/%s/%s", instruction_set, src);
+    return true;
 }
 
 static void mkdir(const char* path, uid_t owner, gid_t group, mode_t mode) {
@@ -151,5 +153,13 @@ TEST_F(ServiceTest, FixupAppData_Moved) {
     EXPECT_EQ(10000, stat_gid("com.example/bar/file"));
 }
 
+TEST_F(ServiceTest, RmDexNoDalvikCache) {
+    LOG(INFO) << "RmDexNoDalvikCache";
+
+    // Try to remove a non existing dalvik cache dex. The call should be
+    // successful because there's nothing to remove.
+    EXPECT_TRUE(service->rmdex("com.example", "arm").isOk());
+}
+
 }  // namespace installd
 }  // namespace android