40 namespace fileOperations
48 fileOperationInitialise,
59 Foam::fileName Foam::fileOperations::uncollatedFileOperation::filePathInfo
61 const bool globalFile,
66 if (io.instance().isAbsolute())
68 fileName objectPath = io.instance()/io.
name();
70 if (isFileOrDir(isFile, objectPath))
81 fileName path = io.
path(globalFile);
82 fileName objectPath = path/io.
name();
84 if (isFileOrDir(isFile, objectPath))
93 && io.time().processorCase()
95 io.instance() == io.time().system()
96 || io.instance() == io.time().constant()
102 fileName parentObjectPath =
103 io.rootPath()/io.time().globalCaseName()
104 /io.instance()/io.db().dbDir()/io.local()/io.name();
106 if (isFileOrDir(isFile, parentObjectPath))
108 return parentObjectPath;
113 if (io.time().processorCase())
115 tmpNrc<dirIndexList> pDirs
117 lookupProcessorsPath(io.objectPath(globalFile))
121 const fileName& pDir = pDirs()[i].first();
123 processorsPath(io, io.instance(), pDir)
125 if (objPath != objectPath && isFileOrDir(isFile, objPath))
137 word newInstancePath = io.time().findInstancePath
139 instant(io.instance())
142 if (newInstancePath.size())
146 io.rootPath()/io.caseName(globalFile)
147 /newInstancePath/io.db().dbDir()/io.local()/io.name()
150 if (isFileOrDir(isFile, fName))
210 const bool checkVariants,
211 const bool followLink
214 return Foam::mode(fName, checkVariants, followLink);
221 const bool checkVariants,
222 const bool followLink
225 return Foam::type(fName, checkVariants, followLink);
232 const bool checkVariants,
233 const bool followLink
243 const bool followLink
253 const bool checkVariants,
254 const bool followLink
264 const bool checkVariants,
265 const bool followLink
275 const bool checkVariants,
276 const bool followLink
286 const bool checkVariants,
287 const bool followLink
297 const std::string& ext
327 const bool followLink
338 const bool followLink
341 return Foam::cp(src, dst, followLink);
359 const bool followLink
362 return Foam::mv(src, dst, followLink);
368 const bool globalFile,
375 Pout<<
"uncollatedFileOperation::filePath :" 376 <<
" objectPath:" << io.
objectPath(globalFile)
377 <<
" globalFile:" << globalFile <<
endl;
380 fileName objPath(filePathInfo(globalFile,
true, io));
384 Pout<<
"uncollatedFileOperation::filePath :" 385 <<
" Returning from file searching:" <<
endl 387 <<
" filePath :" << objPath <<
endl <<
endl;
395 const bool globalFile,
401 Pout<<
"uncollatedFileOperation::dirPath :" 402 <<
" objectPath:" << io.
objectPath(globalFile)
403 <<
" globalFile:" << globalFile <<
endl;
406 fileName objPath(filePathInfo(globalFile,
false, io));
410 Pout<<
"uncollatedFileOperation::dirPath :" 411 <<
" Returning from directory searching:" <<
endl 413 <<
" dirPath :" << objPath <<
endl <<
endl;
429 Pout<<
"uncollatedFileOperation::readObjects :" 431 <<
" instance:" << instance <<
endl;
440 if (newInstance.empty())
444 if (!newInst.empty() && newInst != instance)
459 Pout<<
"uncollatedFileOperation::readObjects :" 460 <<
" newInstance:" << newInstance
461 <<
" objectNames:" << objectNames <<
endl;
477 Pout<<
"uncollatedFileOperation::readHeader :" 478 <<
" fName:" << fName
479 <<
" typeName:" << typeName <<
endl;
486 <<
"file for object " << io.
name() <<
" could not be opened" 495 if (!isPtr.
valid() || !isPtr->good())
510 Pout<<
"uncollatedFileOperation::readHeader :" 511 <<
" for fName:" << fName
525 const word& typeName,
544 isPtr = NewIFstream(fName);
546 if (!isPtr.
valid() || !isPtr->good())
550 "uncollatedFileOperation::readStream()",
555 ) <<
"cannot open file" 561 <<
"problem while reading header for object " << io.
name()
578 <<
"could not detect processor number" 580 <<
" fName:" << fName
588 label groupStart, groupSize, nProcs;
599 if (groupStart != -1 && groupSize > 0)
601 proci = proci-groupStart;
613 const bool masterOnly,
628 Pout<<
"uncollatedFileOperation::read :" 630 <<
" from file " <<
endl;
634 Istream& is = io.readStream(typeName);
650 Pout<<
"uncollatedFileOperation::read :" 652 <<
" from file " <<
endl;
665 std::underlying_type_t<IOstream::streamFormat> formatValue(format);
680 if (myComm.
above() != -1)
700 myComm.
below()[belowI],
738 new OFstream(filePath, format, version, compression)
time_t lastModified(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return time of last file modification.
const labelList & below() const
bool exists(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist (as directory or file) in the file system?
#define forAll(list, i)
Loop across all elements in list.
mode_t mode(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file mode.
bool mv(const fileName &src, const fileName &dst, const bool followLink=false)
Rename src to dst.
const word & name() const
Return name.
A class for handling file names.
virtual fileNameList readDir(const fileName &, const fileType=fileType::file, const bool filtergz=true, const bool followLink=true) const
Read a directory and return the entries as a string list.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
virtual fileName dirPath(const bool globalFile, const IOobject &) const
Search for a directory. globalFile : also check undecomposed.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist as a file in the file system?
#define InfoHeader
Report write to Foam::Info if the local log switch is true.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
static const fileName null
An empty fileName.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
virtual double highResLastModified(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return time of last file modification.
static int nProcsSimpleSum
Number of processors at which the sum algorithm changes from linear.
virtual off_t fileSize(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return size of file.
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
Ostream & endl(Ostream &os)
Add newline and flush stream.
fileName objectPath() const
Return complete path + object name.
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy, recursively if necessary, the source to the destination.
static bool master(const label communicator=0)
Am I the master process.
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
virtual fileName filePath(const bool globalFile, const IOobject &, const word &typeName) const
Search for an object. globalFile : also check undecomposed case.
word format(conversionProperties.lookup("format"))
static int & msgType()
Message tag of standard messages.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
static label worldComm
Default communicator (all processors)
static const List< commsStruct > & linearCommunication(const label communicator=0)
Communication schedule for linear all-to-master (proc 0)
bool mvBak(const fileName &, const std::string &ext="bak")
Rename to a corresponding backup file.
virtual fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return the file type: directory, file or link.
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(fileOperationInitialise, collatedFileOperationInitialise, word, collated)
virtual bool rmDir(const fileName &) const
Remove a directory and its contents.
Input inter-processor communications stream.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool read=true) const
Reads header for regIOobject and returns an ISstream.
virtual autoPtr< ISstream > NewIFstream(const fileName &filePath, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion) const
Generate an ISstream that reads a file.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool readHeader(Istream &)
Read header.
string & note()
Return non-constant access to the optional note.
virtual bool read(regIOobject &, const bool masterOnly, const IOstream::streamFormat defaultFormat, const word &typeName) const
Top-level read.
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a directory in the file system?
void close()
Close Istream.
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
A class for handling words, derived from string.
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
word name() const
Return file name (part beyond last /)
streamFormat
Enumeration for the format of data in the stream.
static const List< commsStruct > & treeCommunication(const label communicator=0)
Communication schedule for tree all-to-master (proc 0)
streamFormat format() const
Return current stream format.
fileType
Enumeration of file types.
fileNameList readDir(const fileName &, const fileType=fileType::file, const bool filterVariants=true, const bool followLink=true)
Read a directory and return the entries as a string list.
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
Structure for communicating between processors.
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
compressionType
Enumeration for the format of data in the stream.
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
bool rmDir(const fileName &)
Remove a directory and its contents.
virtual time_t lastModified(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return time of last file modification.
const Time & time() const
Return time.
Output inter-processor communications stream.
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
uncollatedFileOperation(const bool verbose)
Construct null.
virtual mode_t mode(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return the file mode.
virtual ~uncollatedFileOperation()
Destructor.
An instant of time. Contains the time value and name.
static autoPtr< ISstream > readBlock(const label blocki, Istream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
static bool & parRun()
Is this a parallel run?
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static bool readMasterHeader(IOobject &, Istream &)
Read header. Call only on master.
virtual bool exists(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Does the name exist (as directory or file) in the file system?
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
virtual bool readData(Istream &)
Virtual readData function.
double highResLastModified(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return time of last file modification.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
prefixOSstream Pout(cout, "Pout")
bool chMod(const fileName &, const mode_t)
Set the file mode.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
fileName path() const
Return directory path name (part before last /)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
off_t fileSize(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return size of file.
defineTypeNameAndDebug(collatedFileOperation, 0)
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Registry of regIOobjects.
virtual bool writeData(Ostream &) const =0
Pure virtual writaData function.
word findInstancePath(const fileName &path, const instant &) const
Search the case for the time directory path.
Dummy stream for input. Aborts at any attempt to read from it.
const word & headerClassName() const
Return name of the class name read from header.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
fileName objectPath(const bool global) const
Return complete path + object name including the processor.
virtual bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Does the name exist as a FILE in the file system?
#define InfoInFunction
Report an information message using Foam::Info.
virtual autoPtr< Ostream > NewOFstream(const fileName &filePath, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool write=true) const
Generate an Ostream that writes a file.