ENH: reinstate short-circuit behaviour for findEtcFile()

This commit is contained in:
Mark Olesen
2011-07-07 14:59:18 +02:00
parent 227f440496
commit c2d99767a2
2 changed files with 46 additions and 6 deletions

View File

@ -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())
{

View File

@ -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