diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index ba0037ae624de2e62ebf60b4003b557f98a74c1c..828c311bc4106db63916f933fb08abec79a91afe 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -516,6 +516,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 d74c93b7dd11142ad802588240b7f76a2e691872..7e28d3e7a94b3f437791504e24b6608b02cfaa50 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -174,6 +174,7 @@ UniqueFd Service::GetLocalCapabilities() VerifyCaller(); string path = BConstants::GetSaBundleBackupRootDir(GetUserIdDefault()); 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 628ff6185014b90881aaa510e6ef54be77d50ed8..0d643218c829747456321387cca0a6beda86f49d 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -110,6 +110,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::vector Service::GetExtensionMutex(const BundleName void Service::RemoveExtensionMutex(const BundleName &bundleName) { } + +void Service::CreateDirIfNotExist(const std::string &path) +{ +} } // namespace OHOS::FileManagement::Backup diff --git a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp index 757f571d1710b2818a09a36b114884102ef1199b..ab3d175d5a167ed9a3543bba320332f95a41e0a0 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -117,6 +117,8 @@ std::shared_ptr Service::GetExtensionMutex(const BundleName } void Service::RemoveExtensionMutex(const BundleName&) {} + +void Service::CreateDirIfNotExist(const std::string&) {} } namespace OHOS::FileManagement::Backup {