masterUncollatedFileOperation.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017 OpenFOAM Foundation
9  Copyright (C) 2019-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::fileOperations::masterUncollatedFileOperation
29 
30 Description
31  fileOperations that performs all file operations on the master processor.
32  Requires the calls to be parallel synchronised!
33 
34  Limitations
35  - no /processor in filename
36  - no /uniform/ in the filename
37 
38  The main logic is in ::filePath which returns a
39  - same path on all processors. This can either be a global file
40  (system/controlDict, processorXXX/0/uniform/) or a collated file
41  (processors/0/p)
42  - same path on all processors of the local communicator
43  (processors4_0-1/0/p)
44  - different path on all processors (processor0/0/p)
45 
46  system/controlDict:
47  filePath worldmaster: <globalRoot>/system/controlDict
48  localmaster: ,,
49  slave : ,,
50 
51  processor0/uniform/time
52  filePath worldmaster: <globalRoot>/processorXXX/uniform/time
53  localmaster: ,,
54  slave : ,,
55 
56  processors0/0/p
57  processors10/0/p
58  processors10_2-4/0/p
59 
60 \*---------------------------------------------------------------------------*/
61 
62 #ifndef Foam_fileOperations_masterUncollatedFileOperation_H
63 #define Foam_fileOperations_masterUncollatedFileOperation_H
64 
65 #include "fileOperation.H"
66 #include "OSspecific.H"
67 #include "HashPtrTable.H"
68 #include "DynamicList.H"
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 
72 namespace Foam
73 {
74 
75 // Forward Declarations
76 class PstreamBuffers;
77 
78 namespace fileOperations
79 {
80 
81 /*---------------------------------------------------------------------------*\
82  Class masterUncollatedFileOperation Declaration
83 \*---------------------------------------------------------------------------*/
84 
86 :
87  public fileOperation
88 {
89  // Private Data
90 
91  //- Communicator allocated/managed by us
92  mutable label managedComm_;
93 
94 
95  // Private Member Functions
96 
97  //- Any initialisation steps after constructing
98  void init(bool verbose);
99 
100 
101 protected:
102 
103  // Protected Data
104 
105  //- Cached times for a given directory
107 
108 
109  // Protected Operation Functors
111  class mkDirOp
112  {
113  const mode_t mode_;
114  public:
115  mkDirOp(const mode_t mode)
116  :
117  mode_(mode)
118  {}
120  bool operator()(const fileName& f) const
121  {
122  return Foam::mkDir(f, mode_);
123  }
124  };
126  class chModOp
127  {
128  const mode_t mode_;
129  public:
130  chModOp(const mode_t mode)
131  :
132  mode_(mode)
133  {}
135  bool operator()(const fileName& f) const
136  {
137  return Foam::chMod(f, mode_);
138  }
139  };
141  class modeOp
142  {
143  const bool followLink_;
144  public:
145  modeOp(const bool followLink)
146  :
147  followLink_(followLink)
148  {}
150  mode_t operator()(const fileName& f) const
151  {
152  return Foam::mode(f, followLink_);
153  }
154  };
156  class typeOp
157  {
158  const bool followLink_;
159  public:
160  typeOp(const bool followLink)
161  :
162  followLink_(followLink)
163  {}
164 
165  // Returns label not fileName::Type for reductions
166  label operator()(const fileName& f) const
167  {
168  return Foam::type(f, followLink_);
169  }
170  };
172  class existsOp
173  {
174  const bool checkGzip_;
175  const bool followLink_;
176  public:
177  existsOp(const bool checkGzip, const bool followLink)
178  :
179  checkGzip_(checkGzip),
180  followLink_(followLink)
181  {}
183  bool operator()(const fileName& f) const
184  {
185  return Foam::exists(f, checkGzip_, followLink_);
186  }
187  };
189  class isDirOp
190  {
191  const bool followLink_;
192  public:
193  isDirOp(const bool followLink)
194  :
195  followLink_(followLink)
196  {}
198  bool operator()(const fileName& f) const
199  {
200  return Foam::isDir(f, followLink_);
201  }
202  };
204  class isFileOp
205  {
206  const bool checkGzip_;
207  const bool followLink_;
208  public:
209  isFileOp(const bool checkGzip, const bool followLink)
210  :
211  checkGzip_(checkGzip),
212  followLink_(followLink)
213  {}
215  bool operator()(const fileName& f) const
216  {
217  return Foam::isFile(f, checkGzip_, followLink_);
218  }
219  };
221  class fileSizeOp
222  {
223  const bool followLink_;
224  public:
225  fileSizeOp(const bool followLink)
226  :
227  followLink_(followLink)
228  {}
230  off_t operator()(const fileName& f) const
231  {
232  return Foam::fileSize(f, followLink_);
233  }
234  };
236  class lastModifiedOp
237  {
238  const bool followLink_;
239  public:
240  lastModifiedOp(const bool followLink)
241  :
242  followLink_(followLink)
243  {}
245  time_t operator()(const fileName& f) const
246  {
247  return Foam::lastModified(f, followLink_);
248  }
249  };
252  {
253  const bool followLink_;
254  public:
255  highResLastModifiedOp(const bool followLink)
256  :
257  followLink_(followLink)
258  {}
260  double operator()(const fileName& f) const
261  {
262  return Foam::highResLastModified(f, followLink_);
263  }
264  };
266  class mvBakOp
267  {
268  std::string ext_;
269  public:
270  mvBakOp(const std::string& ext)
271  :
272  ext_(ext)
273  {}
275  bool operator()(const fileName& f) const
276  {
277  return Foam::mvBak(f, ext_);
278  }
279  };
281  class rmOp
282  {
283  public:
284  bool operator()(const fileName& f) const
285  {
286  return Foam::rm(f);
287  }
288  };
290  class rmDirOp
291  {
292  bool silent_;
293  bool emptyOnly_;
294  public:
295  rmDirOp(bool silent=false, bool emptyOnly=false)
296  :
297  silent_(silent),
298  emptyOnly_(emptyOnly)
299  {}
301  bool operator()(const fileName& f) const
302  {
303  return Foam::rmDir(f, silent_, emptyOnly_);
304  }
305  };
307  class cpOp
308  {
309  const bool followLink_;
310  public:
311  cpOp(const bool followLink)
312  :
313  followLink_(followLink)
314  {}
316  bool operator()(const fileName& src, const fileName& dest) const
317  {
318  return Foam::cp(src, dest, followLink_);
319  }
320  };
322  class lnOp
323  {
324  public:
325  bool operator()(const fileName& src, const fileName& dest) const
326  {
327  return Foam::ln(src, dest);
328  }
329  };
331  class mvOp
332  {
333  const bool followLink_;
334  public:
335  mvOp(const bool followLink)
336  :
337  followLink_(followLink)
338  {}
340  bool operator()(const fileName& src, const fileName& dest) const
341  {
342  return Foam::mv(src, dest, followLink_);
343  }
344  };
346  class fileOrNullOp
347  {
348  const bool isFile_;
349  public:
350  fileOrNullOp(const bool isFile)
351  :
352  isFile_(isFile)
353  {}
355  const fileName& operator()(const fileName& f) const
356  {
357  return
358  (
359  (isFile_ ? Foam::isFile(f) : Foam::isDir(f))
360  ? f
361  : fileName::null // const reference, not temporary
362  );
363  }
364  };
366  class readDirOp
367  {
368  const fileName::Type type_;
369  const bool filtergz_;
370  const bool followLink_;
371  public:
373  (
374  const fileName::Type type,
375  const bool filtergz,
376  const bool followLink
377  )
378  :
379  type_(type),
380  filtergz_(filtergz),
381  followLink_(followLink)
382  {}
384  fileNameList operator()(const fileName& f) const
385  {
386  return Foam::readDir(f, type_, filtergz_, followLink_);
387  }
388  };
389 
390 
391  // Private Member Functions
392 
393  template<class Type>
394  Type scatterList(const UList<Type>&, const int, const label comm) const;
395 
396  template<class Type, class FileOp>
397  Type masterOp
398  (
399  const fileName& fName,
400  const FileOp& fop,
401  const int tag,
402  const label comm
403  ) const;
404 
405  template<class Type, class FileOp>
406  Type masterOp
407  (
408  const fileName& src,
409  const fileName& dest,
410  const FileOp& fop,
411  const int tag,
412  const label comm
413  ) const;
414 
415  //- Equivalent of Time::findInstance
416  static word findInstancePath
417  (
418  const instantList& timeDirs,
419  const instant& t
420  );
421 
422  //- Search (locally!) for object; return info on how it was found.
423  // Does not do any parallel communication.
424  // checkGlobal : also check undecomposed case
425  // isFile : true:check for file false:check for directory
426  // searchType : how was found
427  // processorsDir : name of processor directory
428  // instance : instance
429  virtual fileName filePathInfo
430  (
431  const bool checkGlobal,
432  const bool isFile,
433  const IOobject& io,
434  const dirIndexList& pDirs,
435  const bool search,
436  pathType& searchType,
438  word& instance
439  ) const;
440 
441  //- Construct filePath
443  (
444  const IOobject&,
445  const pathType& searchType,
446  const word& processorsDir,
447  const word& instancePath
448  ) const;
449 
450  //- Read file contents and send to processors.
451  // Handles compressed or uncompressed files
452  static void readAndSend
453  (
454  const fileName& filePath,
455  const labelUList& recvProcs,
456  PstreamBuffers& pBufs
457  );
458 
459  //- Read files on comms master
460  static autoPtr<ISstream> read
461  (
462  IOobject& io,
463  const label comm,
464  const bool uniform, // on comms master only
465  const fileNameList& filePaths, // on comms master and sub-ranks
466  const boolUList& readOnProcs // on comms master and sub-ranks
467  );
468 
469  //- Helper: check IO for local existence. Like filePathInfo but
470  // without parent searchign and instance searching
471  bool exists(const dirIndexList&, IOobject& io) const;
472 
473 
474 public:
475 
476  //- Runtime type information
477  TypeName("masterUncollated");
478 
479 
480  // Static Data
481 
482  //- Max size of parallel communications. Switches from non-blocking
483  // to scheduled when reading/writing files. Read as float to enable
484  // easy specification of large sizes.
485  static float maxMasterFileBufferSize;
486 
487 
488  // Constructors
489 
490  //- Default construct
491  explicit masterUncollatedFileOperation(bool verbose = false);
492 
493  //- Construct from communicator with specified io-ranks
495  (
496  const Tuple2<label, labelList>& commAndIORanks,
497  const bool distributedRoots,
498  bool verbose = false
499  );
500 
501 
502  //- Destructor
505 
506  // Member Functions
507 
508  //- Transfer ownership of communicator to this fileOperation.
509  //- Use with caution
510  virtual void storeComm() const;
511 
512 
513  // OSSpecific equivalents
514 
515  //- Make directory
516  virtual bool mkDir(const fileName&, mode_t=0777) const;
517 
518  //- Set the file mode
519  virtual bool chMod(const fileName&, const mode_t) const;
520 
521  //- Return the file mode
522  virtual mode_t mode
523  (
524  const fileName&,
525  const bool followLink = true
526  ) const;
527 
528  //- Return the file type: DIRECTORY, FILE or SYMLINK
529  virtual fileName::Type type
530  (
531  const fileName&,
532  const bool followLink = true
533  ) const;
534 
535  //- Does the name exist (as DIRECTORY or FILE) in the file system?
536  // Optionally enable/disable check for gzip file.
537  virtual bool exists
538  (
539  const fileName&,
540  const bool checkGzip=true,
541  const bool followLink = true
542  ) const;
543 
544  //- Does the name exist as a DIRECTORY in the file system?
545  virtual bool isDir
546  (
547  const fileName&,
548  const bool followLink = true
549  ) const;
550 
551  //- Does the name exist as a FILE in the file system?
552  // Optionally enable/disable check for gzip file.
553  virtual bool isFile
554  (
555  const fileName&,
556  const bool checkGzip=true,
557  const bool followLink = true
558  ) const;
559 
560  //- Return size of file
561  virtual off_t fileSize
562  (
563  const fileName&,
564  const bool followLink = true
565  ) const;
566 
567  //- Return time of last file modification
568  virtual time_t lastModified
569  (
570  const fileName&,
571  const bool followLink = true
572  ) const;
573 
574  //- Return time of last file modification
575  virtual double highResLastModified
576  (
577  const fileName&,
578  const bool followLink = true
579  ) const;
580 
581  //- Read a directory and return the entries as a string list
582  virtual fileNameList readDir
583  (
584  const fileName&,
586  const bool filtergz=true,
587  const bool followLink = true
588  ) const;
589 
590  //- Copy, recursively if necessary, the source to the destination
591  virtual bool cp
592  (
593  const fileName& src,
594  const fileName& dst,
595  const bool followLink = true
596  ) const;
597 
598  //- Create a softlink. dst should not exist. Returns true if
599  // successful.
600  virtual bool ln(const fileName& src, const fileName& dst) const;
601 
602  //- Rename src to dst
603  virtual bool mv
604  (
605  const fileName& src,
606  const fileName& dst,
607  const bool followLink = false
608  ) const;
609 
610  //- Rename to a corresponding backup file
611  // If the backup file already exists, attempt with
612  // "01" .. "99" suffix
613  virtual bool mvBak
614  (
615  const fileName&,
616  const std::string& ext = "bak"
617  ) const;
618 
619  //- Remove a file, returning true if successful otherwise false
620  virtual bool rm(const fileName&) const;
621 
622  //- Remove a directory and its contents
623  // \param dir the directory to remove
624  // \param silent do not report missing directory
625  // \param emptyOnly only remove empty directories (recursive)
626  virtual bool rmDir
627  (
628  const fileName& dir,
629  const bool silent = false,
630  const bool emptyOnly = false
631  ) const;
632 
633 
634  // (reg)IOobject functinality
635 
636  //- Search for an object. checkGlobal : also check undecomposed case
637  virtual fileName filePath
638  (
639  const bool checkGlobal,
640  const IOobject& io,
641  const word& typeName,
642  const bool search
643  ) const;
644 
645  //- Search for a directory. checkGlobal : also check undecomposed
646  // case
647  virtual fileName dirPath
648  (
649  const bool checkGlobal,
650  const IOobject& io,
651  const bool search
652  ) const;
653 
654  //- Search directory for objects. Used in IOobjectList.
655  virtual fileNameList readObjects
656  (
657  const objectRegistry& db,
658  const fileName& instance,
659  const fileName& local,
660  word& newInstance
661  ) const;
662 
663  //- Read object header from supplied file
664  virtual bool readHeader
665  (
666  IOobject&,
667  const fileName&,
668  const word& typeName
669  ) const;
670 
671  //- Reads header for regIOobject and returns an ISstream
672  //- to read the contents.
674  (
675  regIOobject&,
676  const fileName&,
677  const word& typeName,
678  const bool readOnProc = true
679  ) const;
680 
681  //- Top-level read
682  virtual bool read
683  (
684  regIOobject&,
685  const bool masterOnly,
687  const word& typeName
688  ) const;
689 
690  //- Writes a regIOobject (so header, contents and divider).
691  // Returns success state.
692  virtual bool writeObject
693  (
694  const regIOobject& io,
695  IOstreamOption streamOpt = IOstreamOption(),
696  const bool writeOnProc = true
697  ) const;
698 
699  //- Generate an ISstream that reads a file
700  virtual autoPtr<ISstream> NewIFstream(const fileName&) const;
701 
702  //- Generate an OSstream that writes a file
704  (
705  const fileName& pathname,
706  IOstreamOption streamOpt = IOstreamOption(),
707  const bool writeOnProc = true
708  ) const;
709 
710  //- Generate an OSstream that writes a file
712  (
714  const fileName& pathname,
715  IOstreamOption streamOpt = IOstreamOption(),
716  const bool writeOnProc = true
717  ) const;
718 
719 
720  // File modification checking
721 
722  //- Add watching of a file. Returns handle
723  virtual label addWatch(const fileName&) const;
724 
725  //- Remove watch on a file (using handle)
726  virtual bool removeWatch(const label) const;
727 
728  //- Find index (or -1) of file in list of handles
729  virtual label findWatch
730  (
731  const labelList& watchIndices,
732  const fileName&
733  ) const;
734 
735  //- Helper: add watches for list of regIOobjects
736  virtual void addWatches(regIOobject&, const fileNameList&) const;
737 
738  //- Get name of file being watched (using handle)
739  virtual fileName getFile(const label) const;
740 
741  //- Update state of all files
742  virtual void updateStates
743  (
744  const bool masterOnly,
745  const bool syncPar
746  ) const;
747 
748  //- Get current state of file (using handle)
749  virtual fileMonitor::fileState getState(const label) const;
750 
751  //- Set current state of file (using handle) to unmodified
752  virtual void setUnmodified(const label) const;
753 
754 
755  // Other
756 
757  //- Get sorted list of times
758  virtual instantList findTimes(const fileName&, const word&) const;
759 
760  //- Find instance where IOobject is.
761  // FatalError if it cannot be found and readOpt is
762  // (MUST_READ or MUST_READ_IF_MODIFIED).
763  // Otherwise it returns the stopInstance.
764  virtual IOobject findInstance
765  (
766  const IOobject& io,
767  const scalar startValue,
768  const word& stopInstance
769  ) const;
770 
771  //- Callback for time change
772  virtual void setTime(const Time&) const;
773 
774  //- Forcibly wait until all output done. Flush any cached data
775  virtual void flush() const;
776 
777  //- Forcibly parallel sync
778  virtual void sync();
779 
780  //- Return cached times
782  {
783  return times_;
784  }
785 };
786 
787 
788 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
789 
790 } // End namespace fileOperations
791 } // End namespace Foam
792 
793 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
794 
795 #ifdef NoRepository
797 #endif
798 
799 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
800 
801 #endif
802 
803 // ************************************************************************* //
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
bool operator()(const fileName &src, const fileName &dest) const
static word findInstancePath(const instantList &timeDirs, const instant &t)
Equivalent of Time::findInstance.
bool mvBak(const fileName &src, const std::string &ext="bak")
Rename to a corresponding backup file.
Definition: POSIX.C:1357
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
Construct filePath.
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?
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
List< dirIndex > dirIndexList
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.
bool mv(const fileName &src, const fileName &dst, const bool followLink=false)
Rename src to dst.
Definition: POSIX.C:1324
A class for handling file names.
Definition: fileName.H:72
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
Definition: POSIX.C:905
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
HashPtrTable< DynamicList< instant > > times_
Cached times for a given directory.
masterUncollatedFileOperation(bool verbose=false)
Default construct.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:54
static autoPtr< ISstream > read(IOobject &io, const label comm, const bool uniform, const fileNameList &filePaths, const boolUList &readOnProcs)
Read files on comms master.
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
Type masterOp(const fileName &fName, const FileOp &fop, const int tag, const label comm) const
fileState
Enumeration defining the file state.
Definition: fileMonitor.H:70
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
pathType
Enumeration for the location of an IOobject.
readDirOp(const fileName::Type type, const bool filtergz, const bool followLink)
static const fileName null
An empty fileName.
Definition: fileName.H:111
TypeName("masterUncollated")
Runtime type information.
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy the source to the destination (recursively if necessary).
Definition: POSIX.C:1063
virtual bool rmDir(const fileName &dir, const bool silent=false, const bool emptyOnly=false) const
Remove a directory and its contents.
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool readOnProc=true) const
Reads header for regIOobject and returns an ISstream to read the contents.
A simple container for options an IOstream can normally have.
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers...
Definition: HashPtrTable.H:51
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
bool exists(const dirIndexList &, IOobject &io) const
Helper: check IO for local existence. Like filePathInfo but.
An encapsulation of filesystem-related operations.
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 isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:860
virtual bool writeObject(const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Writes a regIOobject (so header, contents and divider).
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
atomicType
Atomic operations (output)
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:614
bool operator()(const fileName &src, const fileName &dest) const
static float maxMasterFileBufferSize
Max size of parallel communications. Switches from non-blocking.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory. checkGlobal : also check undecomposed.
Type scatterList(const UList< Type > &, const int, const label comm) const
A regular file.
Definition: fileName.H:84
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
time_t lastModified(const fileName &name, const bool followLink=true)
Return time of last file modification (normally follows symbolic links).
Definition: POSIX.C:930
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?
Definition: POSIX.C:835
bool operator()(const fileName &src, const fileName &dest) const
bool local
Definition: EEqn.H:20
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
static void readAndSend(const fileName &filePath, const labelUList &recvProcs, PstreamBuffers &pBufs)
Read file contents and send to processors.
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: POSIX.C:1237
bool rmDir(const fileName &directory, const bool silent=false, const bool emptyOnly=false)
Remove a directory and its contents recursively,.
Definition: POSIX.C:1433
const direction noexcept
Definition: Scalar.H:258
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
labelList f(nPoints)
Buffers for inter-processor communications streams (UOPstream, UIPstream).
bool chMod(const fileName &name, const mode_t mode)
Set the file/directory mode, return true on success.
Definition: POSIX.C:757
const HashPtrTable< DynamicList< instant > > & times() const noexcept
Return cached times.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
word format(conversionProperties.get< word >("format"))
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
Definition: POSIX.C:877
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Definition: instant.H:53
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
virtual fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &io, const dirIndexList &pDirs, const bool search, pathType &searchType, word &processorsDir, word &instance) const
Search (locally!) for object; return info on how it was found.
label comm() const noexcept
Communicator to use.
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
streamFormat
Data format (ascii | binary)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Generate an OSstream that writes a file.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:642
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
Registry of regIOobjects.
virtual void setTime(const Time &) const
Callback for time change.
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.
Definition: POSIX.C:963
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
Definition: POSIX.C:773
virtual IOobject findInstance(const IOobject &io, const scalar startValue, const word &stopInstance) const
Find instance where IOobject is.
Type
Enumerations to handle directory entry types.
Definition: fileName.H:81
virtual word processorsDir(const IOobject &io) const
Actual name of processors dir (for use in mode PROCOBJECT, PROCINSTANCE)
Namespace for OpenFOAM.
double highResLastModified(const fileName &, const bool followLink=true)
Return time of last file modification.
Definition: POSIX.C:946
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Definition: POSIX.C:1404