Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
fileOperation Class Referenceabstract

An encapsulation of filesystem-related operations. More...

Inheritance diagram for fileOperation:
Inheritance graph
[legend]
Collaboration diagram for fileOperation:
Collaboration graph
[legend]

Public Types

enum  pathType : int {
  NOTFOUND = 0, ABSOLUTE, OBJECT, WRITEOBJECT,
  PROCUNCOLLATED, PROCBASEOBJECT = PROCUNCOLLATED + 1, PROCOBJECT = PROCBASEOBJECT + 1, PARENTOBJECT,
  FINDINSTANCE, PROCUNCOLLATEDINSTANCE, PROCBASEINSTANCE, PROCINSTANCE
}
 
typedef Tuple2< fileName, Tuple2< pathType, int > > dirIndex
 
typedef List< dirIndexdirIndexList
 
typedef IntRange< int > procRangeType
 

Public Member Functions

 TypeName ("fileOperation")
 
 fileOperation (const label comm, const bool distributedRoots=false)
 
 declareRunTimeSelectionTable (autoPtr, fileOperation, word,(bool verbose),(verbose))
 
virtual ~fileOperation ()=default
 
bool distributed () const noexcept
 
bool distributed (bool on) const noexcept
 
virtual bool mkDir (const fileName &, mode_t=0777) const =0
 
virtual bool chMod (const fileName &, const mode_t) const =0
 
virtual mode_t mode (const fileName &, const bool followLink=true) const =0
 
virtual fileName::Type type (const fileName &, const bool followLink=true) const =0
 
virtual bool exists (const fileName &, const bool checkGzip=true, const bool followLink=true) const =0
 
virtual bool isDir (const fileName &, const bool followLink=true) const =0
 
virtual bool isFile (const fileName &, const bool checkGzip=true, const bool followLink=true) const =0
 
virtual off_t fileSize (const fileName &, const bool followLink=true) const =0
 
virtual time_t lastModified (const fileName &, const bool followLink=true) const =0
 
virtual double highResLastModified (const fileName &, const bool followLink=true) const =0
 
virtual fileNameList readDir (const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true, const bool followLink=true) const =0
 
virtual bool cp (const fileName &src, const fileName &dst, const bool followLink=true) const =0
 
virtual bool ln (const fileName &src, const fileName &dst) const =0
 
virtual bool mv (const fileName &src, const fileName &dst, const bool followLink=false) const =0
 
virtual bool mvBak (const fileName &, const std::string &ext="bak") const =0
 
virtual bool rm (const fileName &) const =0
 
virtual bool rmDir (const fileName &dir, const bool silent=false) const =0
 
virtual fileName objectPath (const IOobject &io, const word &typeName) const
 
virtual fileName filePath (const bool checkGlobal, const IOobject &, const word &typeName, const bool search=true) const =0
 
virtual fileName dirPath (const bool checkGlobal, const IOobject &io, const bool search=true) const =0
 
