41 namespace fileOperations
49 fileOperationInitialise,
62 const bool checkGlobal,
68 if (
io.instance().isAbsolute())
91 &&
io.time().processorCase()
93 io.instance() ==
io.time().system()
94 ||
io.instance() ==
io.time().constant()
100 fileName parentObjectPath =
101 io.rootPath()/
io.time().globalCaseName()
102 /
io.instance()/
io.db().dbDir()/
io.local()/
io.name();
106 return parentObjectPath;
111 if (
io.time().processorCase())
113 refPtr<dirIndexList> pDirs
122 for (
const dirIndex& dirIdx : pDirs())
124 const fileName& pDir = dirIdx.first();
140 word newInstancePath =
io.time().findInstancePath
142 instant(
io.instance())
145 if (newInstancePath.size())
149 io.rootPath()/
io.caseName()
150 /newInstancePath/
io.db().dbDir()/
io.local()/
io.name()
179 void Foam::fileOperations::uncollatedFileOperation::init(
bool verbose)
186 <<
"I/O : " << typeName <<
endl;
239 const bool followLink
249 const bool followLink
259 const bool checkGzip,
260 const bool followLink
270 const bool followLink
280 const bool checkGzip,
281 const bool followLink
291 const bool followLink
301 const bool followLink
311 const bool followLink
321 const std::string& ext
353 const bool followLink
364 const bool followLink
367 return Foam::cp(src, dst, followLink);
385 const bool followLink
396 const bool checkGlobal,
398 const word& typeName,
404 Pout<<
"uncollatedFileOperation::filePath :" 405 <<
" objectPath:" <<
io.objectPath()
406 <<
" checkGlobal:" << checkGlobal <<
endl;
413 Pout<<
"uncollatedFileOperation::filePath :" 414 <<
" Returning from file searching:" <<
endl 415 <<
" objectPath:" <<
io.objectPath() <<
endl 424 const bool checkGlobal,
431 Pout<<
"uncollatedFileOperation::dirPath :" 432 <<
" objectPath:" <<
io.objectPath()
433 <<
" checkGlobal:" << checkGlobal <<
endl;
436 fileName objPath(filePathInfo(checkGlobal,
false,
io,
search));
440 Pout<<
"uncollatedFileOperation::dirPath :" 441 <<
" Returning from directory searching:" <<
endl 442 <<
" objectPath:" <<
io.objectPath() <<
endl 459 Pout<<
"uncollatedFileOperation::readObjects :" 461 <<
" instance:" << instance <<
endl;
470 if (newInstance.empty())
474 if (!newInst.empty() && newInst != instance)
489 Pout<<
"uncollatedFileOperation::readObjects :" 490 <<
" newInstance:" << newInstance
491 <<
" objectNames:" << objectNames <<
endl;
507 Pout<<
"uncollatedFileOperation::readHeader :" 508 <<
" fName:" << fName
509 <<
" typeName:" << typeName <<
endl;
516 <<
"file " <<
io.objectPath() <<
" could not be opened" 523 autoPtr<ISstream> isPtr(NewIFstream(fName));
525 if (!isPtr || !isPtr->good())
535 Pout<<
"uncollatedFileOperation::readHeader :" 536 <<
" for fName:" << fName
538 <<
" headerClassName:" <<
io.headerClassName() <<
endl;
550 const word& typeName,
562 <<
"cannot find file " <<
io.objectPath()
566 autoPtr<ISstream> isPtr = NewIFstream(fName);
568 if (!isPtr || !isPtr->good())
572 "uncollatedFileOperation::readStream()",
577 ) <<
"cannot open file" 580 else if (!
io.readHeader(*isPtr))
583 <<
"problem while reading header for object " <<
io.name()
596 label proci = detectProcessorPath(
io.objectPath());
601 <<
"could not detect processor number" 602 <<
" from objectPath:" <<
io.objectPath()
603 <<
" fName:" << fName
618 proci = proci -
group.start();
630 const bool masterOnly,
641 Pout<<
"uncollatedFileOperation::read :" 642 <<
" Reading object " <<
io.objectPath()
643 <<
" from file " <<
endl;
647 const bool oldGlobal =
io.globalObject(masterOnly);
655 ok =
io.readData(
io.readStream(typeName));
659 io.globalObject(oldGlobal);
664 Pout<<
"uncollatedFileOperation::read :" 665 <<
" Done reading object " <<
io.objectPath()
666 <<
" from file " <<
endl;
675 io.headerClassName(),
687 bool okWrite =
io.writeData(toAll);
698 ok =
io.readData(fromMaster);
bool mvBak(const fileName &src, const std::string &ext="bak")
Rename to a corresponding backup file.
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?
bool mv(const fileName &src, const fileName &dst, const bool followLink=false)
Rename src to dst.
A class for handling file names.
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
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.
static autoPtr< ISstream > readBlock(const label blocki, ISstream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
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.
Output to file stream, using an OSstream.
int infoDetailLevel
Global for selective suppression of Info output.
virtual bool read(regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const
Top-level read.
static const fileName null
An empty fileName.
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
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.
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy the source to the destination (recursively if necessary).
fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &io, const bool search) const
Search for an object.
static bool & parRun() noexcept
Test if this a parallel run.
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
virtual bool rmDir(const fileName &dir, const bool silent=false, const bool emptyOnly=false) const
Remove a directory and its contents.
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
A simple container for options an IOstream can normally have.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
static label worldComm
Default world communicator (all processors). May differ from globalComm if local worlds are in use...
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Generate an OSstream that writes a file.
fileName processorsPath(const IOobject &, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
A class for managing references or pointers (no reference counting)
An encapsulation of filesystem-related operations.
fileName objectPath() const
The complete path + object name.
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(fileOperationInitialise, collatedFileOperationInitialise, word, collated)
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?
refPtr< dirIndexList > lookupAndCacheProcessorsPath(const fileName &objectPath, const bool syncPar) const
Lookup name of processorsDDD using cache.
constexpr const char *const group
Group name for atomic constants.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Tuple2< fileName, Tuple2< pathType, int > > dirIndex
Augment fileName with pathType and local offset.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
atomicType
Atomic operations (output)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
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?
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
A class for handling words, derived from Foam::string.
const Time & time() const noexcept
Return time registry.
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
static constexpr int masterNo() noexcept
Process index of the master (always 0)
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &) const
Lookup name of processorsDDD using cache.
time_t lastModified(const fileName &name, const bool followLink=true)
Return time of last file modification (normally follows symbolic links).
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?
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
static bool isCollatedType(const word &objectType)
True if object type is a known collated type.
static bool readHeader(IOobject &io, Istream &is)
Read header as per IOobject with additional handling of decomposedBlockData.
static bool isUserComm(label communicator) noexcept
True if communicator appears to be user-allocated.
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
bool rmDir(const fileName &directory, const bool silent=false, const bool emptyOnly=false)
Remove a directory and its contents recursively,.
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
int debug
Static debugging option.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
Input from file stream, using an ISstream.
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory. checkGlobal : also check undecomposed.
bool chMod(const fileName &name, const mode_t mode)
Set the file/directory mode, return true on success.
static void broadcasts(const label comm, Type &arg1, Args &&... args)
Broadcast multiple items to all processes in communicator.
static bool isFileOrDir(const bool isFile, const fileName &)
Helper: check for file (isFile) or directory (!isFile)
word format(conversionProperties.get< word >("format"))
static bool masterOnlyReading
To flag master-only reading of objects.
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 ~uncollatedFileOperation()
Destructor.
word findInstancePath(const fileName &directory, const instant &t) const
Search the case for the time directory path corresponding to the given instance.
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool procValid=true) const
Reads header for regIOobject and returns an ISstream.
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
uncollatedFileOperation(bool verbose)
Default construct.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
static bool master(const label communicator=worldComm)
Am I the master rank.
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
streamFormat
Data format (ascii | binary)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
defineTypeNameAndDebug(collatedFileOperation, 0)
Registry of regIOobjects.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
List< fileName > fileNameList
A List of fileNames.
Dummy input stream, which can be used as a placeholder for interfaces taking an Istream or ISstream...
Defines the attributes of an object for which implicit objectRegistry management is supported...
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Inter-processor communications stream.
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
Type
Enumerations to handle directory entry types.
double highResLastModified(const fileName &, const bool followLink=true)
Return time of last file modification.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
#define InfoInFunction
Report an information message using Foam::Info.