From a01adcb5a8142610a6fa6d963bf2742756acced2 Mon Sep 17 00:00:00 2001 From: huaqingsimeng <1004904143@qq.com> Date: Tue, 11 Jul 2023 17:00:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=B8=BA=E5=8D=87=E7=BA=A7=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=8F=90=E4=BE=9Bbackup=5Fkit=5Finner=E8=83=BD?= =?UTF-8?q?=E5=8A=9B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huaqingsimeng --- bundle.json | 1 + .../src/b_session_restore_async.cpp | 175 ++++++++++++++++++ .../backup_kit_inner/src/service_proxy.cpp | 2 +- .../native/backup_kit_inner/BUILD.gn | 1 + .../backup_kit_inner/backup_kit_inner.h | 1 + .../impl/b_session_restore_async.h | 131 +++++++++++++ .../native/backup_kit_inner/impl/i_service.h | 13 +- .../backup_kit_inner/impl/service_proxy.h | 2 +- .../backup_sa/include/module_ipc/service.h | 2 +- services/backup_sa/src/module_ipc/service.cpp | 2 +- .../backup_sa/src/module_ipc/service_stub.cpp | 2 +- .../backup_kit_inner/service_proxy_mock.cpp | 2 +- tests/mock/module_ipc/service_mock.cpp | 2 +- .../backup_impl/include/i_service_mock.h | 2 +- .../module_ipc/service_stub_test.cpp | 2 +- 15 files changed, 324 insertions(+), 16 deletions(-) create mode 100644 frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp create mode 100644 interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h diff --git a/bundle.json b/bundle.json index 5186429d4..cd037d76e 100644 --- a/bundle.json +++ b/bundle.json @@ -90,6 +90,7 @@ "header_files": [ "backup_kit_inner.h", "impl/b_session_restore.h", + "impl/b_session_restore_async.h", "impl/b_file_info.h", "impl/service_proxy.h", "impl/b_session_backup.h", diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp new file mode 100644 index 000000000..38e8e1673 --- /dev/null +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "b_session_restore_async.h" + +#include "b_error/b_error.h" +#include "b_resources/b_constants.h" +#include "b_session_restore.h" +#include "filemgmt_libhilog.h" +#include "service_proxy.h" +#include "service_reverse.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +BSessionRestoreAsync::~BSessionRestoreAsync() +{ + if (!deathRecipient_) { + HILOGI("Death Recipient is nullptr"); + return; + } + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + return; + } + auto remoteObject = proxy->AsObject(); + if (remoteObject != nullptr) { + remoteObject->RemoveDeathRecipient(deathRecipient_); + } + callbacks_ = {}; + deathRecipient_ = nullptr; +} + +shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) +{ + try { + auto restore = make_shared(callbacks); + return restore; + } catch (const exception &e) { + HILOGE("Failed to Restore because of %{public}s", e.what()); + } + return nullptr; +} + +ErrCode BSessionRestoreAsync::PublishFile(BFileInfo fileInfo) +{ + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + return proxy->PublishFile(fileInfo); +} + +ErrCode BSessionRestoreAsync::GetFileHandle(const string &bundleName, const string &fileName) +{ + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + + return proxy->GetFileHandle(bundleName, fileName); +} + +ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, + vector bundlesToRestore, + RestoreTypeEnum restoreType, + int32_t userId) +{ + { + std::unique_lock lock(mutex_); + workList_.push({move(remoteCap), move(bundlesToRestore), restoreType, userId}); + } + + if (isAppend_.exchange(true)) { + return ERR_OK; + } else { + PopBundleInfo(); + } + + return ERR_OK; +} + +void BSessionRestoreAsync::RegisterBackupServiceDied(std::function functor) +{ + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr || !functor) { + return; + } + auto remoteObj = proxy->AsObject(); + if (!remoteObj) { + throw BError(BError::Codes::SA_BROKEN_IPC, "Proxy's remote object can't be nullptr"); + } + + auto callback = [functor](const wptr &obj) { functor(); }; + deathRecipient_ = sptr(new SvcDeathRecipient(callback)); + remoteObj->AddDeathRecipient(deathRecipient_); +} + +void BSessionRestoreAsync::OnBackupServiceDied() +{ + HILOGE("Backup service died"); + if (callbacks_.onBackupServiceDied) { + callbacks_.onBackupServiceDied(); + } + deathRecipient_ = nullptr; + ServiceProxy::InvaildInstance(); + PopBundleInfo(); +} + +void BSessionRestoreAsync::PopBundleInfo() +{ + AppendBundleInfo info; + isAppend_.store(true); + { + std::unique_lock lock(mutex_); + if (workList_.empty()) { + isAppend_.store(false); + return; + } + info = move(workList_.front()); + workList_.pop(); + } + AppendBundlesImpl(move(info)); +} + +void BSessionRestoreAsync::AppendBundlesImpl(AppendBundleInfo info) +{ + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + auto onBackupServiceDied = bind(&BSessionRestoreAsync::OnBackupServiceDied, shared_from_this()); + RegisterBackupServiceDied(onBackupServiceDied); + + BSessionRestore::Callbacks callbacksTmp {.onFileReady = callbacks_.onFileReady, + .onBundleStarted = callbacks_.onBundleStarted, + .onBundleFinished = callbacks_.onBundleFinished, + .onAllBundlesFinished = callbacks_.onAllBundlesFinished, + .onBackupServiceDied = onBackupServiceDied}; + int32_t res = proxy->InitRestoreSession(new ServiceReverse(callbacksTmp)); + if (res != 0) { + HILOGE("Failed to Restore because of %{public}d", res); + BError(BError::Codes::SDK_BROKEN_IPC, "Failed to int restore session").GetCode(); + return OnBundleStarted(res, info.bundlesToRestore); + } + res = + proxy->AppendBundlesRestoreSession(move(info.remoteCap), info.bundlesToRestore, info.restoreType, info.userId); + if (res != 0) { + HILOGE("Failed to Restore because of %{public}d", res); + BError(BError::Codes::SDK_BROKEN_IPC, "Failed to append bundles").GetCode(); + return OnBundleStarted(res, info.bundlesToRestore); + } +} + +void BSessionRestoreAsync::OnBundleStarted(ErrCode errCode, const vector &bundlesToRestore) +{ + for (auto &bundleName : bundlesToRestore) { + if (callbacks_.onBundleStarted) { + callbacks_.onBundleStarted(errCode, bundleName); + } + } +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index 1f86dce5a..52eda3732 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -227,7 +227,7 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - RestoreTpyeEnum restoreType, + RestoreTypeEnum restoreType, int32_t userId) { HILOGI("Begin"); diff --git a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn index b1b64c573..3abaf9b92 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -35,6 +35,7 @@ ohos_shared_library("backup_kit_inner") { "${path_backup}/frameworks/native/backup_kit_inner/src/b_file_info.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_backup.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_proxy.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", diff --git a/interfaces/inner_api/native/backup_kit_inner/backup_kit_inner.h b/interfaces/inner_api/native/backup_kit_inner/backup_kit_inner.h index b00355627..7277da994 100644 --- a/interfaces/inner_api/native/backup_kit_inner/backup_kit_inner.h +++ b/interfaces/inner_api/native/backup_kit_inner/backup_kit_inner.h @@ -18,5 +18,6 @@ #include "impl/b_session_backup.h" #include "impl/b_session_restore.h" +#include "impl/b_session_restore_async.h" #endif // OHOS_FILEMGMT_BACKUP_BACKUP_KIT_INNER_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h new file mode 100644 index 000000000..0d547909e --- /dev/null +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_B_SESSION_RESTORE_ASYNC_H +#define OHOS_FILEMGMT_BACKUP_B_SESSION_RESTORE_ASYNC_H + +#include +#include +#include +#include +#include + +#include "b_file_info.h" +#include "errors.h" +#include "i_service.h" +#include "svc_death_recipient.h" +#include "unique_fd.h" + +namespace OHOS::FileManagement::Backup { +class BSessionRestoreAsync : public std::enable_shared_from_this { +public: + struct Callbacks { + std::function onFileReady; // 当备份服务有文件待发送时执行的回调 + std::function onBundleStarted; // 当启动某个应用的恢复流程结束时执行的回调函数 + std::function + onBundleFinished; // 当某个应用的恢复流程结束或意外中止时执行的回调函数 + std::function onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数 + std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 + }; + + struct AppendBundleInfo { + UniqueFd remoteCap; // 已打开的保存远端设备能力的Json文件 + std::vector bundlesToRestore; // 需要恢复的应用名称列表 + RestoreTypeEnum restoreType; // 待恢复类型(例如升级服务数据迁移就绪无需进行数据传输) + int32_t userId; // 用户ID + }; + +public: + /** + * @brief 获取一个用于控制恢复流程的会话 + * + * @param callbacks 注册的回调函数 + * @return std::unique_ptr 指向BRestoreSession的智能指针。失败时为空指针 + */ + static std::shared_ptr Init(Callbacks callbacks); + + /** + * @brief 通知备份服务文件内容已就绪 + * + * @param fileInfo 文件描述信息 + * @return ErrCode 规范错误码 + * @see GetFileHandle + */ + ErrCode PublishFile(BFileInfo fileInfo); + + /** + * @brief 请求恢复流程所需的真实文件 + * + * @param bundleName 应用名称 + * @param fileName 文件名称 + */ + ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName); + + /** + * @brief 用于追加待恢复应用 + * + * @param remoteCap 已打开的保存远端设备能力的Json文件。可使用GetLocalCapabilities方法获取 + * @param bundlesToRestore 待恢复的应用清单 + * @param userId 用户ID + * @return ErrCode 规范错误码 + */ + ErrCode AppendBundles(UniqueFd remoteCap, + std::vector bundlesToRestore, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE); + +public: + explicit BSessionRestoreAsync(Callbacks callbacks) : callbacks_(callbacks) {}; + ~BSessionRestoreAsync(); + +private: + /** @brief 注册备份服务意外死亡时执行的回调函数 */ + void OnBackupServiceDied(); + + /** @brief 从暂存队列中取出一次待恢复应用请求 */ + void PopBundleInfo(); + + /** + * @brief 执行待恢复应用请求 + * + * @param info 待恢复应用请求信息 + */ + void AppendBundlesImpl(AppendBundleInfo info); + + /** + * @brief IPC请求异常时通知回调 + * + * @param errCode + * @param bundlesToRestore + */ + void OnBundleStarted(ErrCode errCode, const std::vector &bundlesToRestore); + + /** + * @brief 注册备份服务意外死亡时执行的回调函数 + * + * @param functor 回调函数 + */ + void RegisterBackupServiceDied(std::function functor); + +private: + sptr deathRecipient_; + Callbacks callbacks_; + std::atomic isAppend_ {false}; + std::mutex mutex_; + std::queue workList_; +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_B_SESSION_RESTORE_ASYNC_H \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h index 7f6992e30..e8bb2202a 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h @@ -29,10 +29,10 @@ namespace OHOS::FileManagement::Backup { const int DEFAULT_INVAL_VALUE = -1; -typedef enum TypeRestoreTpyeEnum { +typedef enum TypeRestoreTypeEnum { RESTORE_DATA_WAIT_SEND = 0, RESTORE_DATA_READDY = 1, -} RestoreTpyeEnum; +} RestoreTypeEnum; class IService : public IRemoteBroker { public: @@ -44,11 +44,10 @@ public: virtual ErrCode AppFileReady(const std::string &fileName, UniqueFd fd) = 0; virtual ErrCode AppDone(ErrCode errCode) = 0; virtual ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) = 0; - virtual ErrCode AppendBundlesRestoreSession( - UniqueFd fd, - const std::vector &bundleNames, - RestoreTpyeEnum restoreType = RestoreTpyeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE) = 0; + virtual ErrCode AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE) = 0; virtual ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) = 0; virtual ErrCode Finish() = 0; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h index 262ded55f..5273921a2 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h @@ -38,7 +38,7 @@ public: ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - RestoreTpyeEnum restoreType = RestoreTpyeEnum::RESTORE_DATA_WAIT_SEND, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, int32_t userId = DEFAULT_INVAL_VALUE) override; ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; ErrCode Finish() override; diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 5665a71a0..9f0db0a21 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -42,7 +42,7 @@ public: ErrCode GetFileHandle(const std::string &bundleName, const std::string &fileName) override; ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - RestoreTpyeEnum restoreType = RestoreTpyeEnum::RESTORE_DATA_WAIT_SEND, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, int32_t userId = DEFAULT_INVAL_VALUE) override; ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; ErrCode Finish() override; diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 9d1097f7f..72b9739bb 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -204,7 +204,7 @@ ErrCode Service::Start() ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - RestoreTpyeEnum restoreType, + RestoreTypeEnum restoreType, int32_t userId) { HILOGI("Begin"); diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp index a2004596d..eb0f9470d 100644 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ b/services/backup_sa/src/module_ipc/service_stub.cpp @@ -220,7 +220,7 @@ int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, Message if (!data.ReadInt32(type)) { return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreType"); } - RestoreTpyeEnum restoreType = static_cast(type); + RestoreTypeEnum restoreType = static_cast(type); int32_t userId; if (!data.ReadInt32(userId)) { return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive userId"); diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index 35e854405..cd0808e1a 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -82,7 +82,7 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - RestoreTpyeEnum restoreType, + RestoreTypeEnum restoreType, int32_t userId) { return BError(BError::Codes::OK); diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 9ded32d95..a4e6dc931 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -74,7 +74,7 @@ ErrCode Service::AppDone(ErrCode errCode) ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - RestoreTpyeEnum restoreType, + RestoreTypeEnum restoreType, int32_t userId) { return BError(BError::Codes::OK); diff --git a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h index ad74dccd4..2af0cb1e1 100644 --- a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h @@ -95,7 +95,7 @@ public: ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - RestoreTpyeEnum restoreType, + RestoreTypeEnum restoreType, int32_t userId) override { return BError(BError::Codes::OK); diff --git a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp index 73043ce9a..8b06ed40c 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -50,7 +50,7 @@ public: MOCK_METHOD2(GetFileHandle, ErrCode(const string &bundleName, const string &fileName)); MOCK_METHOD4( AppendBundlesRestoreSession, - ErrCode(UniqueFd fd, const std::vector &bundleNames, RestoreTpyeEnum restoreType, int32_t userId)); + ErrCode(UniqueFd fd, const std::vector &bundleNames, RestoreTypeEnum restoreType, int32_t userId)); MOCK_METHOD1(AppendBundlesBackupSession, ErrCode(const std::vector &bundleNames)); MOCK_METHOD0(Finish, ErrCode()); UniqueFd InvokeGetLocalCapabilities() -- Gitee From 860957b3e80335ca03ba06ad757426dd3363a828 Mon Sep 17 00:00:00 2001 From: huaqingsimeng <1004904143@qq.com> Date: Mon, 17 Jul 2023 16:12:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BD=93=E6=89=93=E5=8C=85=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=97=B6=EF=BC=8C=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=B8=80=E4=B8=AA=E7=A9=BA=E5=8C=85=20=E5=BD=93?= =?UTF-8?q?=E6=89=93=E5=8C=85=E8=B7=AF=E5=BE=84=E7=9A=84json=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=A0=87=E7=AD=BE=E5=BC=82=E5=B8=B8=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=B8=80=E4=B8=AA=E7=A9=BA=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huaqingsimeng --- utils/src/b_tarball/b_tarball_cmdline.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/utils/src/b_tarball/b_tarball_cmdline.cpp b/utils/src/b_tarball/b_tarball_cmdline.cpp index 1dbb1bf8e..0b8146f06 100644 --- a/utils/src/b_tarball/b_tarball_cmdline.cpp +++ b/utils/src/b_tarball/b_tarball_cmdline.cpp @@ -23,6 +23,7 @@ #include "b_filesystem/b_dir.h" #include "b_process/b_guard_cwd.h" #include "b_process/b_process.h" +#include "filemgmt_libhilog.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -55,6 +56,10 @@ void BTarballCmdline::Tar(string_view root, vector includes, vector } vector includesDirs = BDir::GetDirs(includes); + if (includesDirs.empty()) { + HILOGE("tar includes Dirs argument must be not empty"); + includesDirs.push_back(""); + } for (auto &&include : includesDirs) { argv.push_back(include); } -- Gitee