diff --git a/LCS/Common/include/Common/FileLocator.h b/LCS/Common/include/Common/FileLocator.h index 6b67171643b0a8ca53a87d65801a64ae6da8deb2..1f8819482b4c4ff3e632f39f02759384df72ab82 100644 --- a/LCS/Common/include/Common/FileLocator.h +++ b/LCS/Common/include/Common/FileLocator.h @@ -81,11 +81,12 @@ public: inline string getSubdir(); //# Finally where it is all about. - // Tries to locate \a aFile in the search path. - // If \a aFile is found, then the full path name is returned; else an - // empty string is returned. - // If \a aFile contains an absolute path (i.e., it starts with a '/'), - // or equals is an empty string, then the input argument is returned. + // Try to locate \a aFile. + // If \a aFile is an absolute path, then simply check for its presence. + // If \a aFile is a relative path, then use the current search path to + // locate \a aFile. + // If \a aFile is found, return its full pathname, otherwise an return + // an empty string. string locate (const string& aFile); private: diff --git a/LCS/Common/src/FileLocator.cc b/LCS/Common/src/FileLocator.cc index dcabc20da5fd685dd7d312008d960b131bbfeab3..4baedfaedcb3969f5a1a416d2d641d796bd1923d 100644 --- a/LCS/Common/src/FileLocator.cc +++ b/LCS/Common/src/FileLocator.cc @@ -207,49 +207,54 @@ void FileLocator::removePath (const string& aPath) // locate(aFile): string // // Tries to find the file in the current searchpath. -// Returns the input argument, if that's an absolute path or an empty string. // Return full filename if found, or else an empty string. // string FileLocator::locate (const string& aFile) { - // return immediately if aFile is empty or contains an absolute path - if(aFile.empty() || aFile[0] == '/') { + // return immediately if aFile is empty + if(aFile.empty()) return string(); // DILEMMA: the filelocator is often used to locate the log_prop file. // using LOG_xxx here will result in an errormessage in that case. // SOLUTION: in global-init.cxx a variable 'initialized' is used in l4cp // to keep the state of the log-package. Make this var accessable. // LOG_DEBUG_STR ("Filename contains a /, returning inputname : " << aFile); - return (aFile); - } - // search the path chain - iterator iter = itsPaths.begin(); - iterator chainEnd = itsPaths.end(); - while (iter != chainEnd) { - // when itsSubdir is filled each test much be performed also with subdir - for (int32 test = 0; test <= (itsSubdir.empty() ? 0 : 1); test++) { - struct stat fileStat; - string fullname; - fullname = *iter + (*iter != "/" ? "/" : ""); - if (test == 0) { // basedir? - fullname += aFile; - } - else { // test subdir - fullname += itsSubdir + "/" + aFile; - } - int result = stat(fullname.c_str(), &fileStat); - if (result == 0) { // found? - return (fullname); + struct stat fileStat; + int result; + + // If aFile contains an absolute path, simply test for its existence. + if(aFile[0] == '/') { + result = stat(aFile.c_str(), &fileStat); + return (result == 0 ? aFile : string()); + } + // Otherwise, search the path chain + else { + iterator iter = itsPaths.begin(); + iterator chainEnd = itsPaths.end(); + while (iter != chainEnd) { + // when itsSubdir is filled each test much be performed also with subdir + for (int test = 0; test <= (itsSubdir.empty() ? 0 : 1); test++) { + string fullname; + fullname = *iter + (*iter != "/" ? "/" : ""); + if (test == 0) { // basedir? + fullname += aFile; + } + else { // test subdir + fullname += itsSubdir + "/" + aFile; + } + result = stat(fullname.c_str(), &fileStat); + if (result == 0) { // found? + return (fullname); + } } + ++iter; } - ++iter; + // not found, return empty string. + // See DILEMMA. +// LOG_DEBUG_STR ("Filename not found in " << getPath() << +// ", returning empty string"); + return string(); } - - // not found, return original file - // See DILEMMA. -// LOG_DEBUG_STR ("Filename not found in " << getPath() << -// ", returning empty string"); - return string(); } //