From de625be3c9a199bd369d8f9a89842578d84dcb4a Mon Sep 17 00:00:00 2001
From: Dieter Hametner <dh (plus) vdr (at) gekrumbel (dot) de>
Date: Fri, 15 Jun 2007 22:12:03 +0000
Subject: - Use stat to find the directories that are assumed to be themes for 
  live. This fixes #353.

---
 pages/setup.ecpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

(limited to 'pages')

diff --git a/pages/setup.ecpp b/pages/setup.ecpp
index 008bec3..46ccf66 100644
--- a/pages/setup.ecpp
+++ b/pages/setup.ecpp
@@ -1,4 +1,5 @@
 <%pre>
+#include <sys/stat.h>
 #include <vdr/tools.h>
 #include "setup.h"
 #include "tools.h"
@@ -156,7 +157,8 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html");
 						<td class="rightcol"><select name="theme" size="1" id="theme">
 <%cpp>
 {
-	cReadDir d((Plugin::GetConfigDirectory() + "/themes").c_str());
+	const string dirPath(Plugin::GetConfigDirectory() + "/themes");
+	cReadDir d(dirPath.c_str());
 	struct dirent* e;
 	string parent("..");
 	string current(".");
@@ -164,7 +166,13 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html");
 		if ((current == e->d_name) || (parent == e->d_name)) {
 			continue;
 		}
-		if (DT_DIR != e->d_type) {
+		/* Check if entry is a directory: I do not rely on e->d_type
+		   here because on some systems it is allways DT_UNKNOWN. Also
+		   testing for DT_DIR does not take into account symbolic
+		   links to directories.
+		*/
+		struct stat buf;
+		if ((stat((dirPath + "/" + e->d_name).c_str(), &buf) != 0) || (!S_ISDIR(buf.st_mode))) {
 			continue;
 		}
 </%cpp>
-- 
cgit v1.2.3