From 9891fe98d41279b8c310a34e4d7b292c0692e111 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Fri, 8 Nov 2024 14:33:57 -0800 Subject: [PATCH] get_full_path() now with trailing / if treatAsDir is true --- src/core/chuck_compile.cpp | 6 ++++-- src/core/chuck_dl.cpp | 2 +- src/core/util_string.cpp | 20 ++++++++++++-------- src/core/util_string.h | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/core/chuck_compile.cpp b/src/core/chuck_compile.cpp index e9ed171ec..8c7454c38 100644 --- a/src/core/chuck_compile.cpp +++ b/src/core/chuck_compile.cpp @@ -685,8 +685,10 @@ std::string Chuck_Compiler::resolveFilename( const std::string & filename, for( list::iterator it = searchPaths.begin(); it != searchPaths.end(); it++ ) { // construct path; expand path again here in case search path has things like ~ - absolutePath = get_full_path(expand_filepath(normalize_directory_name(*it)+fname)); - // try to match + // make sure to get_full_path on the directory itself before appending fname, + // FYI get_full_path() verifies presence of file, fname could be without extension e.g., @import "Foo" + absolutePath = get_full_path( expand_filepath(*it), TRUE ) + fname; + // try to match, by known extensions if none specified hasMatch = matchFilename( absolutePath, extension, exts ); // log EM_log( CK_LOG_FINER, "testing match: '%s' ('%s')", absolutePath.c_str(), hasMatch ? "yes" : "no" ); diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index b027e0802..771134b80 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -3040,7 +3040,7 @@ void * dlopen( const char * path, int mode ) // if empty string, use current directory if( dll_path == "" ) dll_path = ".\\"; // AddDllDirectory expects only fullpaths - dll_path = get_full_path( dll_path ); + dll_path = get_full_path( dll_path, TRUE ); // the relateive _deps directory string dll_deps_path = dll_path + "_deps\\"; // convert to wchar diff --git a/src/core/util_string.cpp b/src/core/util_string.cpp index bf3589e21..dfb98d519 100644 --- a/src/core/util_string.cpp +++ b/src/core/util_string.cpp @@ -774,10 +774,12 @@ std::string get_full_path( const std::string & fp, t_CKBOOL treatAsDir ) if( result == NULL && !treatAsDir && !extension_matches(fp, ".ck") ) result = realpath((fp + ".ck").c_str(), buf); - if( result == NULL ) - return fp; - else - return buf; + // get the return value + string ret = result ? buf : fp; + // if treat as dir, ensure trailing / 1.5.4.2 (ge & nshaheed) added + if( treatAsDir ) ret = normalize_directory_name(ret); + // return + return ret; #else // windows @@ -807,10 +809,12 @@ std::string get_full_path( const std::string & fp, t_CKBOOL treatAsDir ) #endif } - if( result == 0 ) - return fp; - else - return normalize_directory_separator(buf); + // get the return value + string ret = result ? normalize_directory_separator(buf) : fp; + // if treat as dir, ensure trailing / 1.5.4.2 (ge & nshaheed) added + if( treatAsDir ) ret = normalize_directory_name(ret); + // return + return ret; #endif // __PLATFORM_WINDOWS__ } diff --git a/src/core/util_string.h b/src/core/util_string.h index d88eb5e84..21e6f0871 100644 --- a/src/core/util_string.h +++ b/src/core/util_string.h @@ -100,7 +100,7 @@ t_CKBOOL extract_args( const std::string & token, std::string dir_go_up( const std::string & dir, t_CKINT numUp ); // get full path to file -std::string get_full_path( const std::string & fp, t_CKBOOL treatAsDirector = FALSE ); +std::string get_full_path( const std::string & fp, t_CKBOOL treatAsDirectory = FALSE ); // perform filepath expansion (e.g., with ~ on unix systems and some windows) std::string expand_filepath( const std::string & fp, t_CKBOOL ensurePathExists = FALSE );