From c66d2ace27bfe745f6e85c630211d9a750f9147a Mon Sep 17 00:00:00 2001
From: Leon Styhre <leon@leonstyhre.com>
Date: Sat, 21 May 2022 14:25:44 +0200
Subject: [PATCH] Fixed a very rare bug where games and folders could get mixed
 up during gamelist.xml parsing.

---
 es-app/src/GamelistFileParser.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/es-app/src/GamelistFileParser.cpp b/es-app/src/GamelistFileParser.cpp
index 632f3d2b8..5a1b6ae51 100644
--- a/es-app/src/GamelistFileParser.cpp
+++ b/es-app/src/GamelistFileParser.cpp
@@ -190,6 +190,15 @@ namespace GamelistFileParser
                 }
 
                 FileData* file = findOrCreateFile(system, path, type);
+
+                // Don't load entries with the wrong type. This should very rarely (if ever) happen.
+                if (file != nullptr && ((tag == "game" && file->getType() == FOLDER) ||
+                                        (tag == "folder" && file->getType() == GAME))) {
+                    LOG(LogWarning)
+                        << "Game/folder mismatch for \"" << path << "\", skipping entry";
+                    continue;
+                }
+
                 if (!file) {
                     LOG(LogError) << "Couldn't find or create \"" << path << "\", skipping entry";
                     continue;