From f7005bc28acf5f8ca40c1db156f81bb307b87f3d Mon Sep 17 00:00:00 2001 From: chensihan Date: Mon, 11 Nov 2024 15:19:22 +0800 Subject: [PATCH] =?UTF-8?q?getlocal=E5=8A=A0=E5=9B=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chensihan --- services/backup_sa/include/module_ipc/service.h | 2 ++ services/backup_sa/src/module_ipc/service.cpp | 1 + .../src/module_ipc/service_incremental.cpp | 13 +++++++++++++ tests/mock/module_ipc/service_mock.cpp | 4 ++++ 4 files changed, 20 insertions(+) diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 1920da70c..b942f1c5d 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -508,6 +508,8 @@ private: std::map &isClearDataFlags); void TimeoutRadarReport(IServiceReverse::Scenario scenario, std::string &bundleName); + + void CreateDirIfNotExist(const std::string &path); private: static sptr instance_; static std::mutex instanceLock_; diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 28fe3e312..6ee69d2de 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -170,6 +170,7 @@ UniqueFd Service::GetLocalCapabilities() VerifyCaller(); string path = BConstants::GetSaBundleBackupRootDir(session_->GetSessionUserId()); BExcepUltils::VerifyPath(path, false); + CreateDirIfNotExist(path); UniqueFd fd(open(path.data(), O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR)); if (fd < 0) { HILOGE("Failed to open config file = %{private}s, err = %{public}d", path.c_str(), errno); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 1942a5aad..8c7cfefd5 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -109,6 +109,18 @@ void Service::RemoveExtensionMutex(const BundleName &bundleName) backupExtMutexMap_.erase(it); } +void Service::CreateDirIfNotExist(const std::string &path) +{ + if (access(path.c_str(), F_OK) != 0) { + bool created = ForceCreateDirectory(path.data()); + if (created) { + HILOGI("Create directory successfully."); + } else { + HILOGE("Failed to create directory, path = %{private}s, err = %{public}d", path.c_str(), errno); + } + } +} + UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -127,6 +139,7 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorGetSessionUserId()); BExcepUltils::VerifyPath(path, false); + CreateDirIfNotExist(path); UniqueFd fd(open(path.data(), O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR)); if (fd < 0) { HILOGE("GetLocalCapabilitiesIncremental: open file failed, err = %{public}d", errno); diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index affa3e024..ee77c0544 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -262,4 +262,8 @@ std::shared_ptr Service::GetExtensionMutex(const BundleName void Service::RemoveExtensionMutex(const BundleName &bundleName) { } + +void Service::CreateDirIfNotExist(const std::string &path) +{ +} } // namespace OHOS::FileManagement::Backup -- Gitee