Ver código fonte

Fixes the recursive directory dump in the Linux platform code so that module/asset parsing works as expected.

Areloch 9 anos atrás
pai
commit
e48ee1a03a
1 arquivos alterados com 65 adições e 31 exclusões
  1. 65 31
      Engine/source/platformX86UNIX/x86UNIXFileio.cpp

+ 65 - 31
Engine/source/platformX86UNIX/x86UNIXFileio.cpp

@@ -1151,45 +1151,79 @@ bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite)
    DIR *dip;
    struct dirent *d;
 
-   if (subPath && (dStrncmp(subPath, "", 1) != 0))
-     {
-       if ((basePath[dStrlen(basePath) - 1]) == '/')
- 	dSprintf(Path, 1024, "%s%s", basePath, subPath);
-       else
- 	dSprintf(Path, 1024, "%s/%s", basePath, subPath);
-     }
+   dsize_t trLen = basePath ? dStrlen(basePath) : 0;
+   dsize_t subtrLen = subPath ? dStrlen(subPath) : 0;
+   char trail = trLen > 0 ? basePath[trLen - 1] : '\0';
+   char subTrail = subtrLen > 0 ? subPath[subtrLen - 1] : '\0';
+   char subLead = subtrLen > 0 ? subPath[0] : '\0';
+
+   if (trail == '/')
+   {
+      if (subPath && (dStrncmp(subPath, "", 1) != 0))
+      {
+         if (subTrail == '/')
+            dSprintf(Path, 1024, "%s%s", basePath, subPath);
+         else
+            dSprintf(Path, 1024, "%s%s/", basePath, subPath);
+      }
+      else
+         dSprintf(Path, 1024, "%s", basePath);
+   }
    else
-     dSprintf(Path, 1024, "%s", basePath);
+   {
+      if (subPath && (dStrncmp(subPath, "", 1) != 0))
+      {
+         if (subTrail == '/')
+            dSprintf(Path, 1024, "%s%s", basePath, subPath);
+         else
+            dSprintf(Path, 1024, "%s%s/", basePath, subPath);
+      }
+      else
+         dSprintf(Path, 1024, "%s/", basePath);
+   }
+
    dip = opendir(Path);
    if (dip == NULL)
      return false;
+
    //////////////////////////////////////////////////////////////////////////
    // add path to our return list ( provided it is valid )
    //////////////////////////////////////////////////////////////////////////
    if (!Platform::isExcludedDirectory(subPath))
-     {
-       if (noBasePath)
- 	{
- 	  // We have a path and it's not an empty string or an excluded directory
- 	  if ( (subPath && (dStrncmp (subPath, "", 1) != 0)) )
- 	    directoryVector.push_back(StringTable->insert(subPath));
- 	}
-       else
- 	{
- 	  if ( (subPath && (dStrncmp(subPath, "", 1) != 0)) )
- 	    {
- 	      char szPath[1024];
- 	      dMemset(szPath, 0, 1024);
- 	      if ( (basePath[dStrlen(basePath) - 1]) != '/')
- 		dSprintf(szPath, 1024, "%s%s", basePath, subPath);
- 	      else
- 		dSprintf(szPath, 1024, "%s%s", basePath, &subPath[1]);
- 	      directoryVector.push_back(StringTable->insert(szPath));
- 	    }
- 	  else
- 	    directoryVector.push_back(StringTable->insert(basePath));
- 	}
-     }
+   {
+      if (noBasePath)
+      {
+         // We have a path and it's not an empty string or an excluded directory
+         if ( (subPath && (dStrncmp (subPath, "", 1) != 0)) )
+            directoryVector.push_back(StringTable->insert(subPath));
+      }
+      else
+      {
+         if ( (subPath && (dStrncmp(subPath, "", 1) != 0)) )
+         {
+            char szPath[1024];
+            dMemset(szPath, 0, 1024);
+            if (trail == '/')
+            {
+               if ((basePath[dStrlen(basePath) - 1]) != '/')
+                  dSprintf(szPath, 1024, "%s%s", basePath, &subPath[1]);
+               else
+                  dSprintf(szPath, 1024, "%s%s", basePath, subPath);
+            }
+            else
+            {
+               if ((basePath[dStrlen(basePath) - 1]) != '/')
+                  dSprintf(szPath, 1024, "%s%s", basePath, subPath);
+               else
+                  dSprintf(szPath, 1024, "%s/%s", basePath, subPath);
+            }
+
+            directoryVector.push_back(StringTable->insert(szPath));
+         }
+         else
+            directoryVector.push_back(StringTable->insert(basePath));
+      }
+   }
    //////////////////////////////////////////////////////////////////////////
    // Iterate through and grab valid directories
    //////////////////////////////////////////////////////////////////////////