uncollatedFileOperation.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) 2020-2022 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::uncollatedFileOperation
29 
30 Description
31  fileOperation that assumes file operations are local.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef Foam_fileOperations_uncollatedFileOperation_H
36 #define Foam_fileOperations_uncollatedFileOperation_H
37 
38 #include "fileOperation.H"
39 #include "OSspecific.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 namespace fileOperations
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class uncollatedFileOperation Declaration
50 \*---------------------------------------------------------------------------*/
51 
53 :
54  public fileOperation
55 {
56  // Private Data
57 
58  //- Communicator allocated/managed by us
59  label managedComm_;
60 
61 
62  // Private Member Functions
63 
64  //- Any initialisation steps after constructing
65  void init(bool verbose);
66 
67 protected:
68 
69  // Protected Member Functions
70 
71  //- Search for an object.
72  // checkGlobal : also check undecomposed case
73  // isFile : true:check for file false:check for directory
75  (
76  const bool checkGlobal,
77  const bool isFile,
78  const IOobject& io,
79  const bool search
80  ) const;
81 
82  //- Lookup name of processorsDDD using cache.
83  // \note Do not use any parallel synchronisation
84  // \return empty fileName if not found.
86  (
87  const fileName&
88  ) const;
89 
90 
91 public:
92 
93  //- Runtime type information
94  TypeName("uncollated");
95 
96 
97  // Constructors
98 
99  //- Default construct
100  explicit uncollatedFileOperation(bool verbose);
101 
102 
103  //- Destructor
104  virtual ~uncollatedFileOperation();
105 
106 
107  // Member Functions
108 
109  // OSSpecific equivalents
110 
111  //- Make directory
112  virtual bool mkDir(const fileName&, mode_t=0777) const;
113 
114  //- Set the file mode
115  virtual bool chMod(const fileName&, const mode_t) const;
116 
117  //- Return the file mode
118  virtual mode_t mode
119  (
120  const fileName&,
121  const bool followLink = true
122  ) const;
123 
124  //- Return the file type: DIRECTORY, FILE or SYMLINK
125  virtual fileName::Type type
126  (
127  const fileName&,
128  const bool followLink = true
129  ) const;
130 
131  //- Does the name exist (as DIRECTORY or FILE) in the file system?
132  // Optionally enable/disable check for gzip file.
133  virtual bool exists
134  (
135  const fileName&,
136  const bool checkGzip=true,
137  const bool followLink = true
138  ) const;
139 
140  //- Does the name exist as a DIRECTORY in the file system?
141  virtual bool isDir
142  (
143  const fileName&,
144  const bool followLink = true
145  ) const;
146 
147  //- Does the name exist as a FILE in the file system?
148  // Optionally enable/disable check for gzip file.
149  virtual bool isFile
150  (
151  const fileName&,
152  const bool checkGzip=true,
153  const bool followLink = true
154  ) const;
155 
156  //- Return size of file
157  virtual off_t fileSize
158  (
159  const fileName&,
160  const bool followLink = true
161  ) const;
162 
163  //- Return time of last file modification
164  virtual time_t lastModified
165  (
166  const fileName&,
167  const bool followLink = true
168  ) const;
169 
170  //- Return time of last file modification
171  virtual double highResLastModified
172  (
173  const fileName&,
174  const bool followLink = true
175  ) const;
176 
177  //- Read a directory and return the entries as a string list
178  virtual fileNameList readDir
179  (
180  const fileName&,
182  const bool filtergz=true,
183  const bool followLink = true
184  ) const;
185 
186  //- Copy, recursively if necessary, the source to the destination
187  virtual bool cp
188  (
189  const fileName& src,
190  const fileName& dst,
191  const bool followLink = true
192  ) const;
193 
194  //- Create a softlink. dst should not exist. Returns true if
195  // successful.
196  virtual bool ln(const fileName& src, const fileName& dst) const;
197 
198  //- Rename src to dst
199  virtual bool mv
200  (
201  const fileName& src,
202  const fileName& dst,
203  const bool followLink = false
204  ) const;
205 
206  //- Rename to a corresponding backup file
207  // If the backup file already exists, attempt with
208  // "01" .. "99" suffix
209  virtual bool mvBak
210  (
211  const fileName&,
212  const std::string& ext = "bak"
213  ) const;
214 
215  //- Remove a file, returning true if successful otherwise false
216  virtual bool rm(const fileName&) const;
217 
218  //- Remove a directory and its contents
219  // \param dir the directory to remove
220  // \param silent do not report missing directory
221  // \param emptyOnly only remove empty directories (recursive)
222  virtual bool rmDir
223  (
224  const fileName& dir,
225  const bool silent = false,
226  const bool emptyOnly = false
227  ) const;
228 
229 
230  // (reg)IOobject functionality
231 
232  //- Search for an object. checkGlobal : also check undecomposed case
233  virtual fileName filePath
234  (
235  const bool checkGlobal,
236  const IOobject& io,
237  const word& typeName,
238  const bool search
239  ) const;
240 
241  //- Search for a directory. checkGlobal : also check undecomposed
242  // case
243  virtual fileName dirPath
244  (
245  const bool checkGlobal,
246  const IOobject& io,
247  const bool search
248  ) const;
249 
250  //- Search directory for objects. Used in IOobjectList.
251  virtual fileNameList readObjects
252  (
253  const objectRegistry& db,
254  const fileName& instance,
255  const fileName& local,
256  word& newInstance
257  ) const;
258 
259  //- Read object header from supplied file
260  virtual bool readHeader
261  (
262  IOobject&,
263  const fileName&,
264  const word& typeName
265  ) const;
266 
267  //- Reads header for regIOobject and returns an ISstream
268  // to read the contents.
270  (
271  regIOobject&,
272  const fileName&,
273  const word& typeName,
274  const bool procValid = true
275  ) const;
276 
277  //- Top-level read
278  virtual bool read
279  (
280  regIOobject&,
281  const bool masterOnly,
283  const word& typeName
284  ) const;
285 
286  //- Generate an ISstream that reads a file
287  virtual autoPtr<ISstream> NewIFstream(const fileName&) const;
288 
289  //- Generate an OSstream that writes a file
291  (
292  const fileName& pathname,
293  IOstreamOption streamOpt = IOstreamOption(),
294  const bool valid = true
295  ) const;
296 
297  //- Generate an OSstream that writes a file
299  (
301  const fileName& pathname,
302  IOstreamOption streamOpt = IOstreamOption(),
303  const bool valid = true
304  ) const;
305 };
306 
307 
308 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
309 
310 } // End namespace fileOperations
311 } // End namespace Foam
312 
313 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
314 
315 #endif
316 
317 // ************************************************************************* //
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?
A class for handling file names.
Definition: fileName.H:71
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
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.
virtual bool read(regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const
Top-level read.
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &io, const bool search) const
Search for an object.
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.
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Generate an OSstream that writes a file.
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
An encapsulation of filesystem-related operations.
Definition: fileOperation.H:63
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?
fileOperation that assumes file operations are local.
TypeName("uncollated")
Runtime type information.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
atomicType
Atomic operations (output)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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.
Definition: word.H:63
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
A regular file.
Definition: fileName.H:83
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &) const
Lookup name of processorsDDD using cache.
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
bool local
Definition: EEqn.H:20
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.
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory. checkGlobal : also check undecomposed.
word format(conversionProperties.get< word >("format"))
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.
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...
Definition: regIOobject.H:69
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:640
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Registry of regIOobjects.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
Type
Enumerations to handle directory entry types.
Definition: fileName.H:80
Namespace for OpenFOAM.