diff --git a/applications/test/etcFiles/Test-etcFiles.C b/applications/test/etcFiles/Test-etcFiles.C index 022c5295af..59d3a8b47f 100644 --- a/applications/test/etcFiles/Test-etcFiles.C +++ b/applications/test/etcFiles/Test-etcFiles.C @@ -64,6 +64,11 @@ int main(int argc, char *argv[]) "list", "List directories or files to be checked" ); + argList::addBoolOption + ( + "list-all", + "List all directories (including non-existence ones)" + ); argList::addArgument("file..."); argList::addNote @@ -77,9 +82,15 @@ int main(int argc, char *argv[]) // First handle no parameters if (args.size() == 1) { - if (args.found("list")) + if (args.found("list-all")) { - fileNameList results = findEtcDirs(); + fileNameList results = etcDirs(false); + printList(results); + return 0; + } + else if (args.found("list")) + { + fileNameList results = etcDirs(); printList(results); return 0; } diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index d5d1cd32f0..e74e2eca52 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -871,8 +871,14 @@ void Foam::argList::parse if (Pstream::master() && bannerEnabled()) { IOobject::writeBanner(Info, true) - << "Build : " << foamVersion::build.c_str() - << " (OPENFOAM=" << OPENFOAM; + << "Build : "; + + if (foamVersion::build.size()) + { + Info<< foamVersion::build.c_str() << ' '; + } + + Info<< "OPENFOAM=" << foamVersion::api; if (foamVersion::patched()) { @@ -880,7 +886,7 @@ void Foam::argList::parse Info<< " patch=" << foamVersion::patch.c_str(); } - Info<< ')' << nl + Info<< nl << "Arch : " << foamVersion::buildArch << nl << "Exec : " << commandLine_.c_str() << nl << "Date : " << dateString.c_str() << nl diff --git a/src/OpenFOAM/global/etcFiles/etcFiles.C b/src/OpenFOAM/global/etcFiles/etcFiles.C index c192baab4c..fc9997b4bf 100644 --- a/src/OpenFOAM/global/etcFiles/etcFiles.C +++ b/src/OpenFOAM/global/etcFiles/etcFiles.C @@ -95,6 +95,7 @@ static inline bool groupResourceDir(Foam::fileName& queried) is undefined (was this intentional?) #endif + queried.clear(); return false; } @@ -108,7 +109,13 @@ static inline bool groupResourceDir(Foam::fileName& queried) static inline bool projectResourceDir(Foam::fileName& queried) { queried = Foam::getEnv("WM_PROJECT_DIR")/"etc"; - return (queried.size() > 3 && Foam::isDir(queried)); + if (queried.size() > 3) + { + return Foam::isDir(queried); + } + + queried.clear(); + return false; } @@ -119,8 +126,9 @@ Foam::fileNameList searchEtc bool (*accept)(const Foam::fileName&) ) { - // Could use foamVersion::api, but this more direct. - const Foam::fileName version(std::to_string(OPENFOAM)); + // Use foamVersion::api (instead of the OPENFOAM define) to ensure this + // stays properly synchronized with the build information + const Foam::fileName version(std::to_string(Foam::foamVersion::api)); Foam::fileNameList list; Foam::fileName dir, candidate; @@ -192,6 +200,42 @@ Foam::fileNameList searchEtc // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +Foam::fileNameList Foam::etcDirs(bool test) +{ + // Use foamVersion::api (instead of the OPENFOAM define) to ensure this + // stays properly synchronized with the build information + const Foam::fileName version(std::to_string(Foam::foamVersion::api)); + + Foam::fileNameList list(5); + Foam::fileName dir; + label nDirs = 0; + + // User resource directories + if (userResourceDir(dir) || (!test && dir.size())) + { + list[nDirs++] = dir/version; + list[nDirs++] = dir; + } + + // Group (site) resource directories + if (groupResourceDir(dir) || (!test && dir.size())) + { + list[nDirs++] = dir/version; + list[nDirs++] = dir; + } + + // Other (project) resource directory + if (projectResourceDir(dir) || (!test && dir.size())) + { + list[nDirs++] = dir; + } + + list.resize(nDirs); + + return list; +} + + Foam::fileNameList Foam::findEtcDirs ( const fileName& name, diff --git a/src/OpenFOAM/global/etcFiles/etcFiles.H b/src/OpenFOAM/global/etcFiles/etcFiles.H index bbe5291876..9fdcc696c3 100644 --- a/src/OpenFOAM/global/etcFiles/etcFiles.H +++ b/src/OpenFOAM/global/etcFiles/etcFiles.H @@ -44,6 +44,14 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +//- The etc search directories in the normal search order. +// +// \param test false to disable the default test for directory existence. +// +// \return The list of directories +fileNameList etcDirs(bool test=true); + + //- Search for directories from user/group/other directories. // Uses search hierarchy as per findEtcFiles(). // @@ -51,8 +59,8 @@ namespace Foam // an empty list if the name cannot be found. fileNameList findEtcDirs ( - const fileName& name=fileName::null, //!< the file to search for - const bool findFirst=false //!< stop when the first file has been found + const fileName& name, //!< The directory to search for + const bool findFirst=false //!< Stop after locating the first directory ); @@ -76,9 +84,9 @@ fileNameList findEtcDirs // an empty list if the name cannot be found. fileNameList findEtcFiles ( - const fileName& name, //!< the file to search for - const bool mandatory=false, //!< abort if the file cannot be found - const bool findFirst=false //!< stop when the first file has been found + const fileName& name, //!< The file to search for + const bool mandatory=false, //!< Abort if the file cannot be found + const bool findFirst=false //!< Stop after locating the first directory ); @@ -88,8 +96,8 @@ fileNameList findEtcFiles // search hierarchy or an empty fileName if the name cannot be found. fileName findEtcFile ( - const fileName& name, //!< the file to search for - const bool mandatory=false //!< abort if the file cannot be found + const fileName& name, //!< The file to search for + const bool mandatory=false //!< Abort if the file cannot be found );