}
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;
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;
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);
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;
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;