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 3d9545568c026cb68a501eba539393658b73e4a0..9d2967e34676fef1859cd4223ea8b993dea57d50 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 76c86cc16dec5d77f58a0fb24be2330926d461f6..13623fb2e67be5fee58447bac00e2253652f9ca4 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 655fe644aa1891991644c85dde2225236652e8f0..e7e2f72850ec89a7e184e1218b15ff03a78b9d74 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 8bf0b017ab9a40da677bd3a1cd3c651790bf754b..6848656f7f104002eb3fc982ebe0ccbdb5bbcd17 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 5b66c8cd8b1ccf0b5a0b039a404b6a0ec237862c..5bbbe67a01d5701114ee2d8bf57376ad5dc15aad 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 ec2f9db67406f21406e24c26ec08faa322b22213..d6e144219a2e3d36c25f52a7f0df175efd52de69 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