Game Development Community

Platform::isSubDirectory problem on linux

by James Urquhart · in Torque Game Engine · 11/13/2004 (4:00 am) · 5 replies

There seems to be a problem with the Platform::isSubDirectory function in X86UNIXFileio.cc.
The following block of code is incorrect :
if (stat(dirBuf, &fStat) < 0)
         return false;

If "stat" fails, it will take the whole directory walker loop with it.
Since stat is called for each file found in the directory, one error in a file entry (such as incorrect access rights, too many symbolic links, etc) will result in the code not being able to find all the entries in a directory.
Since this function is used in ResManager in setModPaths to determine if a mod is really in a .zip, a mod could fail to load, This happened in my case, as a broken symbolic link was put through stat() before the common folder, so torque thought it was a .zip, and so common failed to load.

To solve this problem, one only need to do "continue;" instead of "return false;", aka :
if (stat(dirBuf, &fStat) < 0)
         continue;

How to reproduce
Create a symbolic link in your torque directory (where your engine executable is located) that points to a non-existent file, e.g. :

ln -s /non/existant/file myfile.txt

You will need to ensure somehow that your file appears before one of your mod folders in the directory's list to encounter the bug.

#1
11/13/2004 (7:05 pm)
Thanks for the information heres what i applied to my local branch :)

--- platformX86UNIX/x86UNIXFileio.cc    2004-11-13 23:41:03.397330064 -0500
+++ platformLinux/x86UNIXFileio.cc      2004-11-13 23:37:43.133774752 -0500
@@ -941,7 +941,11 @@

       dSprintf(dirBuf, sizeof(dirBuf), "%s/%s", pParent, fEntry->d_name);
       if (stat(dirBuf, &fStat) < 0)
+#if defined(TORQUE_OS_LINUX)
+         continue;
+#else
          return false;
+#endif
#2
11/13/2004 (7:21 pm)
@Benoit: Why did you add the define check if it's in UNIX platform code?
#3
11/13/2004 (7:24 pm)
Good eye, James. This is on my todo list.
#4
11/13/2004 (8:27 pm)
LOL guess i was thinking to clearly :)
#5
08/09/2005 (2:26 am)
Ok, in 1.4 trunk.