diff --git a/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp b/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp index 4f978544441b628dcde07f9c06099b33694942b9..b96197d4326a4139d784e9eedd97d5345ffbf6dc 100644 --- a/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp +++ b/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp @@ -488,6 +488,15 @@ static void GetMetaAttr(struct FuseData *data, shared_ptr ino, struc } } +static void CheckAndReport(const string &path, const string &childName, bool create) +{ + if (!create && path != childName) { + CLOUD_FILE_FAULT_REPORT(CloudFileFaultInfo{PHOTOS_BUNDLE_NAME, FaultOperation::LOOKUP, + FaultType::INODE_FILE, ENOMEM, "hash collision: childName:" + GetAnonyString(childName) + + ",path:" + GetAnonyString(path)}); + } +} + static int CloudDoLookupHelper(fuse_ino_t parent, const char *name, struct fuse_entry_param *e, FuseData *data, string& parentName) { @@ -530,10 +539,7 @@ static int CloudDoLookupHelper(fuse_ino_t parent, const char *name, struct fuse_ LOGW("invalidate %s", GetAnonyString(childName).c_str()); child->mBase = make_shared(mBase); } - if (child->path != childName) { - CLOUD_FILE_FAULT_REPORT(CloudFileFaultInfo{PHOTOS_BUNDLE_NAME, FaultOperation::LOOKUP, - FaultType::INODE_FILE, ENOMEM, "hash collision"}); - } + CheckAndReport(child->path, childName, create); child->path = childName; child->parent = parent; LOGD("lookup success, child: %{private}s, refCount: %lld", GetAnonyString(child->path).c_str(), diff --git a/test/unittests/services_daemon/fuse_manager_static_test.cpp b/test/unittests/services_daemon/fuse_manager_static_test.cpp index a7c718843e57b918e4bd34f54e6211f8fc0250a3..28f0f097633a6a06e7c36ca2fbe53943d467e98c 100644 --- a/test/unittests/services_daemon/fuse_manager_static_test.cpp +++ b/test/unittests/services_daemon/fuse_manager_static_test.cpp @@ -64,6 +64,26 @@ void FuseManagerStaticTest::TearDown(void) GTEST_LOG_(INFO) << "TearDown"; } +/** + * @tc.name: CheckAndReport001 + * @tc.desc: Verify the IsHdc function + * @tc.type: FUNC + */ +HWTEST_F(FuseManagerStaticTest, CheckAndReport001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckAndReport001 Begin"; + try { + string path = "/mnt/data/100/cloud_fuse/1"; + string childName = "/mnt/data/100/cloud_fuse/2"; + bool create = false; + CheckAndReport(path, childName, create); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckAndReport001 Error"; + } + GTEST_LOG_(INFO) << "CheckAndReport001 End"; +} + /** * @tc.name: IsValidCachePathTest001 * @tc.desc: Verify the IsValidCachePath function