diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 920d720cf5..3dbd628f04 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -264,7 +264,12 @@ bool Foam::chDir(const fileName& dir) } -Foam::fileNameList Foam::findEtcFiles(const fileName& name, bool mandatory) +Foam::fileNameList Foam::findEtcFiles +( + const fileName& name, + bool mandatory, + bool findFirst +) { fileNameList results; @@ -279,12 +284,20 @@ Foam::fileNameList Foam::findEtcFiles(const fileName& name, bool mandatory) if (isFile(fullName)) { results.append(fullName); + if (findFirst) + { + goto DONE; + } } fullName = searchDir/name; if (isFile(fullName)) { results.append(fullName); + if (findFirst) + { + goto DONE; + } } } @@ -301,12 +314,20 @@ Foam::fileNameList Foam::findEtcFiles(const fileName& name, bool mandatory) if (isFile(fullName)) { results.append(fullName); + if (findFirst) + { + goto DONE; + } } fullName = searchDir/name; if (isFile(fullName)) { results.append(fullName); + if (findFirst) + { + goto DONE; + } } } } @@ -323,12 +344,20 @@ Foam::fileNameList Foam::findEtcFiles(const fileName& name, bool mandatory) if (isFile(fullName)) { results.append(fullName); + if (findFirst) + { + goto DONE; + } } fullName = searchDir/"site"/name; if (isFile(fullName)) { results.append(fullName); + if (findFirst) + { + goto DONE; + } } } } @@ -343,6 +372,10 @@ Foam::fileNameList Foam::findEtcFiles(const fileName& name, bool mandatory) if (isFile(fullName)) { results.append(fullName); + if (findFirst) + { + goto DONE; + } } } @@ -360,6 +393,7 @@ Foam::fileNameList Foam::findEtcFiles(const fileName& name, bool mandatory) } } +DONE: // Return list of matching paths or empty list if none found return results; } @@ -367,7 +401,7 @@ Foam::fileNameList Foam::findEtcFiles(const fileName& name, bool mandatory) Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory) { - fileNameList results(findEtcFiles(name, mandatory)); + fileNameList results(findEtcFiles(name, mandatory, true)); if (results.size()) { diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index 119c669b5f..5491223fcd 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -110,13 +110,19 @@ bool chDir(const fileName& dir); // // \return The list of full paths of all the matching files or // an empty list if the name cannot be found. -// Optionally abort if the file cannot be found -fileNameList findEtcFiles(const fileName&, bool mandatory=false); +// Optionally abort if the file cannot be found. +// Optionally stop search after the first file has been found. +fileNameList findEtcFiles +( + const fileName&, + bool mandatory=false, + bool findFirst=false +); //- Search for a file using findEtcFiles. -// \return The full path name of the first file found which in the +// \return The full path name of the first file found in the // search hierarchy or an empty fileName if the name cannot be found. -// Optionally abort if the file cannot be found +// Optionally abort if the file cannot be found. fileName findEtcFile(const fileName&, bool mandatory=false); //- Make a directory and return an error if it could not be created