From: Christian P. <cp...@us...> - 2005-05-07 13:23:50
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16085/src/System Modified Files: PathFinder.cpp Log Message: - Removed basename(), dirSeparator() and isAccessible() from PathFinder, it now uses the Path class. - Use absolute pathes when finding Files ... without we may cache relative paths that point to the same absolute path. Index: PathFinder.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/PathFinder.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- PathFinder.cpp 28 Apr 2005 10:21:44 -0000 1.6 +++ PathFinder.cpp 7 May 2005 13:23:39 -0000 1.7 @@ -15,6 +15,7 @@ #endif #include "pclasses/Trace.h" +#include "pclasses/System/Path.h" #include "pclasses/System/PathFinder.h" namespace P { @@ -91,42 +92,6 @@ _exts.insert(_exts.end(), ne.begin(), ne.end()); } -// static -bool PathFinder::isAccessible(const Unicode::String & path) -{ -#if WIN32 -# define CHECKACCESS _access -# define CHECKRIGHTS 0 -#else -# define CHECKACCESS access -# define CHECKRIGHTS F_OK -#endif - - return 0 == CHECKACCESS(path.utf8().c_str(), CHECKRIGHTS); -#undef CHECKACCESS -#undef CHECKRIGHTS -} - -Unicode::String PathFinder::basename(const Unicode::String& name) -{ - Unicode::String::size_type slashat = - name.find_last_of(PathFinder::dirSeparator()); - - if(slashat == Unicode::String::npos) - return name; - - return name.substr(slashat + 1); -} - -Unicode::String PathFinder::dirSeparator() -{ -#ifdef WIN32 - return Unicode::String( "\\" ); -#else - return Unicode::String( "/" ); -#endif -} - Unicode::String PathFinder::pathSeparator() { #ifdef WIN32 @@ -148,7 +113,7 @@ #define CHECKPATH(CHECKAT) \ P_TRACE(PathFinder) << "testing '" << CHECKAT << "'"; \ - if( ! CHECKAT.empty() && PathFinder::isAccessible( CHECKAT ) ) \ + if( ! CHECKAT.empty() && Path(CHECKAT).isAccessible() ) \ { \ P_TRACE(PathFinder) << "found '" << CHECKAT << "'"; \ return _hitcache.insert(std::make_pair(resource, CHECKAT)).first->second; \ @@ -166,17 +131,12 @@ } } - CHECKPATH(resource); + //security risk! do not search in current directory by default!! + //CHECKPATH(resource); string_list::const_iterator piter = _paths.begin(); string_list::const_iterator eiter = _exts.begin(); - if(PathFinder::isAccessible(resource)) - { - P_TRACE(PathFinder) << "found '" << resource << "'"; - return resource; - } - Unicode::String path, ext; Unicode::String checkhere; @@ -185,7 +145,8 @@ path = (*piter); if(!path.empty()) { - path += PathFinder::dirSeparator(); + path = Path(path).absPath(); + path += Path::separator(); } ++piter; |