34 #ifndef FOAM_RESOURCE_USER_CONFIG_DIRNAME 35 # warning FOAM_RESOURCE_USER_CONFIG_DIRNAME undefined (was this intentional?) 38 #ifndef FOAM_RESOURCE_SITE_ENVNAME 39 # warning FOAM_RESOURCE_SITE_ENVNAME undefined (was this intentional?) 42 #ifndef FOAM_RESOURCE_SITE_FALLBACK_ENVNAME 43 # warning FOAM_RESOURCE_SITE_FALLBACK_ENVNAME undefined (was this intentional?) 48 #undef FOAM_PROJECT_ENVNAME 49 #define FOAM_PROJECT_ENVNAME "WM_PROJECT_DIR" 66 static inline std::string locationToString(
unsigned short location)
70 if (location & 0700) {
mode +=
'u'; }
71 if (location & 0070) {
mode +=
'g'; }
72 if (location & 0007) {
mode +=
'o'; }
80 static inline void errorMandatoryNotFound
82 const std::string&
name,
83 unsigned short location
91 <<
"--> FOAM FATAL ERROR :\n" 92 " Could not find mandatory etc entry (mode=" 93 << locationToString(location) <<
")\n '" 108 #ifdef FOAM_RESOURCE_USER_CONFIG_DIRNAME 136 #ifdef FOAM_RESOURCE_SITE_ENVNAME 138 if (queried.size() > 4)
146 #ifdef FOAM_RESOURCE_SITE_FALLBACK_ENVNAME 155 #ifdef FOAM_CONFIGURED_PROJECT_DIR 156 queried = FOAM_CONFIGURED_PROJECT_DIR
"/site/etc";
189 #ifdef FOAM_CONFIGURED_PROJECT_ETC 190 queried = FOAM_CONFIGURED_PROJECT_ETC;
197 #ifdef FOAM_CONFIGURED_PROJECT_DIR 198 queried = FOAM_CONFIGURED_PROJECT_DIR
"/etc";
214 static inline bool accept
222 const auto t =
name.type(
true,
true);
227 Foam::fileName::Type::UNDEFINED != t
231 Foam::fileName::Type::UNDEFINED == typeRequired
232 ? (Foam::fileName::Type::UNDEFINED != t)
233 : (typeRequired == t)
254 if (userResourceDir(queried) || (!test && queried.size()))
256 list[nDirs++] = queried/
version;
257 list[nDirs++] = queried;
261 if (groupResourceDir(queried) || (!test && queried.size()))
263 list[nDirs++] = queried/
version;
264 list[nDirs++] = queried;
268 if (projectResourceDir(queried) || (!test && queried.size()))
270 list[nDirs++] = queried;
282 unsigned short location,
292 if (!(location & 0777))
296 <<
"--> FOAM Error :\n " 297 "No user/group/other location specified for 'etc' file" 309 if (fileName::Type::FILE == typeRequired &&
name.empty())
317 if ((location & 0700) && userResourceDir(queried))
320 if (accept(candidate, typeRequired))
322 list.
append(std::move(candidate));
329 candidate = queried/
name;
330 if (accept(candidate, typeRequired))
332 list.
append(std::move(candidate));
342 if ((location & 0070) && groupResourceDir(queried))
345 if (accept(candidate, typeRequired))
347 list.
append(std::move(candidate));
354 candidate = queried/
name;
355 if (accept(candidate, typeRequired))
357 list.
append(std::move(candidate));
367 if ((location & 0007) && projectResourceDir(queried))
369 candidate = queried/
name;
370 if (accept(candidate, typeRequired))
372 list.
append(std::move(candidate));
382 const fileName&
name,
383 unsigned short location,
393 const fileName&
name,
394 const bool mandatory,
395 unsigned short location,
405 if (mandatory && list.
empty())
407 errorMandatoryNotFound(
name, location);
416 const fileName&
name,
417 unsigned short location,
428 found = std::move(list.first());
437 const fileName&
name,
438 unsigned short location
447 const fileName&
name,
448 const bool mandatory,
449 unsigned short location
454 if (mandatory &&
found.empty())
456 errorMandatoryNotFound(
name, location);
A class for handling file names.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void resize(const label len)
Adjust allocated size of list.
void append(const T &val)
Append an element at the end of the list.
fileNameList findEtcFiles(const fileName &name, const bool mandatory=false, unsigned short location=0777, const bool findFirst=false)
Search for files from user/group/other etc locations.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Ostream & endl(Ostream &os)
Add newline and flush stream.
#define FOAM_RESOURCE_SITE_ENVNAME
The env name for site-resources to obtain a site-resources directory.
string getEnv(const std::string &envName)
Get environment value for given envName.
fileName home()
Return home directory path name for the current user.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Functions to search 'etc' directories for configuration files etc.
#define FOAM_RESOURCE_USER_CONFIG_DIRNAME
fileNameList etcDirs(bool test=true)
The etc search directories in the normal search order.
const int api
OpenFOAM api number (integer) corresponding to the value of OPENFOAM at the time of compilation...
fileName findEtcDir(const fileName &name, unsigned short location=0777)
Search for a single FILE within the etc directories.
fileNameList findEtcEntries(const fileName &name, unsigned short location=0777, const fileName::Type typeRequired=fileName::Type::UNDEFINED, const bool findFirst=false)
Search for files or directories from user/group/other etc locations.
fileName findEtcEntry(const fileName &name, unsigned short location=0777, const fileName::Type typeRequired=fileName::Type::UNDEFINED)
Search for a single FILE or DIRECTORY within the etc directories.
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
fileName findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
#define FOAM_PROJECT_ENVNAME
fileNameList findEtcDirs(const fileName &name, unsigned short location=0777, const bool findFirst=false)
Search for directories from user/group/other etc locations.
List< fileName > fileNameList
A List of fileNames.
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
#define FOAM_RESOURCE_SITE_FALLBACK_ENVNAME
The env name for determining a fallback directory name for site-resources when the directory correspo...
Type
Enumerations to handle directory entry types.