From b1fa058d1dc3f167bcbe73c0ce244d712287cf38 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 12 Oct 2023 19:29:06 -0400 Subject: [PATCH] sagasu: Don't add duplicate folder nodes --- sagasu/src/filetreemodel.cpp | 24 +++++++++++++++--------- sagasu/src/hashdatabase.cpp | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/sagasu/src/filetreemodel.cpp b/sagasu/src/filetreemodel.cpp index 3a9f33c..cc87633 100644 --- a/sagasu/src/filetreemodel.cpp +++ b/sagasu/src/filetreemodel.cpp @@ -144,15 +144,21 @@ void FileTreeModel::addKnownFolder(QString string) conct += QStringLiteral("/") + children[i]; } std::string conctStd = conct.toStdString(); - auto folderItem = new TreeInformation(); - folderItem->name = children[i]; - folderItem->type = TreeType::Folder; - folderItem->parent = parentItem; - folderItem->row = i + 1; - folderItem->hash = physis_generate_partial_hash(conctStd.c_str()); - parentItem->children.push_back(folderItem); - parentItem = folderItem; - knownDirHashes[folderItem->hash] = folderItem; + auto hash = physis_generate_partial_hash(conctStd.c_str()); + + if (knownDirHashes.contains(hash)) { + parentItem = knownDirHashes[hash]; + } else { + auto folderItem = new TreeInformation(); + folderItem->name = children[i]; + folderItem->type = TreeType::Folder; + folderItem->parent = parentItem; + folderItem->row = i + 1; + folderItem->hash = hash; + parentItem->children.push_back(folderItem); + parentItem = folderItem; + knownDirHashes[folderItem->hash] = folderItem; + } } } diff --git a/sagasu/src/hashdatabase.cpp b/sagasu/src/hashdatabase.cpp index 88c59a0..387cf0c 100644 --- a/sagasu/src/hashdatabase.cpp +++ b/sagasu/src/hashdatabase.cpp @@ -42,7 +42,7 @@ void HashDatabase::addFile(QString file) filename = file.sliced(lastSlash + 1, file.length() - lastSlash - 1); } - qInfo() << filename; + qInfo() << "Adding" << filename; std::string folderStd = filename.toStdString();