diff --git a/frameworks/native/distributed_file_inner/src/copy/file_copy_manager.cpp b/frameworks/native/distributed_file_inner/src/copy/file_copy_manager.cpp index e040a2476862a90d2c04ee6b306ec43c1c8feb89..b848719b4f4130778b7e6fc6dda53112867e60cd 100644 --- a/frameworks/native/distributed_file_inner/src/copy/file_copy_manager.cpp +++ b/frameworks/native/distributed_file_inner/src/copy/file_copy_manager.cpp @@ -212,6 +212,9 @@ int32_t FileCopyManager::Copy(const std::string &srcUri, const std::string &dest auto infos = std::make_shared(); auto ret = CreateFileInfos(srcUri, destUri, infos); if (ret != E_OK) { + if (processCallback == nullptr) { + return EINVAL; + } return ret; } diff --git a/test/unittests/distributed_file_inner/copy/file_copy_manager_test.cpp b/test/unittests/distributed_file_inner/copy/file_copy_manager_test.cpp index 6ef2504756043807457508c2da7599d4a71b256f..3332c6d897d93bc45b867a3d654ec6edb09e3efc 100644 --- a/test/unittests/distributed_file_inner/copy/file_copy_manager_test.cpp +++ b/test/unittests/distributed_file_inner/copy/file_copy_manager_test.cpp @@ -94,7 +94,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Copy_0001, TestSize.Level0) EXPECT_EQ(ret, EINVAL); ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(localUri, dstUri, listener_); - EXPECT_EQ(ret, ENOENT); + EXPECT_EQ(ret, EINVAL); string remoteUri = "/data/test/Copy/?networkid=/"; if (!ForceCreateDirectory(remoteUri)) { @@ -329,6 +329,28 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Copy_0009, TestSize.Level0) GTEST_LOG_(INFO) << "FileCopyManager_Copy_0009 End"; } +/** +* @tc.name: FileCopyManager_Copy_0010 +* @tc.desc: The execution of the Copy failed. +* @tc.type: FUNC +* @tc.require: I7TDJK + */ +HWTEST_F(FileCopyManagerTest, FileCopyManager_Copy_0010, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "FileCopyManager_Copy_0010 Start"; + string localUri = "/data/test/test.txt"; + string dstUri = "/data/test/test.txt"; + + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy("", localUri, emptyCallback_); + EXPECT_EQ(ret, EINVAL); + + ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(localUri, "", listener_); + EXPECT_EQ(ret, EINVAL); + + GTEST_LOG_(INFO) << "FileCopyManager_Copy_0010 End"; +} + + /** * @tc.name: FileCopyManager_DeleteResFile_0001 * @tc.desc: Verify the DeleteResFile function when transListener is not null and destPath exists.