From c6aa17cc4ad411d37e82978351ffe1aef37fd2eb Mon Sep 17 00:00:00 2001 From: chensihan Date: Sat, 26 Oct 2024 11:39:25 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=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 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index ba0037ae6..828c311bc 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 d74c93b7d..7e28d3e7a 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 628ff6185..2b1092455 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 backup root dir successfully."); + } else { + HILOGE("Failed to create backup root dir, err = %{public}d", 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 Date: Sat, 26 Oct 2024 11:42:58 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=8A=A0=E5=9B=BA=20Signed-off-by:=20chens?= =?UTF-8?q?ihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/backup_sa/src/module_ipc/service_incremental.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 2b1092455..0d643218c 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -115,9 +115,9 @@ void Service::CreateDirIfNotExist(const std::string &path) if (access(path.c_str(), F_OK) != 0) { bool created = ForceCreateDirectory(path.data()); if (created) { - HILOGI("Create backup root dir successfully."); + HILOGI("Create directory successfully."); } else { - HILOGE("Failed to create backup root dir, err = %{public}d", errno); + HILOGE("Failed to create directory, path = %{private}s, err = %{public}d", path.c_str(), errno); } } } -- Gitee From 0bd014d78c8803289b3f9b19a3243dee95de7c7e Mon Sep 17 00:00:00 2001 From: chensihan Date: Sat, 26 Oct 2024 11:42:58 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=8A=A0=E5=9B=BA=20Signed-off-by:=20chens?= =?UTF-8?q?ihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/backup_sa/src/module_ipc/service_incremental.cpp | 4 ++-- tests/mock/module_ipc/service_mock.cpp | 4 ++++ tests/unittests/backup_sa/module_ipc/service_other_test.cpp | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 2b1092455..0d643218c 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -115,9 +115,9 @@ void Service::CreateDirIfNotExist(const std::string &path) if (access(path.c_str(), F_OK) != 0) { bool created = ForceCreateDirectory(path.data()); if (created) { - HILOGI("Create backup root dir successfully."); + HILOGI("Create directory successfully."); } else { - HILOGE("Failed to create backup root dir, err = %{public}d", errno); + HILOGE("Failed to create directory, path = %{private}s, err = %{public}d", path.c_str(), errno); } } } diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 55efa64a3..8e9c5bd4e 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 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 757f571d1..167f98355 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 CreateDirIfNotExist(const std::string &path){} } namespace OHOS::FileManagement::Backup { -- Gitee From f4f208bc2a215ad9386f44c932e421ef3cb62e28 Mon Sep 17 00:00:00 2001 From: chensihan Date: Mon, 28 Oct 2024 11:10:36 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=8A=A0=E5=9B=BA=20Signed-off-by:=20chens?= =?UTF-8?q?ihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/mock/module_ipc/service_mock.cpp | 2 +- tests/unittests/backup_sa/module_ipc/service_other_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 8e9c5bd4e..d2cc3ba15 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -263,7 +263,7 @@ void Service::RemoveExtensionMutex(const BundleName &bundleName) { } -void CreateDirIfNotExist(const std::string &path) +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 b3c224c5a..ab3d175d5 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -118,7 +118,7 @@ std::shared_ptr Service::GetExtensionMutex(const BundleName void Service::RemoveExtensionMutex(const BundleName&) {} -void CreateDirIfNotExist(const std::string&) {} +void Service::CreateDirIfNotExist(const std::string&) {} } namespace OHOS::FileManagement::Backup { -- Gitee