Commit 6f9573bb authored by Henry Weller's avatar Henry Weller
Browse files

etcFiles: Added functions to find directories in the 'etc' directories

'findEtcFiles' moved from OSspecific to 'etcFiles' as it is not OS-specific
parent c242c176
......@@ -292,155 +292,6 @@ bool Foam::chDir(const fileName& dir)
}
Foam::fileNameList Foam::findEtcFiles
(
const fileName& name,
bool mandatory,
bool findFirst
)
{
fileNameList results;
// Search for user files in
// * ~/.OpenFOAM/VERSION
// * ~/.OpenFOAM
//
fileName searchDir = home()/".OpenFOAM";
if (isDir(searchDir))
{
fileName fullName = searchDir/FOAMversion/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
fullName = searchDir/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
}
// Search for group (site) files in
// * $WM_PROJECT_SITE/VERSION
// * $WM_PROJECT_SITE
//
searchDir = getEnv("WM_PROJECT_SITE");
if (searchDir.size())
{
if (isDir(searchDir))
{
fileName fullName = searchDir/FOAMversion/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
fullName = searchDir/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
}
}
else
{
// OR search for group (site) files in
// * $WM_PROJECT_INST_DIR/site/VERSION
// * $WM_PROJECT_INST_DIR/site
//
searchDir = getEnv("WM_PROJECT_INST_DIR");
if (isDir(searchDir))
{
fileName fullName = searchDir/"site"/FOAMversion/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
fullName = searchDir/"site"/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
}
}
// Search for other (shipped) files in
// * $WM_PROJECT_DIR/etc
//
searchDir = getEnv("WM_PROJECT_DIR");
if (isDir(searchDir))
{
fileName fullName = searchDir/"etc"/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
}
// Not found
if (results.empty())
{
// Abort if the file is mandatory, otherwise return null
if (mandatory)
{
std::cerr
<< "--> FOAM FATAL ERROR in Foam::findEtcFiles() :"
" could not find mandatory file\n '"
<< name.c_str() << "'\n\n" << std::endl;
::exit(1);
}
}
// Return list of matching paths or empty list if none found
return results;
}
Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
{
fileNameList results(findEtcFiles(name, mandatory, true));
if (results.size())
{
return results[0];
}
else
{
return fileName();
}
}
bool Foam::mkDir(const fileName& pathName, mode_t mode)
{
// empty names are meaningless
......
......@@ -145,8 +145,7 @@ void Foam::sigStopAtWriteNow::set(const bool verbose)
FatalErrorInFunction
<< "stopAtWriteNowSignal : " << signal_
<< " cannot be the same as the writeNowSignal."
<< " Please change this in the controlDict ("
<< findEtcFile("controlDict", false) << ")."
<< " Please change this in the etc/controlDict."
<< exit(FatalError);
}
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "etcFiles.H"
#include "OSspecific.H"
#include "foamVersion.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::fileNameList Foam::findEtcDirs(const fileName& local)
{
fileNameList dirs;
// Search for user directories in
// * ~/.OpenFOAM/VERSION
// * ~/.OpenFOAM
//
fileName searchDir = home()/".OpenFOAM";
if (isDir(searchDir))
{
fileName fullName = searchDir/FOAMversion/local;
if (isDir(fullName))
{
dirs.append(fullName);
}
fullName = searchDir/local;
if (isDir(fullName))
{
dirs.append(fullName);
}
}
// Search for group (site) directories in
// * $WM_PROJECT_SITE/VERSION
// * $WM_PROJECT_SITE
//
searchDir = getEnv("WM_PROJECT_SITE");
if (searchDir.size())
{
if (isDir(searchDir))
{
fileName fullName = searchDir/FOAMversion/local;
if (isDir(fullName))
{
dirs.append(fullName);
}
fullName = searchDir/local;
if (isDir(fullName))
{
dirs.append(fullName);
}
}
}
else
{
// Or search for group (site) files in
// * $WM_PROJECT_INST_DIR/site/VERSION
// * $WM_PROJECT_INST_DIR/site
//
searchDir = getEnv("WM_PROJECT_INST_DIR");
if (isDir(searchDir))
{
fileName fullName = searchDir/"site"/FOAMversion/local;
if (isDir(fullName))
{
dirs.append(fullName);
}
fullName = searchDir/"site"/local;
if (isDir(fullName))
{
dirs.append(fullName);
}
}
}
// Search for other (shipped) files in
// * $WM_PROJECT_DIR/etc
//
searchDir = getEnv("WM_PROJECT_DIR");
if (isDir(searchDir))
{
fileName fullName = searchDir/"etc"/local;
if (isDir(fullName))
{
dirs.append(fullName);
}
}
return dirs;
}
Foam::fileNameList Foam::findEtcFiles
(
const fileName& name,
bool mandatory,
bool findFirst
)
{
fileNameList results;
// Search for user files in
// * ~/.OpenFOAM/VERSION
// * ~/.OpenFOAM
//
fileName searchDir = home()/".OpenFOAM";
if (isDir(searchDir))
{
fileName fullName = searchDir/FOAMversion/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
fullName = searchDir/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
}
// Search for group (site) files in
// * $WM_PROJECT_SITE/VERSION
// * $WM_PROJECT_SITE
//
searchDir = getEnv("WM_PROJECT_SITE");
if (searchDir.size())
{
if (isDir(searchDir))
{
fileName fullName = searchDir/FOAMversion/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
fullName = searchDir/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
}
}
else
{
// Or search for group (site) files in
// * $WM_PROJECT_INST_DIR/site/VERSION
// * $WM_PROJECT_INST_DIR/site
//
searchDir = getEnv("WM_PROJECT_INST_DIR");
if (isDir(searchDir))
{
fileName fullName = searchDir/"site"/FOAMversion/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
fullName = searchDir/"site"/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
}
}
// Search for other (shipped) files in
// * $WM_PROJECT_DIR/etc
//
searchDir = getEnv("WM_PROJECT_DIR");
if (isDir(searchDir))
{
fileName fullName = searchDir/"etc"/name;
if (isFile(fullName))
{
results.append(fullName);
if (findFirst)
{
return results;
}
}
}
// Not found
if (results.empty())
{
// Abort if the file is mandatory, otherwise return null
if (mandatory)
{
std::cerr
<< "--> FOAM FATAL ERROR in Foam::findEtcFiles() :"
" could not find mandatory file\n '"
<< name.c_str() << "'\n\n" << std::endl;
::exit(1);
}
}
// Return list of matching paths or empty list if none found
return results;
}
Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
{
fileNameList results(findEtcFiles(name, mandatory, true));
if (results.size())
{
return results[0];
}
else
{
return fileName();
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
InNamespace
Foam
Description
Functions to search 'etc' directories for configuration files etc.
SourceFiles
etcFiles.C
\*---------------------------------------------------------------------------*/
#ifndef etcFiles_H
#define etcFiles_H
#include "fileNameList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Search for directories from user/group/shipped directories.
// The search scheme allows for version-specific and
// version-independent files using the following hierarchy:
// - \b user settings:
// - ~/.OpenFOAM/\<VERSION\>
// - ~/.OpenFOAM/
// - \b group (site) settings (when $WM_PROJECT_SITE is set):
// - $WM_PROJECT_SITE/\<VERSION\>
// - $WM_PROJECT_SITE
// - \b group (site) settings (when $WM_PROJECT_SITE is not set):
// - $WM_PROJECT_INST_DIR/site/\<VERSION\>
// - $WM_PROJECT_INST_DIR/site/
// - \b other (shipped) settings:
// - $WM_PROJECT_DIR/etc/
//
// \return The list of full paths of all the matching directories or
// an empty list if the name cannot be found.
fileNameList findEtcDirs(const fileName& local = fileName::null);
//- Search for files from user/group/shipped directories.
// The search scheme allows for version-specific and
// version-independent files using the following hierarchy:
// - \b user settings:
// - ~/.OpenFOAM/\<VERSION\>
// - ~/.OpenFOAM/
// - \b group (site) settings (when $WM_PROJECT_SITE is set):
// - $WM_PROJECT_SITE/\<VERSION\>
// - $WM_PROJECT_SITE
// - \b group (site) settings (when $WM_PROJECT_SITE is not set):
// - $WM_PROJECT_INST_DIR/site/\<VERSION\>
// - $WM_PROJECT_INST_DIR/site/
// - \b other (shipped) settings:
// - $WM_PROJECT_DIR/etc/
//
// \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.
// 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 in the
// search hierarchy or an empty fileName if the name cannot be found.
// Optionally abort if the file cannot be found.
fileName findEtcFile(const fileName&, bool mandatory=false);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -92,38 +92,6 @@ fileName cwd();
// else return false
bool chDir(const fileName& dir);
//- Search for files from user/group/shipped directories.
// The search scheme allows for version-specific and
// version-independent files using the following hierarchy:
// - \b user settings:
// - ~/.OpenFOAM/\<VERSION\>
// - ~/.OpenFOAM/
// - \b group (site) settings (when $WM_PROJECT_SITE is set):
// - $WM_PROJECT_SITE/\<VERSION\>
// - $WM_PROJECT_SITE
// - \b group (site) settings (when $WM_PROJECT_SITE is not set):
// - $WM_PROJECT_INST_DIR/site/\<VERSION\>
// - $WM_PROJECT_INST_DIR/site/
// - \b other (shipped) settings:
// - $WM_PROJECT_DIR/etc/
//
// \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.
// 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 in the
// search hierarchy or an empty fileName if the name 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
// and does not already exist
bool mkDir(const fileName&, mode_t=0777);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment