OSDN Git Service

Don't delete /mnt/user/<userId>/package on reset.
authorSudheer Shanka <sudheersai@google.com>
Sat, 23 Feb 2019 01:03:02 +0000 (17:03 -0800)
committerSudheer Shanka <sudheersai@google.com>
Sat, 23 Feb 2019 01:03:02 +0000 (17:03 -0800)
We need this to stay mounted at /storage.

Bug: 124466384
Test: manual
Test: atest cts/hostsidetests/appsecurity/src/android/appsecurity/cts/ExternalStorageHostTest.java
Test: atest cts/tests/tests/provider/src/android/provider/cts/MediaStore*
Change-Id: I0cc835471ced2822d83d7056bec53d62ddc682f0

Utils.cpp
Utils.h
VolumeManager.cpp

index 0a16fc1..6e0fe21 100644 (file)
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -898,20 +898,10 @@ static status_t delete_dir_contents(DIR* dir) {
 }
 
 status_t DeleteDirContentsAndDir(const std::string& pathname) {
-    // Shamelessly borrowed from android::installd
-    std::unique_ptr<DIR, decltype(&closedir)> dirp(opendir(pathname.c_str()), closedir);
-    if (!dirp) {
-        if (errno == ENOENT) {
-            return OK;
-        }
-        PLOG(ERROR) << "Failed to opendir " << pathname;
-        return -errno;
-    }
-    status_t res = delete_dir_contents(dirp.get());
+    status_t res = DeleteDirContents(pathname);
     if (res < 0) {
         return res;
     }
-    dirp.reset(nullptr);
     if (rmdir(pathname.c_str()) != 0) {
         PLOG(ERROR) << "rmdir failed on " << pathname;
         return -errno;
@@ -920,6 +910,19 @@ status_t DeleteDirContentsAndDir(const std::string& pathname) {
     return OK;
 }
 
+status_t DeleteDirContents(const std::string& pathname) {
+    // Shamelessly borrowed from android::installd
+    std::unique_ptr<DIR, decltype(&closedir)> dirp(opendir(pathname.c_str()), closedir);
+    if (!dirp) {
+        if (errno == ENOENT) {
+            return OK;
+        }
+        PLOG(ERROR) << "Failed to opendir " << pathname;
+        return -errno;
+    }
+    return delete_dir_contents(dirp.get());
+}
+
 // TODO(118708649): fix duplication with init/util.h
 status_t WaitForFile(const char* filename, std::chrono::nanoseconds timeout) {
     android::base::Timer t;
diff --git a/Utils.h b/Utils.h
index 9a1fa09..e9b1c32 100644 (file)
--- a/Utils.h
+++ b/Utils.h
@@ -140,6 +140,7 @@ status_t UnmountTreeWithPrefix(const std::string& prefix);
 status_t UnmountTree(const std::string& mountPoint);
 
 status_t DeleteDirContentsAndDir(const std::string& pathname);
+status_t DeleteDirContents(const std::string& pathname);
 
 status_t WaitForFile(const char* filename, std::chrono::nanoseconds timeout);
 
index 83632e4..358d2eb 100644 (file)
@@ -76,6 +76,7 @@ using android::base::StringPrintf;
 using android::base::unique_fd;
 using android::vold::BindMount;
 using android::vold::CreateDir;
+using android::vold::DeleteDirContents;
 using android::vold::DeleteDirContentsAndDir;
 using android::vold::Symlink;
 using android::vold::Unlink;
@@ -1234,7 +1235,7 @@ int VolumeManager::reset() {
     mVisibleVolumeIds.clear();
 
     for (userid_t userId : mStartedUsers) {
-        DeleteDirContentsAndDir(StringPrintf("/mnt/user/%d/package", userId));
+        DeleteDirContents(StringPrintf("/mnt/user/%d/package", userId));
     }
     mStartedUsers.clear();
     return 0;