An encapsulation of filesystem-related operations. More...
Public Types | |
enum | pathType { NOTFOUND, ABSOLUTE, OBJECT, WRITEOBJECT, PROCUNCOLLATED, PROCBASEOBJECT, PROCOBJECT, PARENTOBJECT, FINDINSTANCE, PROCUNCOLLATEDINSTANCE, PROCBASEINSTANCE, PROCINSTANCE } |
Enumeration for the location of an IOobject. More... | |
typedef Tuple2< fileName, Tuple2< pathType, label > > | dirIndex |
A dirIndex adds the path type and local offset to a fileName. More... | |
typedef List< dirIndex > | dirIndexList |
typedef IntRange< int > | procRangeType |
Public Member Functions | |
TypeName ("fileOperation") | |
Runtime type information. More... | |
fileOperation (const label comm, const bool distributedRoots=false) | |
Construct from communicator, optionally with distributed roots. More... | |
declareRunTimeSelectionTable (autoPtr, fileOperation, word,(bool verbose),(verbose)) | |
virtual | ~fileOperation ()=default |
Destructor. More... | |
bool | distributed () const noexcept |
Distributed roots (parallel run) More... | |
bool | distributed (bool on) noexcept |
Set distributed roots on/off, return old value. More... | |
virtual bool | mkDir (const fileName &, mode_t=0777) const =0 |
Make directory. More... | |
virtual bool | chMod (const fileName &, const mode_t) const =0 |
Set the file mode. More... | |
virtual mode_t | mode (const fileName &, const bool followLink=true) const =0 |
Return the file mode. More... | |
virtual fileName::Type | type (const fileName &, const bool followLink=true) const =0 |
Return the file type: DIRECTORY, FILE or LINK. More... | |
virtual bool | exists (const fileName &, const bool checkGzip=true, const bool followLink=true) const =0 |
Does the name exist (as DIRECTORY or FILE) in the file system? More... | |
virtual bool | isDir (const fileName &, const bool followLink=true) const =0 |
Does the name exist as a DIRECTORY in the file system? More... | |
virtual bool | isFile (const fileName &, const bool checkGzip=true, const bool followLink=true) const =0 |
Does the name exist as a FILE in the file system? More... | |
virtual off_t | fileSize (const fileName &, const bool followLink=true) const =0 |
Return size of file. More... | |
virtual time_t | lastModified (const fileName &, const bool followLink=true) const =0 |
Return time of last file modification. More... | |
virtual double | highResLastModified (const fileName &, const bool followLink=true) const =0 |
Return time of last file modification. More... | |
virtual fileNameList | readDir (const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true, const bool followLink=true) const =0 |
Read a directory and return the entries as a string list. More... | |
virtual bool | cp (const fileName &src, const fileName &dst, const bool followLink=true) const =0 |
Copy, recursively if necessary, the source to the destination. More... | |
virtual bool | ln (const fileName &src, const fileName &dst) const =0 |
Create a softlink. dst should not exist. Returns true if. More... | |
virtual bool | mv (const fileName &src, const fileName &dst, const bool followLink=false) const =0 |
Rename src to dst. More... | |
virtual bool | mvBak (const fileName &, const std::string &ext="bak") const =0 |
Rename to a corresponding backup file. More... | |
virtual bool | rm (const fileName &) const =0 |
Remove a file, returning true if successful otherwise false. More... | |
virtual bool | rmDir (const fileName &dir, const bool silent=false) const =0 |
Remove a directory and its contents. More... | |
virtual fileName | objectPath (const IOobject &io, const word &typeName) const |
Generate disk file name for object. Opposite of filePath. More... | |
virtual fileName | filePath (const bool checkGlobal, const IOobject &, const word &typeName, const bool search=true) const =0 |
Search for an object. checkGlobal : also check undecomposed case. More... | |
virtual fileName | dirPath (const bool checkGlobal, const IOobject &io, const bool search=true) const =0 |
Search for a directory. checkGlobal : also check undecomposed. More... | |
virtual fileNameList | readObjects (const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const |
Search directory for objects. Used in IOobjectList. More... | |
virtual bool | readHeader (IOobject &, const fileName &, const word &typeName) const =0 |
Read object header from supplied file. More... | |
virtual autoPtr< ISstream > | readStream (regIOobject &, const fileName &, const word &typeName, const bool valid=true) const =0 |
Reads header for regIOobject and returns an ISstream. More... | |
virtual bool | read (regIOobject &, const bool masterOnly, const IOstream::streamFormat format, const word &typeName) const =0 |
Top-level read. More... | |
virtual bool | writeObject (const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const |
Writes a regIOobject (so header, contents and divider). More... | |
virtual fileName | filePath (const fileName &) const |
Search for a file or directory. Use IOobject version in. More... | |
virtual autoPtr< ISstream > | NewIFstream (const fileName &) const =0 |
Generate an ISstream that reads a file. More... | |
virtual autoPtr< OSstream > | NewOFstream (const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const =0 |
Generate an OSstream that writes a file. More... | |
virtual label | addWatch (const fileName &) const |
Add watching of a file. Returns handle. More... | |
virtual bool | removeWatch (const label) const |
Remove watch on a file (using handle) More... | |
virtual label | findWatch (const labelList &watchIndices, const fileName &) const |
Find index (or -1) of file in list of handles. More... | |
virtual void | addWatches (regIOobject &, const fileNameList &) const |
Helper: add watches for list of regIOobjects. More... | |
virtual fileName | getFile (const label) const |
Get name of file being watched (using handle) More... | |
virtual void | updateStates (const bool masterOnly, const bool syncPar) const |
Update state of all files. More... | |
virtual fileMonitor::fileState | getState (const label) const |
Get current state of file (using handle) More... | |
virtual void | setUnmodified (const label) const |
Set current state of file (using handle) to unmodified. More... | |
virtual word | processorsDir (const IOobject &io) const |
Actual name of processors dir (for use in mode PROCOBJECT,. More... | |
virtual word | processorsDir (const fileName &) const |
Actual name of processors dir (for use in mode PROCOBJECT,. More... | |
virtual void | setNProcs (const label nProcs) |
Set number of processor directories/results. Only used in. More... | |
virtual label | nProcs (const fileName &dir, const fileName &local="") const |
Get number of processor directories/results. Used for e.g. More... | |
virtual instantList | findTimes (const fileName &, const word &) const |
Get sorted list of times. More... | |
virtual IOobject | findInstance (const IOobject &io, const scalar startValue, const word &stopInstance) const |
Find instance where IOobject is. Fails if cannot be found. More... | |
virtual void | setTime (const Time &) const |
Callback for time change. More... | |
virtual void | flush () const |
Forcibly wait until all output done. Flush any cached data. More... | |
fileName | processorsCasePath (const IOobject &, const word &procDir) const |
Generate path (like io.path) from root+casename with any. More... | |
fileName | processorsPath (const IOobject &, const word &instance, const word &procDir) const |
Generate path (like io.path) with provided instance and any. More... | |
fileName | processorsPath (const fileName &, const word &procDir) const |
Operating on fileName: replace processorXXX with procDir. More... | |
Static Public Member Functions | |
static autoPtr< fileOperation > | New (const word &handlerType, bool verbose=false) |
Select fileHandler-type. More... | |
static instantList | sortTimes (const fileNameList &dirEntries, const word &constantName="constant") |
Sort directory entries according to time value,. More... | |
static label | splitProcessorPath (const fileName &objectPath, fileName &path, fileName &procDir, fileName &local, procRangeType &group, label &nProcs) |
Split objectPath into part before 'processor' and part after. More... | |
static label | detectProcessorPath (const fileName &objPath) |
Detect processor number from '/aa/bb/processorDDD/cc'. More... | |
Static Public Attributes | |
static const Enum< pathType > | pathTypeNames_ |
static word | processorsBaseDir = "processors" |
Return the processors directory name (usually "processors") More... | |
static word | defaultFileHandler |
Name of the default fileHandler. More... | |
static autoPtr< fileOperation > | fileHandlerPtr_ |
Static fileOperation. More... | |
Protected Member Functions | |
fileMonitor & | monitor () const |
Get or create fileMonitor singleton. More... | |
refPtr< dirIndexList > | lookupAndCacheProcessorsPath (const fileName &, const bool syncPar) const |
Lookup name of processorsDDD using cache. More... | |
virtual refPtr< dirIndexList > | lookupProcessorsPath (const fileName &objectPath) const |
Lookup name of processorsDDD using cache. More... | |
bool | exists (IOobject &io) const |
Does ioobject exist. Is either a directory (empty name()) or. More... | |
Static Protected Member Functions | |
static void | mergeTimes (const instantList &extraTimes, const word &constantName, instantList ×) |
Merge two times. More... | |
static bool | isFileOrDir (const bool isFile, const fileName &) |
Helper: check for file (isFile) or directory (!isFile) More... | |
Protected Attributes | |
const label | comm_ |
Communicator to use. More... | |
bool | distributed_ |
Distributed roots (parallel run) More... | |
HashTable< dirIndexList > | procsDirs_ |
Detected processors directories. More... | |
autoPtr< fileMonitor > | monitorPtr_ |
File-change monitor for all registered files. More... | |
A dirIndex adds the path type and local offset to a fileName.
Definition at line 103 of file fileOperation.H.
typedef List<dirIndex> dirIndexList |
Definition at line 104 of file fileOperation.H.
typedef IntRange<int> procRangeType |
For addressing a range of processors, identical to UPstream::rangeType
Definition at line 108 of file fileOperation.H.
enum pathType |
Enumeration for the location of an IOobject.
Enumerator | |
---|---|
NOTFOUND | |
ABSOLUTE | |
OBJECT | |
WRITEOBJECT | |
PROCUNCOLLATED | |
PROCBASEOBJECT | |
PROCOBJECT | |
PARENTOBJECT | |
FINDINSTANCE | |
PROCUNCOLLATEDINSTANCE | |
PROCBASEINSTANCE | |
PROCINSTANCE |
Definition at line 82 of file fileOperation.H.
|
explicit |
Construct from communicator, optionally with distributed roots.
Definition at line 568 of file fileOperation.C.
|
virtualdefault |
Destructor.
|
protected |
Get or create fileMonitor singleton.
Definition at line 246 of file fileOperation.C.
References IOobject::fileModificationChecking, IOobject::inotify, IOobject::inotifyMaster, and fileOperation::monitorPtr_.
|
staticprotected |
Merge two times.
Definition at line 264 of file fileOperation.C.
References forAll, Foam::less(), Foam::name(), List< T >::setSize(), Foam::sort(), and List< T >::transfer().
Helper: check for file (isFile) or directory (!isFile)
Definition at line 337 of file fileOperation.C.
References f(), Foam::isDir(), and Foam::isFile().
|
protected |
Lookup name of processorsDDD using cache.
Definition at line 345 of file fileOperation.C.
References DynamicList< T, SizeMin >::append(), Foam::expressions::patchExpr::debug, DebugInfo, Foam::endl(), IOobject::fileModificationChecking, Foam::constant::atomic::group, IOobject::inotifyMaster, UPstream::master(), Foam::max(), UPstream::msgType(), refPtr< T >::New(), UPstream::parRun(), path(), Foam::Pout, Foam::readDir(), Foam::returnReduce(), rp(), Pstream::scatter(), fileOperation::setNProcs(), and IOobject::timeStampMaster.
|
protectedvirtual |
Lookup name of processorsDDD using cache.
Reimplemented in uncollatedFileOperation.
Definition at line 515 of file fileOperation.C.
Does ioobject exist. Is either a directory (empty name()) or.
a file
Definition at line 522 of file fileOperation.C.
References Foam::isDir(), Foam::isFile(), IOobject::name(), word::null, IOobject::objectPath(), and IOobject::typeHeaderOk().
TypeName | ( | "fileOperation" | ) |
Runtime type information.
declareRunTimeSelectionTable | ( | autoPtr | , |
fileOperation | , | ||
word | , | ||
(bool verbose) | , | ||
(verbose) | |||
) |
|
static |
Select fileHandler-type.
Definition at line 580 of file fileOperation.C.
References Foam::abort(), DebugInFunction, Foam::endl(), Foam::FatalError, and FatalErrorInLookup.
Referenced by Foam::fileHandler(), argList::parse(), and Time::readDict().
|
static |
Sort directory entries according to time value,.
with "constant" appearing first (if it exists)
Definition at line 186 of file fileOperation.C.
References Foam::less(), and Foam::sort().
|
inlinenoexcept |
Distributed roots (parallel run)
Definition at line 238 of file fileOperation.H.
References fileOperation::distributed_.
Set distributed roots on/off, return old value.
Definition at line 244 of file fileOperation.H.
References fileOperation::distributed_.
Make directory.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Set the file mode.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Return the file mode.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
|
pure virtual |
Return the file type: DIRECTORY, FILE or LINK.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Referenced by Time::readDict().
|
pure virtual |
Does the name exist (as DIRECTORY or FILE) in the file system?
Optionally enable/disable check for gzip file.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Does the name exist as a DIRECTORY in the file system?
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
|
pure virtual |
Does the name exist as a FILE in the file system?
Optionally enable/disable check for gzip file.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Return size of file.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Return time of last file modification.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
|
pure virtual |
Return time of last file modification.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
|
pure virtual |
Read a directory and return the entries as a string list.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
|
pure virtual |
Copy, recursively if necessary, the source to the destination.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Create a softlink. dst should not exist. Returns true if.
successful.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
|
pure virtual |
Rename src to dst.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Rename to a corresponding backup file.
If the backup file already exists, attempt with "01" .. "99" suffix
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Remove a file, returning true if successful otherwise false.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Remove a directory and its contents.
silent | do not report missing directory |
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Referenced by Time::writeObject().
|
virtual |
Generate disk file name for object. Opposite of filePath.
Optional wanted typeName.
Reimplemented in collatedFileOperation.
Definition at line 607 of file fileOperation.C.
References IOobject::objectPath().
|
pure virtual |
Search for an object. checkGlobal : also check undecomposed case.
Optional wanted typeName.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Referenced by IOobject::globalFilePath(), IOobject::localFilePath(), and surfaceFormatsCore::relativeFilePath().
|
pure virtual |
Search for a directory. checkGlobal : also check undecomposed.
case
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
|
virtual |
Search directory for objects. Used in IOobjectList.
Reimplemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Definition at line 1015 of file fileOperation.C.
References objectRegistry::dbDir(), Foam::expressions::patchExpr::debug, Foam::endl(), fileName::FILE, Foam::isDir(), word::null, IOobject::objectPath(), path(), IOobject::path(), Foam::Pout, and Foam::readDir().
Referenced by IOobjectList::IOobjectList(), and masterUncollatedFileOperation::readObjects().
|
pure virtual |
Read object header from supplied file.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Referenced by regIOobject::headerOk(), and IOobject::typeHeaderOk().
|
pure virtual |
Reads header for regIOobject and returns an ISstream.
to read the contents.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
|
pure virtual |
Top-level read.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Referenced by regIOobject::read(), and regIOobject::readHeaderOk().
|
virtual |
Writes a regIOobject (so header, contents and divider).
Returns success state. Default action is to write to the objectPath using writeData. If !valid the file does not need to be written (this is used e.g. to suppress empty local lagrangian data)
Reimplemented in masterUncollatedFileOperation, and collatedFileOperation.
Definition at line 617 of file fileOperation.C.
References IOstream::good(), Foam::mkDir(), IOobject::objectPath(), regIOobject::writeData(), IOobject::writeEndDivider(), and IOobject::writeHeader().
Referenced by regIOobject::writeObject().
|
virtual |
Search for a file or directory. Use IOobject version in.
preference
Definition at line 661 of file fileOperation.C.
References Foam::expressions::patchExpr::debug, Foam::endl(), Foam::exists(), Foam::constant::atomic::group, fileName::null, path(), Foam::Pout, and WarningInFunction.
Generate an ISstream that reads a file.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
Referenced by openFoamTableReader< Type >::operator()().
|
pure virtual |
Generate an OSstream that writes a file.
Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.
|
virtual |
Add watching of a file. Returns handle.
Reimplemented in masterUncollatedFileOperation.
Definition at line 717 of file fileOperation.C.
|
virtual |
Remove watch on a file (using handle)
Reimplemented in masterUncollatedFileOperation.
Definition at line 723 of file fileOperation.C.
Referenced by regIOobject::addWatch(), regIOobject::checkOut(), regIOobject::read(), Time::readDict(), and Time::~Time().
Find index (or -1) of file in list of handles.
Reimplemented in masterUncollatedFileOperation.
Definition at line 730 of file fileOperation.C.
References forAll.
Referenced by regIOobject::addWatch().
|
virtual |
Helper: add watches for list of regIOobjects.
Reimplemented in masterUncollatedFileOperation.
Definition at line 747 of file fileOperation.C.
References DynamicList< T, SizeMin >::append(), HashTable< T, Key, Hash >::erase(), f(), and regIOobject::watchIndices().
Referenced by Time::read(), Time::readDict(), Time::readModifiedObjects(), and Time::setMonitoring().
|
virtual |
Get name of file being watched (using handle)
Reimplemented in masterUncollatedFileOperation.
Definition at line 783 of file fileOperation.C.
Referenced by regIOobject::addWatch(), regIOobject::read(), Time::readDict(), and regIOobject::readIfModified().
Update state of all files.
Reimplemented in masterUncollatedFileOperation.
Definition at line 790 of file fileOperation.C.
References UPstream::parRun().
Referenced by Time::readModifiedObjects().
|
virtual |
Get current state of file (using handle)
Reimplemented in masterUncollatedFileOperation.
Definition at line 800 of file fileOperation.C.
|
virtual |
Set current state of file (using handle) to unmodified.
Reimplemented in masterUncollatedFileOperation.
Definition at line 808 of file fileOperation.C.
Referenced by regIOobject::writeObject().
Actual name of processors dir (for use in mode PROCOBJECT,.
PROCINSTANCE)
Reimplemented in collatedFileOperation.
Definition at line 513 of file fileOperation.H.
Actual name of processors dir (for use in mode PROCOBJECT,.
PROCINSTANCE)
Reimplemented in collatedFileOperation.
Definition at line 520 of file fileOperation.H.
|
virtual |
Set number of processor directories/results. Only used in.
decomposePar
Reimplemented in collatedFileOperation.
Definition at line 1054 of file fileOperation.C.
Referenced by fileOperation::lookupAndCacheProcessorsPath().
Get number of processor directories/results. Used for e.g.
reconstructPar, argList checking
Definition at line 1059 of file fileOperation.C.
References Foam::endl(), Foam::constant::atomic::group, Foam::isDir(), Foam::isFile(), UPstream::master(), Foam::max(), polyMesh::meshSubDir, UPstream::msgType(), decomposedBlockData::numBlocks(), Foam::readDir(), rp(), Pstream::scatter(), and WarningInFunction.
|
virtual |
Get sorted list of times.
Reimplemented in masterUncollatedFileOperation.
Definition at line 815 of file fileOperation.C.
References Foam::expressions::patchExpr::debug, fileName::DIRECTORY, Foam::endl(), Foam::Pout, and Foam::readDir().
Referenced by TimePaths::findTimes(), masterUncollatedFileOperation::findTimes(), and masterUncollatedFileOperation::readObjects().
|
virtual |
Find instance where IOobject is. Fails if cannot be found.
and readOpt() is MUST_READ/MUST_READ_IF_MODIFIED. Otherwise returns stopInstance.
Reimplemented in masterUncollatedFileOperation.
Definition at line 868 of file fileOperation.C.
References TimePaths::constant(), DebugInFunction, Foam::endl(), Foam::exists(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, IOobject::instance(), IOobject::local(), IOobject::MUST_READ, IOobject::MUST_READ_IF_MODIFIED, IOobject::name(), IOobject::readOpt(), IOobject::time(), and TimePaths::times().
|
inlinevirtual |
Callback for time change.
Reimplemented in masterUncollatedFileOperation.
Definition at line 551 of file fileOperation.H.
Referenced by Time::setTime(), and masterUncollatedFileOperation::setTime().
|
virtual |
Forcibly wait until all output done. Flush any cached data.
Reimplemented in masterUncollatedFileOperation, and collatedFileOperation.
Definition at line 1120 of file fileOperation.C.
References Foam::expressions::patchExpr::debug, Foam::endl(), and Foam::Pout.
Referenced by masterUncollatedFileOperation::flush().
Foam::fileName processorsCasePath | ( | const IOobject & | io, |
const word & | procDir | ||
) | const |
Generate path (like io.path) from root+casename with any.
'processorXXX' replaced by procDir (usually 'processsors')
Definition at line 1132 of file fileOperation.C.
References TimePaths::globalCaseName(), IOobject::rootPath(), and IOobject::time().
Foam::fileName processorsPath | ( | const IOobject & | io, |
const word & | instance, | ||
const word & | procDir | ||
) | const |
Generate path (like io.path) with provided instance and any.
'processorXXX' replaced by procDir (usually 'processsors')
Definition at line 1142 of file fileOperation.C.
References IOobject::db(), objectRegistry::dbDir(), and IOobject::local().
Foam::fileName processorsPath | ( | const fileName & | dir, |
const word & | procDir | ||
) | const |
Operating on fileName: replace processorXXX with procDir.
Definition at line 1157 of file fileOperation.C.
References Foam::endl(), fileName::name(), fileName::null, fileName::path(), and WarningInFunction.
|
static |
Split objectPath into part before 'processor' and part after.
Returns -1 or processor number and optionally number of processors. Use with care.
Definition at line 1183 of file fileOperation.C.
References Foam::constant::atomic::group, path(), Foam::pos(), and Foam::read().
|
static |
Detect processor number from '/aa/bb/processorDDD/cc'.
Definition at line 1343 of file fileOperation.C.
References Foam::constant::atomic::group, and path().
|
static |
Definition at line 99 of file fileOperation.H.
Referenced by masterUncollatedFileOperation::filePath().
|
protected |
Communicator to use.
Definition at line 116 of file fileOperation.H.
|
protected |
Distributed roots (parallel run)
Definition at line 119 of file fileOperation.H.
Referenced by fileOperation::distributed().
|
mutableprotected |
Detected processors directories.
Definition at line 122 of file fileOperation.H.
|
mutableprotected |
File-change monitor for all registered files.
Definition at line 125 of file fileOperation.H.
Referenced by fileOperation::monitor().
|
static |
Return the processors directory name (usually "processors")
Definition at line 170 of file fileOperation.H.
|
static |
Name of the default fileHandler.
Definition at line 173 of file fileOperation.H.
Referenced by argList::argList(), Foam::fileHandler(), and argList::parse().
|
static |
Static fileOperation.
Definition at line 183 of file fileOperation.H.
Referenced by Foam::fileHandler(), and argList::parse().