Go to the documentation of this file.
41 namespace fileOperations
62 const bool checkGlobal,
72 if (isFileOrDir(
isFile, objectPath))
78 return fileName::null;
86 if (isFileOrDir(
isFile, objectPath))
108 if (isFileOrDir(
isFile, parentObjectPath))
110 return parentObjectPath;
119 fileOperation::lookupAndCacheProcessorsPath
126 for (
const dirIndex& dirIdx : pDirs())
128 const fileName& pDir = dirIdx.first();
130 processorsPath(io, io.
instance(), pDir)
132 if (objPath != objectPath && isFileOrDir(
isFile, objPath))
149 if (newInstancePath.size())
157 if (isFileOrDir(
isFile, fName))
165 return fileName::null;
177 return fileOperation::lookupAndCacheProcessorsPath(fName,
false);
193 <<
"I/O : " << typeName <<
endl;
223 const bool followLink
233 const bool followLink
243 const bool checkGzip,
244 const bool followLink
254 const bool followLink
264 const bool checkGzip,
265 const bool followLink
275 const bool followLink
285 const bool followLink
295 const bool followLink
305 const std::string& ext
336 const bool followLink
347 const bool followLink
350 return Foam::cp(src, dst, followLink);
368 const bool followLink
371 return Foam::mv(src, dst, followLink);
377 const bool checkGlobal,
379 const word& typeName,
385 Pout<<
"uncollatedFileOperation::filePath :"
387 <<
" checkGlobal:" << checkGlobal <<
endl;
394 Pout<<
"uncollatedFileOperation::filePath :"
395 <<
" Returning from file searching:" <<
endl
397 <<
" filePath :" << objPath <<
endl <<
endl;
405 const bool checkGlobal,
412 Pout<<
"uncollatedFileOperation::dirPath :"
414 <<
" checkGlobal:" << checkGlobal <<
endl;
421 Pout<<
"uncollatedFileOperation::dirPath :"
422 <<
" Returning from directory searching:" <<
endl
424 <<
" dirPath :" << objPath <<
endl <<
endl;
440 Pout<<
"uncollatedFileOperation::readObjects :"
442 <<
" instance:" << instance <<
endl;
448 fileOperation::readObjects(db, instance, local, newInstance)
451 if (newInstance.empty())
455 if (!newInst.empty() && newInst != instance)
458 objectNames = fileOperation::readObjects
470 Pout<<
"uncollatedFileOperation::readObjects :"
471 <<
" newInstance:" << newInstance
472 <<
" objectNames:" << objectNames <<
endl;
488 Pout<<
"uncollatedFileOperation::readHeader :"
489 <<
" fName:" << fName
490 <<
" typeName:" << typeName <<
endl;
497 <<
"file " << io.
objectPath() <<
" could not be opened"
506 if (!isPtr || !isPtr->
good())
512 bool ok = decomposedBlockData::readHeader(io, *isPtr);
516 Pout<<
"uncollatedFileOperation::readHeader :"
517 <<
" for fName:" << fName
531 const word& typeName,
549 if (!isPtr || !isPtr->
good())
553 "uncollatedFileOperation::readStream()",
558 ) <<
"cannot open file"
564 <<
"problem while reading header for object " << io.
name()
568 if (!decomposedBlockData::isCollatedType(io))
577 label proci = detectProcessorPath(io.
objectPath());
582 <<
"could not detect processor number"
584 <<
" fName:" << fName
594 splitProcessorPath(fName,
path, procDir, local,
group, nProcs);
599 proci = proci -
group.start();
611 const bool masterOnly,
617 if (Pstream::master() || !masterOnly)
621 Pout<<
"uncollatedFileOperation::read :"
623 <<
" from file " <<
endl;
631 const bool oldMasterOnly = regIOobject::masterOnlyReading;
632 regIOobject::masterOnlyReading = masterOnly;
635 ok = io.
readData(io.readStream(typeName));
640 regIOobject::masterOnlyReading = oldMasterOnly;
644 Pout<<
"uncollatedFileOperation::read :"
646 <<
" from file " <<
endl;
650 if (masterOnly && Pstream::parRun())
655 Pstream::scatter(io.
note());
660 (Pstream::nProcs() < Pstream::nProcsSimpleSum)
661 ? Pstream::linearCommunication()
662 : Pstream::treeCommunication()
667 if (myComm.
above() != -1)
671 Pstream::commsTypes::scheduled,
686 Pstream::commsTypes::scheduled,
687 myComm.
below()[belowI],
int debug
Static debugging option.
const fileName & globalCaseName() const
Return global case name.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
#define InfoInFunction
Report an information message using Foam::Info.
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
A class for handling words, derived from Foam::string.
An encapsulation of filesystem-related operations.
A class for handling file names.
bool chMod(const fileName &name, const mode_t mode)
Set the file/directory mode, return true on success.
constexpr const char *const group
Group name for atomic constants.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
const fileName & instance() const noexcept
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
Input from file stream, using an ISstream.
An interval of (signed) integers defined by a start and a size.
A fileOperation initialiser for unthreaded file handlers.
Output inter-processor communications stream.
virtual bool writeData(Ostream &) const =0
Pure virtual writeData function.
Dummy input stream, which can be used as a placeholder for interfaces taking an Istream or ISstream....
const fileName & rootPath() const
bool processorCase() const noexcept
Return true if this is a processor case.
Type
Enumerations to handle directory entry types.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &io, const bool search) const
Search for an object.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
addNamedToRunTimeSelectionTable(fileOperationInitialise, collatedFileOperationInitialise, word, collated)
Ostream & endl(Ostream &os)
Add newline and flush stream.
const word & headerClassName() const noexcept
Return name of the class name read from header.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
const labelList & below() const noexcept
const Time & time() const
Return Time associated with the objectRegistry.
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory. checkGlobal : also check undecomposed.
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &) const
Lookup name of processorsDDD using cache.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
#define forAll(list, i)
Loop across all elements in list.
virtual fileName filePath(const bool checkGlobal, const IOobject &io, const word &typeName, const bool search) const
Search for an object. checkGlobal : also check undecomposed case.
bool readHeader(Istream &is)
Registry of regIOobjects.
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
word format(conversionProperties.get< word >("format"))
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
const fileName & local() const noexcept
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
const fileName & caseName() const
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
bool globalObject() const noexcept
Is object same for all processors?
The IOstreamOption is a simple container for options an IOstream can normally have.
bool good() const noexcept
True if the managed pointer is non-null.
double highResLastModified(const fileName &, const bool followLink=true)
Return time of last file modification.
streamFormat
Data format (ascii | binary)
bool mv(const fileName &src, const fileName &dst, const bool followLink=false)
Rename src to dst.
Macros for easy insertion into run-time selection tables.
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
virtual bool read(regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const
Top-level read.
virtual fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true, const bool followLink=true) const
Read a directory and return the entries as a string list.
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
General fileOperation initialiser. Handles -ioRanks option, using it to set the FOAM_IORANKS environm...
virtual bool rmDir(const fileName &dir, const bool silent=false) const
Remove a directory and its contents.
Structure for communicating between processors.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Output to file stream, using an OSstream.
bool mvBak(const fileName &src, const std::string &ext="bak")
Rename to a corresponding backup file.
const word & name() const noexcept
Return name.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
const string & note() const noexcept
Return the optional note.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
word findInstancePath(const fileName &directory, const instant &t) const
const word & system() const
Return system name.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy the source to the destination (recursively if necessary).
bool rmDir(const fileName &directory, const bool silent=false)
Remove a directory and its contents (optionally silencing warnings)
void close()
Close Istream.
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
uncollatedFileOperation(bool verbose)
Default construct.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
label above() const noexcept
virtual bool readData(Istream &)
Virtual readData function.
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Input inter-processor communications stream.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
An instant of time. Contains the time value and name.
virtual bool exists(const fileName &, const bool checkGzip=true, const bool followLink=true) const
Does the name exist (as DIRECTORY or FILE) in the file system?
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
fileName objectPath() const
The complete path + object name.
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool procValid=true) const
Reads header for regIOobject and returns an ISstream.
const word & constant() const
Return constant name.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
fileName path() const
The complete path.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Generate an OSstream that writes a file.
static bool isAbsolute(const std::string &str)
const Time & time() const noexcept
Return time registry.
virtual bool isFile(const fileName &, const bool checkGzip=true, const bool followLink=true) const
Does the name exist as a FILE in the file system?
time_t lastModified(const fileName &name, const bool followLink=true)
Return time of last file modification (normally follows symbolic links).
defineTypeNameAndDebug(collatedFileOperation, 0)
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or LINK.
A class for managing references or pointers (no reference counting)
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
static void readBlock(Istream &is, const label n, List< T > &list)
const objectRegistry & db() const noexcept
Return the local objectRegistry.