From 08fe335a801b0a37bfdfe3f39b1e50be8b624e39 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sun, 28 Aug 2022 21:58:57 +0800 Subject: [PATCH] check name conflicts when loading nodes --- .../notebookconfigmgr/vxnotebookconfigmgr.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp b/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp index c94f1687..ac1f86da 100644 --- a/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp +++ b/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -170,6 +171,8 @@ QSharedPointer VXNotebookConfigMgr::nodeConfigToNode(const NodeConfig &p_c void VXNotebookConfigMgr::loadFolderNode(Node *p_node, const NodeConfig &p_config) { + QSet seenNames; + QVector> children; children.reserve(p_config.m_files.size() + p_config.m_folders.size()); const auto basePath = p_node->fetchPath(); @@ -183,6 +186,12 @@ void VXNotebookConfigMgr::loadFolderNode(Node *p_node, const NodeConfig &p_confi continue; } + if (seenNames.contains(folder.m_name)) { + qWarning() << "skipped loading node with duplicated name under" << p_node->fetchPath(); + continue; + } + seenNames.insert(folder.m_name); + auto folderNode = QSharedPointer::create(folder.m_name, getNotebook(), p_node); @@ -198,6 +207,12 @@ void VXNotebookConfigMgr::loadFolderNode(Node *p_node, const NodeConfig &p_confi continue; } + if (seenNames.contains(file.m_name)) { + qWarning() << "skipped loading node with duplicated name under" << p_node->fetchPath(); + continue; + } + seenNames.insert(file.m_name); + // For compability only. needUpdateConfig = needUpdateConfig || file.m_signature == Node::InvalidId;