From e7ffdfd57ab566ac718b7fd9120fd9d6ed5ec207 Mon Sep 17 00:00:00 2001 From: mujie1970 Date: Fri, 5 Sep 2025 16:45:00 +0800 Subject: [PATCH] Fix problems from ai review Signed-off-by: mujie1970 --- .../src/cloud_sync_manager_impl.cpp | 14 +++++- .../download_callback_middle_napi.cpp | 2 +- .../include/cloud_disk/io_message_listener.h | 1 - .../src/cloud_disk/io_message_listener.cpp | 6 ++- .../cloudsync_api/cloudsync_impl/BUILD.gn | 2 +- .../cloud_sync_manager_impl_test.cpp | 44 +++++++++++++++++-- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp index 3d9545568..9d2967e34 100644 --- a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp @@ -814,7 +814,12 @@ static std::string GetThumbsPath(const std::string& path) { const string str = "files/"; size_t len = str.size() - 1; - std::string newPath = "/storage/media/cloud/files/.thumbs" + path.substr(path.find(str) + len); // 待删除的文件路径 + auto found = path.find(str); + if (found == string::npos) { + LOGE("\"files/\" not found in path"); + return ""; + } + std::string newPath = "/storage/media/cloud/files/.thumbs" + path.substr(found + len); // 待删除的文件路径 return newPath; } @@ -822,7 +827,12 @@ static std::string GetMediaPath(const std::string& path) { const string str = "storage/"; size_t len = str.size() - 1; - std::string newPath = "/storage/media" + path.substr(path.find(str) + len); + auto found = path.find(str); + if (found == string::npos) { + LOGE("\"storage/\" not found in path"); + return ""; + } + std::string newPath = "/storage/media" + path.substr(found + len); return newPath; } diff --git a/interfaces/kits/js/cloudfilesync/download_callback_middle_napi.cpp b/interfaces/kits/js/cloudfilesync/download_callback_middle_napi.cpp index 76c86cc16..13623fb2e 100644 --- a/interfaces/kits/js/cloudfilesync/download_callback_middle_napi.cpp +++ b/interfaces/kits/js/cloudfilesync/download_callback_middle_napi.cpp @@ -64,7 +64,7 @@ void CloudDlCallbackMiddleNapi::OnDownloadProcess(const DownloadProgressObj &pro } std::shared_ptr callbackImpl = shared_from_this(); napi_status status = napi_send_event( - callbackImpl->env_, + env_, [fileCacheInfo, callbackImpl]() mutable { if (fileCacheInfo == nullptr || callbackImpl == nullptr) { LOGE("Failed to callback, is callbackImpl null: %{public}d", (callbackImpl == nullptr)); diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index 655fe644a..e7e2f7285 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -53,7 +53,6 @@ private: std::atomic isThreadRunning{false}; std::thread ioThread; std::mutex sleepMutex; - std::mutex cvMute; std::condition_variable sleepCv; std::map bundleTimeMap; IoData currentData; diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 8bf0b017a..6848656f7 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -175,8 +175,10 @@ void IoMessageManager::OnReceiveEvent(const AppExecFwk::AppStateData &appStateDa } if (appStateData.state == TYPE_BACKGROUND) { if (ioThread.joinable()) { - lock_guard lock(cvMute); - isThreadRunning.store(false); + { + lock_guard lock(sleepMutex); + isThreadRunning.store(false); + } sleepCv.notify_all(); ioThread.join(); ioThread = thread(); diff --git a/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn b/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn index 5b66c8cd8..5bbbe67a0 100644 --- a/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn +++ b/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn @@ -79,13 +79,13 @@ ohos_unittest("cloud_sync_manager_impl_test") { module_out_path = "dfs_service/dfs_service" sources = [ - "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp", "${distributedfile_path}/test/mock/system_ability_manager_client_mock.cpp", "cloud_sync_manager_impl_test.cpp", ] include_dirs = [ "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/include", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src", "${distributedfile_path}/interfaces/inner_api/native/cloudsync_kit_inner", "${distributedfile_path}/test/mock", "${distributedfile_path}/test/mock/ipc", diff --git a/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp b/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp index ec2f9db67..d6e144219 100644 --- a/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp +++ b/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp @@ -20,7 +20,7 @@ #include #include -#include "cloud_sync_manager_impl.h" +#include "cloud_sync_manager_impl.cpp" #include "dfs_error.h" #include "icloud_sync_service.h" #include "iservice_registry.h" @@ -36,8 +36,6 @@ namespace fs = std::filesystem; using namespace testing::ext; using namespace testing; using namespace std; -constexpr int32_t MAX_DENTRY_FILE_SIZE = 500; -constexpr int32_t MAX_FILE_CACHE_NUM = 400; class CloudSyncManagerImplTest : public testing::Test { public: @@ -1371,5 +1369,45 @@ HWTEST_F(CloudSyncManagerImplTest, ClearFileConflictTest001, TestSize.Level1) } GTEST_LOG_(INFO) << "ClearFileConflictTest001 End"; } + +/* + * @tc.name: GetThumbsPath + * @tc.desc: Verify the GetThumbsPath function + * @tc.type: FUNC + * @tc.require: ICGORT + */ +HWTEST_F(CloudSyncManagerImplTest, GetThumbsPathTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetThumbsPathTest001 Start"; + try { + string inputPath = "/storage/cloud/100/data"; + auto ret = GetThumbsPath(inputPath); + EXPECT_EQ(ret, ""); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << " GetThumbsPathTest001 FAILED"; + } + GTEST_LOG_(INFO) << "GetThumbsPathTest001 End"; +} + +/* + * @tc.name: GetMediaPath + * @tc.desc: Verify the GetMediaPath function + * @tc.type: FUNC + * @tc.require: ICGORT + */ +HWTEST_F(CloudSyncManagerImplTest, GetMediaPathTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetMediaPathTest001 Start"; + try { + string inputPath = "/data/service/el2/100/hmdfs/account/files"; + auto ret = GetMediaPath(inputPath); + EXPECT_EQ(ret, ""); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << " GetMediaPathTest001 FAILED"; + } + GTEST_LOG_(INFO) << "GetMediaPathTest001 End"; +} } // namespace FileManagement::CloudSync } // namespace OHOS \ No newline at end of file -- Gitee