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"
66static 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'; }
73 if (mode.empty()) { mode =
"???"; }
80static 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";
214static inline bool accept
222 const auto t = name.type(
true,
true);
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"
299 <<
name.c_str() <<
"'\n\n" << std::endl;
309 if (fileName::Type::FILE == typeRequired &&
name.empty())
317 if ((location & 0700) && userResourceDir(queried))
319 candidate = queried/version/
name;
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))
344 candidate = queried/version/
name;
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));
383 unsigned short location,
394 const bool mandatory,
395 unsigned short location,
405 if (mandatory && list.
empty())
407 errorMandatoryNotFound(
name, location);
417 unsigned short location,
438 unsigned short location
448 const bool mandatory,
449 unsigned short location
454 if (mandatory &&
found.empty())
456 errorMandatoryNotFound(
name, location);
#define FOAM_RESOURCE_USER_CONFIG_DIRNAME
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
void append(const T &val)
Append an element at the end of the list.
void resize(const label len)
Adjust allocated size of list.
T & first()
Return the first element of the list.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
void size(const label n)
Older name for setAddressableSize.
A class for handling file names.
Type
Enumerations to handle directory entry types.
@ UNDEFINED
Undefined type.
#define FOAM_PROJECT_ENVNAME
Functions to search 'etc' directories for configuration files etc.
#define FOAM_RESOURCE_SITE_FALLBACK_ENVNAME
#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 findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
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.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
fileNameList findEtcDirs(const fileName &name, unsigned short location=0777, const bool findFirst=false)
Search for directories from user/group/other etc locations.
fileNameList etcDirs(bool test=true)
The etc search directories in the normal search order.
fileName home()
Return home directory path name for the current user.
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.
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.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?