From 608545118ac835a92592d9c0cc1ee707b1033293 Mon Sep 17 00:00:00 2001
From: Aloshi <aloshi@aloshi>
Date: Sat, 13 Apr 2013 17:30:57 -0500
Subject: [PATCH] Hopefully fixed infinite recursion.

---
 changelog.txt      |  6 ++++++
 src/SystemData.cpp | 18 +++---------------
 src/SystemData.h   |  1 -
 3 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/changelog.txt b/changelog.txt
index 060f76b1f..d078ec685 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,3 +1,9 @@
+April 13, 2013
+-Finally merged the unstable branch, which means better input everything!
+-Can now use multiple joysticks.
+-Can now remap keyboard input.
+-Hopefully prevented infinitely recursing symlinks.
+
 March 28, 2013
 -Hopefully fixed bad joystick events at startup.
 
diff --git a/src/SystemData.cpp b/src/SystemData.cpp
index 1c1ac232d..ef63adc4a 100644
--- a/src/SystemData.cpp
+++ b/src/SystemData.cpp
@@ -88,20 +88,6 @@ void SystemData::launchGame(Window* window, GameData* game)
 	window->init();
 }
 
-bool SystemData::containsFolder(FolderData* root, const std::string& path)
-{
-	for(int i = 0; i < root->getFileCount(); i++)
-	{
-		FileData* f = root->getFile(i);
-		if(f->isFolder())
-		{
-			if(f->getPath() == path || containsFolder((FolderData*)f, path))
-				return true;
-		}
-	}
-	return false;
-}
-
 void SystemData::populateFolder(FolderData* folder)
 {
 	std::string folderPath = folder->getPath();
@@ -114,8 +100,10 @@ void SystemData::populateFolder(FolderData* folder)
 	//make sure that this isn't a symlink to a thing we already have
 	if(fs::is_symlink(folderPath))
 	{
-		if(containsFolder(mRootFolder, folderPath))
+		//if this symlink resolves to somewhere that's at the beginning of our path, it's gonna recurse
+		if(folderPath.find(fs::canonical(folderPath).string()) == 0)
 		{
+			LOG(LogWarning) << "Skipping infinitely recursive symlink \"" << folderPath << "\"";
 			return;
 		}
 	}
diff --git a/src/SystemData.h b/src/SystemData.h
index 17fdfd3f5..e3c6755d2 100644
--- a/src/SystemData.h
+++ b/src/SystemData.h
@@ -38,7 +38,6 @@ private:
 	std::string mLaunchCommand;
 
 	void populateFolder(FolderData* folder);
-	bool containsFolder(FolderData* folder, const std::string& path);
 
 	FolderData* mRootFolder;
 };