Skip to content

Commit

Permalink
get_full_path() now with trailing / if treatAsDir is true
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Nov 8, 2024
1 parent 32ca6de commit 9891fe9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/core/chuck_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,10 @@ std::string Chuck_Compiler::resolveFilename( const std::string & filename,
for( list<string>::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" );
Expand Down
2 changes: 1 addition & 1 deletion src/core/chuck_dl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions src/core/util_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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__
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/util_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 9891fe9

Please sign in to comment.