From e3065659b5d944712dcd89ccd317435acddbc051 Mon Sep 17 00:00:00 2001 From: Zhou Shihui Date: Mon, 16 Jun 2025 10:34:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E8=A3=85=E7=9B=AE=E5=BD=95=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=A4=B1=E8=B4=A5=E5=90=8Erename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhou Shihui --- .../include/user_unlocked_event_subscriber.h | 2 +- .../src/bundle_mgr_service_event_handler.cpp | 2 +- .../bundlemgr/src/installd/installd_host_impl.cpp | 4 +++- .../src/user_unlocked_event_subscriber.cpp | 15 ++++++++------- .../bms_event_handler_unlocked_test.cpp | 15 +++++++++++++++ 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/services/bundlemgr/include/user_unlocked_event_subscriber.h b/services/bundlemgr/include/user_unlocked_event_subscriber.h index 7ea79b439a..1b77b32027 100644 --- a/services/bundlemgr/include/user_unlocked_event_subscriber.h +++ b/services/bundlemgr/include/user_unlocked_event_subscriber.h @@ -46,7 +46,7 @@ public: static void ProcessExtensionDir(const BundleInfo &bundleInfo, std::vector &dirs); static void CreateSharefilesSubDataDirs(const std::vector &bundleInfos, int32_t userId); static void ProcessNewBackupDir(const std::vector &bundleInfos, int32_t userId); - static void DeleteUninstallTmpDirs(const int32_t userId); + static void DeleteUninstallTmpDirs(const std::set& userIds); private: static void CheckPathAttribute(const std::string &path, const BundleInfo &bundleInfo, bool &isExist); static void CreateNewBackupDir(const BundleInfo &bundleInfo, int32_t userId); diff --git a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp index 42efc8db0a..54b0f3f870 100644 --- a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp +++ b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp @@ -4496,7 +4496,7 @@ void BMSEventHandler::CleanTempDir() const } } - UpdateAppDataMgr::DeleteUninstallTmpDirs(Constants::DEFAULT_USERID); + UpdateAppDataMgr::DeleteUninstallTmpDirs(std::set{Constants::DEFAULT_USERID}); } void BMSEventHandler::CheckBundleProvisionInfo() diff --git a/services/bundlemgr/src/installd/installd_host_impl.cpp b/services/bundlemgr/src/installd/installd_host_impl.cpp index 6310b42b19..139be37fe2 100644 --- a/services/bundlemgr/src/installd/installd_host_impl.cpp +++ b/services/bundlemgr/src/installd/installd_host_impl.cpp @@ -117,7 +117,9 @@ ErrCode InstalldHostImpl::CreateBundleDir(const std::string &bundleDir) } if (InstalldOperator::IsExistDir(bundleDir)) { LOG_W(BMS_TAG_INSTALLD, "bundleDir %{public}s is exist", bundleDir.c_str()); - OHOS::ForceRemoveDirectoryBMS(bundleDir); + if (!OHOS::ForceRemoveDirectoryBMS(bundleDir)) { + InstalldOperator::DeleteDirFlexible(bundleDir, true); + } } if (!InstalldOperator::MkRecursiveDir(bundleDir, true)) { LOG_E(BMS_TAG_INSTALLD, "create bundle dir %{public}s failed, errno:%{public}d", bundleDir.c_str(), errno); diff --git a/services/bundlemgr/src/user_unlocked_event_subscriber.cpp b/services/bundlemgr/src/user_unlocked_event_subscriber.cpp index 296186cb4f..d49b24a283 100644 --- a/services/bundlemgr/src/user_unlocked_event_subscriber.cpp +++ b/services/bundlemgr/src/user_unlocked_event_subscriber.cpp @@ -71,7 +71,7 @@ void UserUnlockedEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData userId_ = userId; std::thread updateDataDirThread(UpdateAppDataMgr::UpdateAppDataDirSelinuxLabel, userId); updateDataDirThread.detach(); - std::thread(UpdateAppDataMgr::DeleteUninstallTmpDirs, userId).detach(); + std::thread(UpdateAppDataMgr::DeleteUninstallTmpDirs, std::set{userId}).detach(); #ifdef BUNDLE_FRAMEWORK_APP_CONTROL DelayedSingleton::GetInstance()->SetAppInstallControlStatus(); #endif @@ -86,7 +86,7 @@ void UserUnlockedEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData userId_ = userId; std::thread updateDataDirThread(UpdateAppDataMgr::UpdateAppDataDirSelinuxLabel, userId); updateDataDirThread.detach(); - std::thread(UpdateAppDataMgr::DeleteUninstallTmpDirs, userId).detach(); + std::thread(UpdateAppDataMgr::DeleteUninstallTmpDirs, std::set{userId}).detach(); } #if defined (BUNDLE_FRAMEWORK_SANDBOX_APP) && defined (DLP_PERMISSION_ENABLE) APP_LOGI("RemoveUnreservedSandbox call ClearUnreservedSandbox"); @@ -190,13 +190,14 @@ bool UpdateAppDataMgr::CreateEl5Dir(const CreateDirParam &createDirParam) return true; } -void UpdateAppDataMgr::DeleteUninstallTmpDirs(const int32_t userId) +void UpdateAppDataMgr::DeleteUninstallTmpDirs(const std::set& userIds) { - std::vector dirs = GetBundleDataDirs(userId); - if (dirs.empty()) { - LOG_I(BMS_TAG_DEFAULT, "dirs empty"); - return; + std::vector dirs; + for (const int32_t &userId : userIds) { + std::vector tmpDirs = GetBundleDataDirs(userId); + dirs.insert(dirs.end(), tmpDirs.begin(), tmpDirs.end()); } + dirs.emplace_back(Constants::BUNDLE_CODE_DIR); ErrCode ret = InstalldClient::GetInstance()->DeleteUninstallTmpDirs(dirs); if (ret != ERR_OK) { LOG_W(BMS_TAG_DEFAULT, "delete tmp dirs failed:%{public}d", ret); diff --git a/services/bundlemgr/test/unittest/bms_event_handler_test/bms_event_handler_unlocked_test.cpp b/services/bundlemgr/test/unittest/bms_event_handler_test/bms_event_handler_unlocked_test.cpp index 72b7e30c8d..949b52d93d 100644 --- a/services/bundlemgr/test/unittest/bms_event_handler_test/bms_event_handler_unlocked_test.cpp +++ b/services/bundlemgr/test/unittest/bms_event_handler_test/bms_event_handler_unlocked_test.cpp @@ -156,4 +156,19 @@ HWTEST_F(BmsEventHandlerUnLockedTest, UserUnlockedEventSubscriber_0500, Function bool res = updateAppDataMgr.CreateEl5Dir(createDirParam); EXPECT_EQ(res, false); } + +/** + * @tc.number: UserUnlockedEventSubscriber_0800 + * @tc.name: GetBundleDataDirs and DeleteUninstallTmpDirs + * @tc.desc: test GetBundleDataDirs and DeleteUninstallTmpDirs + */ +HWTEST_F(BmsEventHandlerUnLockedTest, UserUnlockedEventSubscriber_0800, Function | SmallTest | Level0) +{ + UpdateAppDataMgr updateAppDataMgr; + std::vector dirs = updateAppDataMgr.GetBundleDataDirs(100); + updateAppDataMgr.DeleteUninstallTmpDirs({}); + updateAppDataMgr.DeleteUninstallTmpDirs({100}); + updateAppDataMgr.DeleteUninstallTmpDirs({0, 1}); + EXPECT_EQ(dirs.size(), ServiceConstants::BUNDLE_EL.size() * 2); +} } // OHOS \ No newline at end of file -- Gitee