dummyFileOperation.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) 2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::fileOperations::dummyFileOperation
28 
29 Description
30  Dummy fileOperation, to be used as a placeholder for interfaces
31  taking a reference to a fileOperation.
32  Will mostly behave like a no-op, but at the moment no guarantees
33  of any particular behaviour other than good() returning false.
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef Foam_fileOperations_dummyFileOperation_H
38 #define Foam_fileOperations_dummyFileOperation_H
39 
40 #include "fileOperation.H"
41 #include "OSspecific.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 namespace fileOperations
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class dummyFileOperation Declaration
52 \*---------------------------------------------------------------------------*/
53 
55 :
56  public fileOperation
57 {
58 public:
59 
60  //- Runtime type information
61  TypeNameNoDebug("dummy");
62 
63 
64  // Constructors
65 
66  //- Default construct
67  explicit dummyFileOperation(bool verbose = false);
68 
69 
70  //- Destructor
71  virtual ~dummyFileOperation();
72 
73 
74  // Member Functions
75 
76  //- This fileOperation is not really valid for anything.
77  virtual bool good() const { return false; }
78 
79  //- No managed communicator
80  virtual void storeComm() const {}
81 
82 
83  // OSSpecific equivalents
84 
85  //- Make directory
86  virtual bool mkDir(const fileName&, mode_t=0777) const;
87 
88  //- Set the file mode
89  virtual bool chMod(const fileName&, const mode_t) const;
90 
91  //- Return the file mode
92  virtual mode_t mode
93  (
94  const fileName&,
95  const bool followLink = true
96  ) const;
97 
98  //- Return the file type: DIRECTORY, FILE or SYMLINK
99  virtual fileName::Type type
100  (
101  const fileName&,
102  const bool followLink = true
103  ) const;
104 
105  //- Does the name exist (as DIRECTORY or FILE) in the file system?
106  // Optionally enable/disable check for gzip file.
107  virtual bool exists
108  (
109  const fileName&,
110  const bool checkGzip=true,
111  const bool followLink = true
112  ) const;
113 
114  //- Does the name exist as a DIRECTORY in the file system?
115  virtual bool isDir
116  (
117  const fileName&,
118  const bool followLink = true
119  ) const;
120 
121  //- Does the name exist as a FILE in the file system?
122  // Optionally enable/disable check for gzip file.
123  virtual bool isFile
124  (
125  const fileName&,
126  const bool checkGzip=true,
127  const bool followLink = true
128  ) const;
129 
130  //- Return size of file
131  virtual off_t fileSize
132  (
133  const fileName&,
134  const bool followLink = true
135  ) const;
136 
137  //- Return time of last file modification
138  virtual time_t lastModified
139  (
140  const fileName&,
141  const bool followLink = true
142  ) const;
143 
144  //- Return time of last file modification
145  virtual double highResLastModified
146  (
147  const fileName&,
148  const bool followLink = true
149  ) const;
150 
151  //- Read a directory and return the entries as a string list
152  virtual fileNameList readDir
153  (
154  const fileName&,
156  const bool filtergz=true,
157  const bool followLink = true
158  ) const;
159 
160  //- Copy, recursively if necessary, the source to the destination
161  virtual bool cp
162  (
163  const fileName& src,
164  const fileName& dst,
165  const bool followLink = true
166  ) const;
167 
168  //- Create a softlink. dst should not exist. Returns true if
169  // successful.
170  virtual bool ln(const fileName& src, const fileName& dst) const;
171 
172  //- Rename src to dst
173  virtual bool mv
174  (
175  const fileName& src,
176  const fileName& dst,
177  const bool followLink = false
178  ) const;
179 
180  //- Rename to a corresponding backup file
181  // If the backup file already exists, attempt with
182  // "01" .. "99" suffix
183  virtual bool mvBak
184  (
185  const fileName&,
186  const std::string& ext = "bak"
187  ) const;
188 
189  //- Remove a file, returning true if successful otherwise false
190  virtual bool rm(const fileName&) const;
191 
192  //- Remove a directory and its contents
193  // \param dir the directory to remove
194  // \param silent do not report missing directory
195  // \param emptyOnly only remove empty directories (recursive)
196  virtual bool rmDir
197  (
198  const fileName& dir,
199  const bool silent = false,
200  const bool emptyOnly = false
201  ) const;
202 
203 
204  // (reg)IOobject functionality
205 
206  //- Search for an object. checkGlobal
207  virtual fileName filePath
208  (
209  const bool checkGlobal,
210  const IOobject& io,
211  const word& typeName,
212  const bool search
213  ) const;
214 
215  //- Search for a directory. checkGlobal
216  virtual fileName dirPath
217  (
218  const bool checkGlobal,
219  const IOobject& io,
220  const bool search
221  ) const;
222 
223  //- Search directory for objects. Used in IOobjectList.
224  virtual fileNameList readObjects
225  (
226  const objectRegistry& db,
227  const fileName& instance,
228  const fileName& local,
229  word& newInstance
230  ) const;
231 
232  //- Read object header from supplied file
233  virtual bool readHeader
234  (
235  IOobject&,
236  const fileName&,
237  const word& typeName
238  ) const;
239 
240  //- Reads header for regIOobject and returns an ISstream
241  //- to read the contents.
243  (
244  regIOobject&,
245  const fileName&,
246  const word& typeName,
247  const bool readOnProc = true
248  ) const;
249 
250  //- Top-level read
251  virtual bool read
252  (
253  regIOobject&,
254  const bool masterOnly,
256  const word& typeName
257  ) const;
258 
259  //- Generate an ISstream that reads a file
260  virtual autoPtr<ISstream> NewIFstream(const fileName&) const;
261 
262  //- Generate an OSstream that writes a file
264  (
265  const fileName& pathname,
266  IOstreamOption streamOpt = IOstreamOption(),
267  const bool writeOnProc = true
268  ) const;
269 
270  //- Generate an OSstream that writes a file
272  (
274  const fileName& pathname,
275  IOstreamOption streamOpt = IOstreamOption(),
276  const bool writeOnProc = true
277  ) const;
278 };
279 
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 } // End namespace fileOperations
284 } // End namespace Foam
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 #endif
289 
290 // ************************************************************************* //
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
virtual bool read(regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const
Top-level read.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
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 isFile(const fileName &, const bool checkGzip=true, const bool followLink=true) const
Does the name exist as a FILE in the file system?
A class for handling file names.
Definition: fileName.H:72
TypeNameNoDebug("dummy")
Runtime type information.
virtual double highResLastModified(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.
dummyFileOperation(bool verbose=false)
Default construct.
A simple container for options an IOstream can normally have.
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?
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
An encapsulation of filesystem-related operations.
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
virtual void storeComm() const
No managed communicator.
Dummy fileOperation, to be used as a placeholder for interfaces taking a reference to a fileOperation...
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
atomicType
Atomic operations (output)
A class for handling words, derived from Foam::string.
Definition: word.H:63
A regular file.
Definition: fileName.H:84
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
bool local
Definition: EEqn.H:20
virtual bool rmDir(const fileName &dir, const bool silent=false, const bool emptyOnly=false) const
Remove a directory and its contents.
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Generate an OSstream that writes a file.
word format(conversionProperties.get< word >("format"))
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.
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
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 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.
virtual bool good() const
This fileOperation is not really valid for anything.
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 fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:642
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual fileName filePath(const bool checkGlobal, const IOobject &io, const word &typeName, const bool search) const
Search for an object. checkGlobal.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Registry of regIOobjects.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Type
Enumerations to handle directory entry types.
Definition: fileName.H:81
Namespace for OpenFOAM.