diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2024-08-20 11:13:07 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-20 09:13:07 -0700 |
| commit | d286ff53c101e471a4a07ee50d277c99d18632b0 (patch) | |
| tree | 0bbb318bffc70d765427ef562763cfa579734e96 | |
| parent | f77a5ac9d1547a4394bba4ab8e94d905972c79b7 (diff) | |
Implement Path::createDirectoryRecursive (#4871)
* Implement Path::createDirectoryRecursive
Implement Path::createDirectoryRecursive with existing Path::createDirectory
that uses system call instead of c++ standard lib.
* Change the use of 'while(1)' to 'for(;;)'
| -rw-r--r-- | source/core/slang-io.cpp | 54 | ||||
| -rw-r--r-- | source/slang/slang-ir-specialize-function-call.cpp | 2 |
2 files changed, 52 insertions, 4 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 54a8fc79e..ffbb5fa98 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -564,9 +564,57 @@ namespace Slang bool Path::createDirectoryRecursive(const String& path) { - std::error_code ec; - std::filesystem::create_directories(path.getBuffer(), ec); - return !ec; + String finalPath = Path::simplify(path); + if (finalPath.getLength() == 0) + { + return false; + } + + List<String> pathList; + + // Check whether the parent directories exist, and add to the pathList if they are + // not, we will create all the directories from back of the list. + String parentDir = finalPath; + for(;;) + { + if (parentDir.getLength() == 0 || File::exists(parentDir)) + { + break; + } + else + { + pathList.add(parentDir); + parentDir = Path::getParentDirectory(parentDir); + } + } + + // If there are no directories to create, then we are done + if (pathList.getCount() == 0) + { + return true; + } + + // Traverse from back of the list, because that is most outer directory. + Int i = 0; + for (i = pathList.getCount() - 1; i >= 0; i--) + { + if (!createDirectory(pathList[i])) + { + break; + } + } + + // Something wrong when creating parent directories + if (i > 0) + { + // Remove the directories if we've created + if (i != pathList.getCount() - 1) + remove(pathList[i]); + + return false; + } + + return true; } /* static */SlangResult Path::getPathType(const String& path, SlangPathType* pathTypeOut) diff --git a/source/slang/slang-ir-specialize-function-call.cpp b/source/slang/slang-ir-specialize-function-call.cpp index 98aba0fae..d260f8105 100644 --- a/source/slang/slang-ir-specialize-function-call.cpp +++ b/source/slang/slang-ir-specialize-function-call.cpp @@ -596,7 +596,7 @@ struct FunctionParameterSpecializationContext IRInst* findNonuniformIndexInst(IRInst* inst) { - while(1) + for(;;) { if (inst == nullptr) return nullptr; |
