diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 6e1677d019e4d54ab83066148a26058c7072544c..87afdaaeb7d0e2d62b422a48c5a4b4e65c12b075 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -517,6 +517,8 @@ private: void TimeoutRadarReport(IServiceReverse::Scenario scenario, std::string &bundleName); + void CreateDirIfNotExist(const std::string &path); + void OnBundleStarted(BError error, sptr session, const BundleName &bundleName); void HandleExceptionOnAppendBundles(sptr session, const vector &appendBundleNames, diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 5785bc60ca89d7c74900330358c761bb89708342..8048c2f3997256ed7b71dbe426bf05c0c33de6b4 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -279,6 +279,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 7d330e0d1c04e65dddc6b517dbd60289aa1c7b0c..88c084e9d7023313bd65b0b3568d7da56986892a 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 657809995d06256233af7369b0fabf97f00b6d54..3fdca2e861b97dc5b38feb39e88189480496d03f 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -264,6 +264,10 @@ void Service::RemoveExtensionMutex(const BundleName &bundleName) { } +void Service::CreateDirIfNotExist(const std::string &path) +{ +} + void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) {} void Service::HandleExceptionOnAppendBundles(sptr session,