Browse Source

Linux fixes

Panagiotis Christopoulos Charitos 3 weeks ago
parent
commit
fe9a9a5100
3 changed files with 14 additions and 11 deletions
  1. 1 1
      AnKi/Resource/ResourceFilesystem.cpp
  2. 2 2
      AnKi/Util/Filesystem.h
  3. 11 8
      AnKi/Util/FilesystemPosix.cpp

+ 1 - 1
AnKi/Resource/ResourceFilesystem.cpp

@@ -430,7 +430,7 @@ Error ResourceFilesystem::addNewPath(CString filepath, const ResourceStringList&
 		ANKI_RESOURCE_LOGI("Added new data path \"%s\" that contains %u files", &filepath[0], fileCount);
 	}
 
-	if(false)
+	if(false && m_paths.getSize())
 	{
 		for(const File& s : m_paths.getFront().m_files)
 		{

+ 2 - 2
AnKi/Util/Filesystem.h

@@ -34,8 +34,8 @@ class WalkDirectoryArgs
 {
 public:
 	CString m_path;
-	Bool m_isDirectory;
-	Bool m_stopSearch;
+	Bool m_isDirectory = false;
+	Bool m_stopSearch = false;
 };
 
 /// @internal

+ 11 - 8
AnKi/Util/FilesystemPosix.cpp

@@ -66,8 +66,7 @@ class WalkDirectoryTreeCallbackContext
 public:
 	const Function<Error(WalkDirectoryArgs&)>* m_callback = nullptr;
 	U32 m_prefixLen;
-	Error m_err = {Error::kNone};
-	Bool m_stopSearch = false;
+	Error m_error = Error::kNone;
 };
 
 static thread_local WalkDirectoryTreeCallbackContext g_walkDirectoryTreeContext;
@@ -93,7 +92,7 @@ static int walkDirectoryTreeCallback(const char* filepath, [[maybe_unused]] cons
 		WalkDirectoryTreeCallbackContext& ctx = g_walkDirectoryTreeContext;
 		ANKI_ASSERT(ctx.m_callback);
 
-		if(ctx.m_err || ctx.m_stopSearch || strlen(filepath) <= ctx.m_prefixLen)
+		if(strlen(filepath) <= ctx.m_prefixLen)
 		{
 			return 0;
 		}
@@ -101,8 +100,12 @@ static int walkDirectoryTreeCallback(const char* filepath, [[maybe_unused]] cons
 		WalkDirectoryArgs args;
 		args.m_path = filepath + ctx.m_prefixLen;
 		args.m_isDirectory = isDir;
-		ctx.m_err = (*ctx.m_callback)(args);
-		ctx.m_stopSearch = args.m_stopSearch;
+		ctx.m_error = (*ctx.m_callback)(args);
+
+		if(ctx.m_error || args.m_stopSearch)
+		{
+			return 666;
+		}
 	}
 
 	return 0;
@@ -123,17 +126,17 @@ Error walkDirectoryTreeInternal(CString dir, const Function<Error(WalkDirectoryA
 	WalkDirectoryTreeCallbackContext& ctx = g_walkDirectoryTreeContext;
 	ctx.m_callback = &callback;
 	ctx.m_prefixLen = prefixLen;
-	ctx.m_err = Error::kNone;
+	ctx.m_error = Error::kNone;
 
 	const int result = nftw(dir.cstr(), walkDirectoryTreeCallback, USE_FDS, FTW_PHYS);
-	if(result != 0)
+	if(result != 0 && result != 666)
 	{
 		ANKI_UTIL_LOGE("nftw() failed");
 		err = Error::kFunctionFailed;
 	}
 	else
 	{
-		err = ctx.m_err;
+		err = ctx.m_error;
 	}
 
 	return err;