diff --git a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp index ec45fb13a..4c6d08264 100644 --- a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp +++ b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp @@ -488,22 +488,20 @@ bool Snapshot::checkIntegrityRecursively() { bool Snapshot::checkIntegrityRecursively(const NodeId &parentId) { // Check that we do not have the same file twice in the same folder - const auto &parrentItem = _items[parentId]; - for (auto child = parrentItem.childrenIds().begin(), end = parrentItem.childrenIds().end(); child != end; child++) { - if (!checkIntegrityRecursively(*child)) { + const auto &parentItem = _items[parentId]; + std::set names; + for (auto childId = parentItem.childrenIds().begin(), end = parentItem.childrenIds().end(); childId != end; childId++) { + if (!checkIntegrityRecursively(*childId)) { return false; } - for (auto child2 = child; child2 != end; ++child2) { - if (*child != *child2 && _items[*child].name() == _items[*child2].name()) { - LOG_ERROR(Log::instance()->getLogger(), "Snapshot integrity check failed, the folder named: \"" - << SyncName2Str(parrentItem.name()).c_str() << "\"(" - << parrentItem.id().c_str() << ") contains: \"" - << SyncName2Str(_items[*child].name()).c_str() - << "\" twice with two differents NodeId (" << child->c_str() - << " and " << child2->c_str() << ")"); - return false; - } + auto result = names.insert(_items[*childId].name()); + if (!result.second) { + LOG_ERROR(Log::instance()->getLogger(), + "Snapshot integrity check failed, the folder named: \"" + << SyncName2Str(parentItem.name()).c_str() << "\"(" << parentItem.id().c_str() << ") contains: \"" + << SyncName2Str(_items[*childId].name()).c_str() << "\" twice with two differents NodeId"); + return false; } } return true;