From 2700a89f8c80620f1d523563cc80ec0da39e9761 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 22 Oct 2018 20:48:59 -0400 Subject: Fix problem with __import not working (#688) * Added getPathType to ISlangFileSystemExt. This is needed so that when searching for a file it's existance can be tested without loading the file. On some platforms a getCanonicalPath can do this - but depending on how getCanonicalPath is implemented, it may not do. This test is made after the relative path is produced before finding the canonical path. * Test for importing along search path. * Added comment to explain the issue around WrapFileSystem impl of getPathType. * Make search path use / not \ --- source/core/slang-io.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'source/core/slang-io.cpp') diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index ab093f577..2b443a62b 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -132,6 +132,49 @@ namespace Slang #endif } + /* static */SlangResult Path::GetPathType(const String & path, SlangPathType* pathTypeOut) + { +#ifdef _WIN32 + // https://msdn.microsoft.com/en-us/library/14h5k7ff.aspx + struct _stat32 statVar; + if (::_wstat32(String(path).ToWString(), &statVar) == 0) + { + if (statVar.st_mode & _S_IFDIR) + { + *pathTypeOut = SLANG_PATH_TYPE_DIRECTORY; + return SLANG_OK; + } + else if (statVar.st_mode & _S_IFREG) + { + *pathTypeOut = SLANG_PATH_TYPE_FILE; + return SLANG_OK; + } + return SLANG_FAIL; + } + + return SLANG_E_NOT_FOUND; +#else + struct stat statVar; + if (::stat(path.Buffer(), &statVar) == 0) + { + if (S_ISDIR(statVar.st_mode)) + { + *pathTypeOut = SLANG_PATH_TYPE_DIRECTORY; + return SLANG_OK; + } + if (S_ISREG(statVar.st_mode)) + { + *pathTypeOut = SLANG_PATH_TYPE_FILE; + return SLANG_OK; + } + return SLANG_FAIL; + } + + return SLANG_E_NOT_FOUND; +#endif + } + + /* static */SlangResult Path::GetCanonical(const String & path, String & canonicalPathOut) { #if defined(_WIN32) -- cgit v1.2.3