Don't delete /mnt/user/<userId>/package on reset.
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
diff --git a/Utils.cpp b/Utils.cpp
index 0a16fc1..6e0fe21 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -898,6 +898,19 @@
}
status_t DeleteDirContentsAndDir(const std::string& pathname) {
+ status_t res = DeleteDirContents(pathname);
+ if (res < 0) {
+ return res;
+ }
+ if (rmdir(pathname.c_str()) != 0) {
+ PLOG(ERROR) << "rmdir failed on " << pathname;
+ return -errno;
+ }
+ LOG(VERBOSE) << "Success: rmdir on " << 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) {
@@ -907,17 +920,7 @@
PLOG(ERROR) << "Failed to opendir " << pathname;
return -errno;
}
- status_t res = delete_dir_contents(dirp.get());
- if (res < 0) {
- return res;
- }
- dirp.reset(nullptr);
- if (rmdir(pathname.c_str()) != 0) {
- PLOG(ERROR) << "rmdir failed on " << pathname;
- return -errno;
- }
- LOG(VERBOSE) << "Success: rmdir on " << pathname;
- return OK;
+ return delete_dir_contents(dirp.get());
}
// TODO(118708649): fix duplication with init/util.h