virtual fileNameList readObjects (const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
 
virtual bool readHeader (IOobject &, const fileName &, const word &typeName) const =0
 
virtual autoPtr< ISstreamreadStream (regIOobject &, const fileName &, const word &typeName, const bool valid=true) const =0
 
virtual bool read (regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const =0
 
virtual bool writeObject (const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
 
virtual fileName filePath (const fileName &) const
 
virtual autoPtr< ISstreamNewIFstream (const fileName &) const =0
 
virtual autoPtr< OSstreamNewOFstream (const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const =0
 
virtual label addWatch (const fileName &) const
 
virtual bool removeWatch (const label) const
 
virtual label findWatch (const labelList &watchIndices, const fileName &) const
 
virtual void addWatches (regIOobject &, const fileNameList &) const
 
virtual fileName getFile (const label) const
 
virtual void updateStates (const bool masterOnly, const bool syncPar) const
 
virtual fileMonitor::fileState getState (const label) const
 
virtual void setUnmodified (const label) const
 
virtual word processorsDir (const IOobject &io) const
 
virtual word processorsDir (const fileName &) const
 
virtual void setNProcs (const label nProcs)
 
virtual label nProcs (const fileName &dir, const fileName &local="") const
 
virtual instantList findTimes (const fileName &, const word &) const
 
virtual IOobject findInstance (const IOobject &io, const scalar startValue, const word &stopInstance) const
 
virtual void setTime (const Time &) const
 
virtual void flush () const
 
fileName processorsCasePath (const IOobject &, const word &procDir) const
 
fileName processorsPath (const IOobject &, const word &instance, const word &procDir) const
 
fileName processorsPath (const fileName &, const word &procDir) const
 

Static Public Member Functions

static autoPtr< fileOperationNewUncollated ()
 
static autoPtr< fileOperationNew (const word &handlerType, bool verbose=false)
 
static instantList sortTimes (const fileNameList &dirEntries, const word &constantName="constant")
 
static label splitProcessorPath (const fileName &objectPath, fileName &path, fileName &procDir, fileName &local, procRangeType &group, label &nProcs)
 
static label detectProcessorPath (const fileName &objPath)
 

Static Public Attributes

static const Enum< pathTypepathTypeNames_
 
static word processorsBaseDir = "processors"
 
static word defaultFileHandler
 
static autoPtr< fileOperationfileHandlerPtr_
 

Protected Member Functions

fileMonitormonitor () const
 
refPtr< dirIndexListlookupAndCacheProcessorsPath (const fileName &objectPath, const bool syncPar) const
 
virtual refPtr< dirIndexListlookupProcessorsPath (const fileName &objectPath) const
 
bool exists (IOobject &io) const
 

Static Protected Member Functions

static labelList ioRanks ()
 
static void mergeTimes (const instantList &extraTimes, const word &constantName, instantList &times)
 
static bool isFileOrDir (const bool isFile, const fileName &)
 

Protected Attributes

const label comm_
 
bool distributed_
 
HashTable< dirIndexListprocsDirs_
 
autoPtr< fileMonitormonitorPtr_
 

Detailed Description

An encapsulation of filesystem-related operations.

Definition at line 63 of file fileOperation.H.

Member Typedef Documentation

◆ dirIndex

Definition at line 93 of file fileOperation.H.

◆ dirIndexList

Definition at line 94 of file fileOperation.H.

◆ procRangeType

typedef IntRange<int> procRangeType

Definition at line 98 of file fileOperation.H.

Member Enumeration Documentation

◆ pathType

enum pathType : int
Enumerator
NOTFOUND 

Not found.

ABSOLUTE 

instance is absolute directory

OBJECT 

io.objectPath() exists

WRITEOBJECT 

write path exists

PROCUNCOLLATED 

objectPath exists in 'processorN'

PROCBASEOBJECT 

objectPath exists in 'processorsNN'

PROCOBJECT 

objectPath exists in 'processorsNN_first-last'

PARENTOBJECT 

parent of object path

FINDINSTANCE 

file found in time directory

PROCUNCOLLATEDINSTANCE 

as PROCUNCOLLATED but with instance

PROCBASEINSTANCE 

as PROCBASEOBJECT but with instance

PROCINSTANCE 

as PROCOBJECT but with instance

Definition at line 68 of file fileOperation.H.

Constructor & Destructor Documentation

◆ fileOperation()

fileOperation ( const label  comm,
const bool  distributedRoots = false 
)
explicit

Definition at line 687 of file fileOperation.C.

◆ ~fileOperation()

virtual ~fileOperation ( )
virtualdefault

Member Function Documentation

◆ monitor()

Foam::fileMonitor & monitor ( ) const
protected

◆ ioRanks()

Foam::labelList ioRanks ( )
staticprotected

Definition at line 215 of file fileOperation.C.

References Foam::getEnv().

Here is the call graph for this function:

◆ mergeTimes()

void mergeTimes ( const instantList extraTimes,
const word constantName,
instantList times 
)
staticprotected

Definition at line 309 of file fileOperation.C.

References forAll, Foam::less(), Foam::name(), List::setSize(), Foam::sort(), and List::transfer().

Here is the call graph for this function:

◆ isFileOrDir()

bool isFileOrDir ( const bool  isFile,
const fileName f 
)
staticprotected

Definition at line 382 of file fileOperation.C.

References f(), Foam::isDir(), and Foam::isFile().

Here is the call graph for this function:

◆ lookupAndCacheProcessorsPath()

Foam::refPtr< Foam::fileOperation::dirIndexList > lookupAndCacheProcessorsPath ( const fileName objectPath,
const bool  syncPar 
) const
protected

◆ lookupProcessorsPath()

Foam::refPtr< Foam::fileOperation::dirIndexList > lookupProcessorsPath ( const fileName objectPath) const
protectedvirtual

Reimplemented in uncollatedFileOperation.

Definition at line 634 of file fileOperation.C.

◆ exists() [1/2]

bool exists ( IOobject io) const
protected

Definition at line 641 of file fileOperation.C.

References Foam::isDir(), Foam::isFile(), IOobject::name(), word::null, IOobject::objectPath(), and IOobject::typeHeaderOk().

Here is the call graph for this function:

◆ TypeName()

TypeName ( "fileOperation"  )

◆ NewUncollated()

Foam::autoPtr< Foam::fileOperation > NewUncollated ( )
static

Definition at line 1467 of file fileOperation.C.

Referenced by faMeshReconstructor::writeMesh().

Here is the caller graph for this function:

◆ declareRunTimeSelectionTable()

declareRunTimeSelectionTable ( autoPtr  ,
fileOperation  ,
word  ,
(bool verbose)  ,
(verbose)   
)

◆ New()

Foam::autoPtr< Foam::fileOperation > New ( const word handlerType,
bool  verbose = false 
)
static

Definition at line 699 of file fileOperation.C.

References Foam::abort(), DebugInFunction, Foam::endl(), Foam::FatalError, and FatalErrorInLookup.

Referenced by Foam::fileHandler(), argList::parse(), and Time::readDict().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sortTimes()

Foam::instantList sortTimes ( const fileNameList dirEntries,
const word constantName = "constant" 
)
static

Definition at line 231 of file fileOperation.C.

References Foam::less(), List::resize(), and Foam::sort().

Here is the call graph for this function:

◆ distributed() [1/2]

bool distributed ( ) const
inlinenoexcept

Definition at line 234 of file fileOperation.H.

References fileOperation::distributed_.

Referenced by if(), and faMeshReconstructor::writeMesh().

Here is the caller graph for this function:

◆ distributed() [2/2]

bool distributed ( bool  on) const
noexcept

Definition at line 725 of file fileOperation.C.

◆ mkDir()

virtual bool mkDir ( const fileName ,
mode_t  = 0777 
) const
pure virtual

◆ chMod()

virtual bool chMod ( const fileName ,
const  mode_t 
) const
pure virtual

◆ mode()

virtual mode_t mode ( const fileName ,
const bool  followLink = true 
) const
pure virtual

◆ type()

virtual fileName::Type type ( const fileName ,
const bool  followLink = true 
) const
pure virtual

◆ exists() [2/2]

virtual bool exists ( const fileName ,
const bool  checkGzip = true,
const bool  followLink = true 
) const
pure virtual

◆ isDir()

virtual bool isDir ( const fileName ,
const bool  followLink = true 
) const
pure virtual

◆ isFile()

virtual bool isFile ( const fileName ,
const bool  checkGzip = true,
const bool  followLink = true 
) const
pure virtual

◆ fileSize()

virtual off_t fileSize ( const fileName ,
const bool  followLink = true 
) const
pure virtual

◆ lastModified()

virtual time_t lastModified ( const fileName ,
const bool  followLink = true 
) const
pure virtual

◆ highResLastModified()

virtual double highResLastModified ( const fileName ,
const bool  followLink = true 
) const
pure virtual

◆ readDir()

virtual fileNameList readDir ( const fileName ,
const fileName::Type  = fileName::FILE,
const bool  filtergz = true,
const bool  followLink = true 
) const
pure virtual

◆ cp()

virtual bool cp ( const fileName src,
const fileName dst,
const bool  followLink = true 
) const
pure virtual

◆ ln()

virtual bool ln ( const fileName src,
const fileName dst 
) const
pure virtual

◆ mv()

virtual bool mv ( const fileName src,
const fileName dst,
const bool  followLink = false 
) const
pure virtual

◆ mvBak()

virtual bool mvBak ( const fileName ,
const std::string &  ext = "bak" 
) const
pure virtual

◆ rm()

virtual bool rm ( const fileName ) const
pure virtual

◆ rmDir()

virtual bool rmDir ( const fileName dir,
const bool  silent = false 
) const
pure virtual

Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.

Referenced by Time::writeObject().

Here is the caller graph for this function:

◆ objectPath()

Foam::fileName objectPath ( const IOobject io,
const word typeName 
) const
virtual

Reimplemented in collatedFileOperation.

Definition at line 734 of file fileOperation.C.

References IOobject::objectPath().

Here is the call graph for this function:

◆ filePath() [1/2]

virtual fileName filePath ( const bool  checkGlobal,
const IOobject ,
const word typeName,
const bool  search = true 
) const
pure virtual

◆ dirPath()

virtual fileName dirPath ( const bool  checkGlobal,
const IOobject io,
const bool  search = true 
) const
pure virtual

◆ readObjects()

Foam::fileNameList readObjects ( const objectRegistry db,
const fileName instance,
const fileName local,
word newInstance 
) const
virtual

◆ readHeader()

virtual bool readHeader ( IOobject ,
const fileName ,
const word typeName 
) const
pure virtual

Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.

Referenced by regIOobject::headerOk(), and IOobject::typeHeaderOk().

Here is the caller graph for this function:

◆ readStream()

virtual autoPtr<ISstream> readStream ( regIOobject ,
const fileName ,
const word typeName,
const bool  valid = true 
) const
pure virtual

◆ read()

virtual bool read ( regIOobject ,
const bool  masterOnly,
const IOstreamOption::streamFormat  format,
const word typeName 
) const
pure virtual

Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.

Referenced by regIOobject::read(), and regIOobject::readHeaderOk().

Here is the caller graph for this function:

◆ writeObject()

bool writeObject ( const regIOobject io,
IOstreamOption  streamOpt = IOstreamOption(),
const bool  valid = true 
) const
virtual

Reimplemented in masterUncollatedFileOperation, and collatedFileOperation.

Definition at line 744 of file fileOperation.C.

References IOstream::good(), Foam::mkDir(), IOobject::objectPath(), os(), fileName::path(), regIOobject::writeData(), IOobject::writeEndDivider(), and IOobject::writeHeader().

Referenced by STDMD::initialise(), and regIOobject::writeObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filePath() [2/2]

Foam::fileName filePath ( const fileName fName) const
virtual

Definition at line 788 of file fileOperation.C.

References Foam::expressions::patchExpr::debug, Foam::endl(), Foam::exists(), Foam::constant::atomic::group, fileName::null, path(), Foam::Pout, and WarningInFunction.

Here is the call graph for this function:

◆ NewIFstream()

virtual autoPtr<ISstream> NewIFstream ( const fileName ) const
pure virtual

Implemented in masterUncollatedFileOperation, and uncollatedFileOperation.

Referenced by openFoamTableReader< Type >::operator()().

Here is the caller graph for this function:

◆ NewOFstream()

virtual autoPtr<OSstream> NewOFstream ( const fileName pathname,
IOstreamOption  streamOpt = IOstreamOption(),
const bool  valid = true 
) const
pure virtual

◆ addWatch()

Foam::label addWatch ( const fileName fName) const
virtual

Reimplemented in masterUncollatedFileOperation.

Definition at line 844 of file fileOperation.C.

◆ removeWatch()

bool removeWatch ( const label  watchIndex) const
virtual

Reimplemented in masterUncollatedFileOperation.

Definition at line 850 of file fileOperation.C.

Referenced by regIOobject::addWatch(), regIOobject::checkOut(), regIOobject::read(), Time::readDict(), and Time::~Time().

Here is the caller graph for this function:

◆ findWatch()

Foam::label findWatch ( const labelList watchIndices,
const fileName fName 
) const
virtual

Reimplemented in masterUncollatedFileOperation.

Definition at line 857 of file fileOperation.C.

References forAll.

Referenced by regIOobject::addWatch().

Here is the caller graph for this function:

◆ addWatches()

void addWatches ( regIOobject rio,
const fileNameList files 
) const
virtual

Reimplemented in masterUncollatedFileOperation.

Definition at line 874 of file fileOperation.C.

References DynamicList::append(), f(), and regIOobject::watchIndices().

Referenced by Time::read(), Time::readDict(), Time::readModifiedObjects(), and Time::setMonitoring().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFile()

Foam::fileName getFile ( const label  watchIndex) const
virtual

Reimplemented in masterUncollatedFileOperation.

Definition at line 910 of file fileOperation.C.

Referenced by regIOobject::addWatch(), regIOobject::read(), Time::readDict(), and regIOobject::readIfModified().

Here is the caller graph for this function:

◆ updateStates()

void updateStates ( const bool  masterOnly,
const bool  syncPar 
) const
virtual

Reimplemented in masterUncollatedFileOperation.

Definition at line 917 of file fileOperation.C.

References UPstream::parRun().

Referenced by Time::readModifiedObjects().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getState()

Foam::fileMonitor::fileState getState ( const label  watchFd) const
virtual

Reimplemented in masterUncollatedFileOperation.

Definition at line 927 of file fileOperation.C.

◆ setUnmodified()

void setUnmodified ( const label  watchFd) const
virtual

Reimplemented in masterUncollatedFileOperation.

Definition at line 935 of file fileOperation.C.

Referenced by regIOobject::writeObject().

Here is the caller graph for this function:

◆ processorsDir() [1/2]

virtual word processorsDir ( const IOobject io) const
inlinevirtual

Reimplemented in collatedFileOperation.

Definition at line 505 of file fileOperation.H.

References fileOperation::processorsBaseDir.

◆ processorsDir() [2/2]

virtual word processorsDir ( const fileName ) const
inlinevirtual

Reimplemented in collatedFileOperation.

Definition at line 512 of file fileOperation.H.

References fileOperation::processorsBaseDir.

◆ setNProcs()

void setNProcs ( const label  nProcs)
virtual

Reimplemented in collatedFileOperation.

Definition at line 1181 of file fileOperation.C.

Referenced by fileOperation::lookupAndCacheProcessorsPath().

Here is the caller graph for this function:

◆ nProcs()

Foam::label nProcs ( const fileName dir,
const fileName local = "" 
) const
virtual

◆ findTimes()

Foam::instantList findTimes ( const fileName directory,
const word constantName 
) const
virtual

Reimplemented in masterUncollatedFileOperation.

Definition at line 942 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findInstance()

Foam::IOobject findInstance ( const IOobject io,
const scalar  startValue,
const word stopInstance 
) const
virtual

◆ setTime()

virtual void setTime ( const Time ) const
inlinevirtual

Reimplemented in masterUncollatedFileOperation.

Definition at line 543 of file fileOperation.H.

Referenced by Time::setTime(), and masterUncollatedFileOperation::setTime().

Here is the caller graph for this function:

◆ flush()

void flush ( ) const
virtual

Reimplemented in masterUncollatedFileOperation, and collatedFileOperation.

Definition at line 1233 of file fileOperation.C.

References Foam::expressions::patchExpr::debug, Foam::endl(), and Foam::Pout.

Referenced by masterUncollatedFileOperation::flush().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processorsCasePath()

Foam::fileName processorsCasePath ( const IOobject io,
const word procDir 
) const

Definition at line 1245 of file fileOperation.C.

References TimePaths::globalCaseName(), IOobject::rootPath(), and IOobject::time().

Here is the call graph for this function:

◆ processorsPath() [1/2]

Foam::fileName processorsPath ( const IOobject io,
const word instance,
const word procDir 
) const

Definition at line 1255 of file fileOperation.C.

References IOobject::db(), objectRegistry::dbDir(), and IOobject::local().

Here is the call graph for this function:

◆ processorsPath() [2/2]

Foam::fileName processorsPath ( const fileName dir,
const word procDir 
) const

Definition at line 1270 of file fileOperation.C.

References Foam::endl(), fileName::name(), fileName::null, fileName::path(), string::starts_with(), and WarningInFunction.

Here is the call graph for this function:

◆ splitProcessorPath()

Foam::label splitProcessorPath ( const fileName objectPath,
fileName path,
fileName procDir,
fileName local,
procRangeType group,
label &  nProcs 
)
static

Definition at line 1296 of file fileOperation.C.

References Foam::constant::atomic::group, path(), Foam::pos(), and Foam::read().

Here is the call graph for this function:

◆ detectProcessorPath()

Foam::label detectProcessorPath ( const fileName objPath)
static

Definition at line 1456 of file fileOperation.C.

References Foam::constant::atomic::group, and path().

Here is the call graph for this function:

Member Data Documentation

◆ pathTypeNames_

const Foam::Enum< Foam::fileOperation::pathType > pathTypeNames_
static

Definition at line 90 of file fileOperation.H.

Referenced by masterUncollatedFileOperation::filePath().

◆ comm_

const label comm_
protected

Definition at line 106 of file fileOperation.H.

◆ distributed_

bool distributed_
mutableprotected

Definition at line 109 of file fileOperation.H.

Referenced by fileOperation::distributed().

◆ procsDirs_

HashTable<dirIndexList> procsDirs_
mutableprotected

Definition at line 112 of file fileOperation.H.

◆ monitorPtr_

autoPtr<fileMonitor> monitorPtr_
mutableprotected

Definition at line 115 of file fileOperation.H.

◆ processorsBaseDir

Foam::word processorsBaseDir = "processors"
static

Definition at line 163 of file fileOperation.H.

Referenced by fileOperation::processorsDir().

◆ defaultFileHandler

word defaultFileHandler
static

Definition at line 166 of file fileOperation.H.

Referenced by argList::argList(), Foam::fileHandler(), and argList::parse().

◆ fileHandlerPtr_

Foam::autoPtr< Foam::fileOperation > fileHandlerPtr_
static

Definition at line 176 of file fileOperation.H.

Referenced by Foam::fileHandler(), and argList::parse().


The documentation for this class was generated from the following files: