Commit 9076f5b2 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: provide argList::envGlobalPath() static method

- this is identical to either of these solutions:

     * getEnv("FOAM_CASE")
     * stringOps::expand("<case>")

  but with a closer resemblance to argList or Time globalPath(),
  which makes the intent clearer.
  Avoids using raw strings in the caller, which improves compile-time checks.

  Used in situations where a class has no derivation path or other
  access to a time registry or command args.
parent 455c8ef5
......@@ -25,6 +25,7 @@ License
#include "dynamicCode.H"
#include "dynamicCodeContext.H"
#include "argList.H"
#include "stringOps.H"
#include "Fstream.H"
#include "IOstreams.H"
......@@ -64,10 +65,10 @@ void Foam::dynamicCode::checkSecurity
if (isAdministrator())
{
FatalIOErrorInFunction(dict)
<< "This code should not be executed by someone with administrator"
<< " rights due to security reasons." << nl
<< "(it writes a shared library which then gets loaded "
<< "using dlopen)"
<< "This code should not be executed by someone"
<< " with administrator rights for security reasons." << nl
<< "It generates a shared library which is loaded using dlopen"
<< nl << endl
<< exit(FatalIOError);
}
......@@ -292,8 +293,8 @@ bool Foam::dynamicCode::writeDigest(const std::string& sha1) const
Foam::dynamicCode::dynamicCode(const word& codeName, const word& codeDirName)
:
codeRoot_(stringOps::expand("<case>")/topDirName),
libSubDir_(stringOps::expand("platforms/$WM_OPTIONS/lib")),
codeRoot_(argList::envGlobalPath()/topDirName),
libSubDir_(stringOps::expand("platforms/${WM_OPTIONS}/lib")),
codeName_(codeName),
codeDirName_(codeDirName)
{
......
......@@ -463,6 +463,14 @@ bool Foam::argList::postProcess(int argc, char *argv[])
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::fileName Foam::argList::envGlobalPath()
{
return Foam::getEnv("FOAM_CASE");
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::word Foam::argList::optionCompat(const word& optName)
......
......@@ -272,6 +272,18 @@ public:
// Member Functions
// Environment
//- Global case (directory) from environment variable
//
// Returns the contents of the \c FOAM_CASE variable,
// which has previously been set by argList or by Time.
//
// This will normally be identical to the value of globalPath(),
// but obtained via the environment.
static fileName envGlobalPath();
// Low-level
//- Scan for -help, -doc options etc prior to checking the validity
......
......@@ -114,9 +114,17 @@ bool Foam::functionObjects::systemCall::read(const dictionary& dict)
if (executeCalls_.empty() && endCalls_.empty() && writeCalls_.empty())
{
WarningInFunction
<< "no executeCalls, endCalls or writeCalls defined."
<< "No executeCalls, endCalls or writeCalls defined."
<< endl;
}
else if (isAdministrator())
{
FatalErrorInFunction
<< "System calls should not be executed by someone"
<< " with administrator rights for security reasons." << nl
<< nl << endl
<< exit(FatalError);
}
else if (!dynamicCode::allowSystemOperations)
{
FatalErrorInFunction
......
......@@ -25,7 +25,7 @@ License
#include "noiseModel.H"
#include "functionObject.H"
#include "stringOps.H"
#include "argList.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -143,7 +143,7 @@ Foam::fileName Foam::noiseModel::baseFileDir(const label dataseti) const
{
return
(
stringOps::expand("<case>") // ie, globalPath()
argList::envGlobalPath()
/ functionObject::outputPrefix
/ "noise"
/ outputPrefix_
......
......@@ -25,7 +25,7 @@ License
#include "pointNoise.H"
#include "noiseFFT.H"
#include "stringOps.H"
#include "argList.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -244,8 +244,7 @@ void pointNoise::calculate()
if (!fName.isAbsolute())
{
// ie, globalPath() / name
fName = stringOps::expand("<case>")/fName;
fName = argList::envGlobalPath()/fName;
}
Function1Types::CSV<scalar> data("pressure", dict_, fName);
......
......@@ -27,8 +27,8 @@ License
#include "surfaceReader.H"
#include "surfaceWriter.H"
#include "noiseFFT.H"
#include "argList.H"
#include "graph.H"
#include "stringOps.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -465,8 +465,7 @@ void surfaceNoise::calculate()
if (!fName.isAbsolute())
{
// ie, globalPath() / name
fName = stringOps::expand("<case>")/fName;
fName = argList::envGlobalPath()/fName;
}
initialise(fName);
......
......@@ -25,6 +25,7 @@ License
#include "boundaryDataSurfaceWriter.H"
#include "makeSurfaceWriterMethods.H"
#include "argList.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -62,7 +63,7 @@ Foam::fileName Foam::boundaryDataSurfaceWriter::write
const pointField& points = surf.points();
// Dummy time to use as an objectRegistry
const fileName caseDir(getEnv("FOAM_CASE"));
const fileName caseDir(argList::envGlobalPath());
Time dummyTime
(
......
......@@ -54,7 +54,7 @@ Foam::fileName Foam::boundaryDataSurfaceWriter::writeTemplate
const faceList& faces = surf.faces();
// Dummy time to use as an objectRegistry
const fileName caseDir(getEnv("FOAM_CASE"));
const fileName caseDir(argList::envGlobalPath());
Time dummyTime
(
......
Supports Markdown
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