Loading...
Searching...
No Matches
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-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::fileOperations::uncollatedFileOperation
29
30Description
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
43namespace Foam
44{
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 mutable label managedComm_;
60
61
62 // Private Member Functions
63
64 //- Any initialisation steps after constructing
65 void init(bool verbose);
66
67
68protected:
69
70 // Protected Member Functions
71
72 //- Search for an object.
73 // checkGlobal : also check undecomposed case
74 // isFile : true:check for file false:check for directory
76 (
77 const bool checkGlobal,
78 const bool isFile,
79 const IOobject& io,
80 const bool search
81 ) const;
82
83 //- Lookup name of processorsDDD using cache.
84 // \note Do not use any parallel synchronisation
85 // \return empty fileName if not found.
87 (
88 const fileName& objectPath
89 ) const;
90
91
92public:
93
94 //- Runtime type information
95 TypeName("uncollated");
96
97
98 // Constructors
99
100 //- Default construct
101 explicit uncollatedFileOperation(bool verbose = false);
102
103 //- Construct from communicator with specified io-ranks
105 (
106 const Tuple2<label, labelList>& commAndIORanks,
107 const bool distributedRoots,
108 bool verbose = false
109 );
110
111
112 //- Destructor
113 virtual ~uncollatedFileOperation();
114
115
116 // Member Functions
117
118 //- Transfer ownership of communicator to this fileOperation.
119 //- Use with caution
120 virtual void storeComm() const;
121
122
123 // OSSpecific equivalents
124
125 //- Make directory
126 virtual bool mkDir(const fileName&, mode_t=0777) const;
127
128 //- Set the file mode
129 virtual bool chMod(const fileName&, const mode_t) const;
130
131 //- Return the file mode
132 virtual mode_t mode
133 (
134 const fileName&,
135 const bool followLink = true
136 ) const;
137
138 //- Return the file type: DIRECTORY, FILE or SYMLINK
139 virtual fileName::Type type
140 (
141 const fileName&,
142 const bool followLink = true
143 ) const;
144
145 //- Does the name exist (as DIRECTORY or FILE) in the file system?
146 // Optionally enable/disable check for gzip file.
147 virtual bool exists
148 (
149 const fileName&,
150 const bool checkGzip=true,
151 const bool followLink = true
152 ) const;
153
154 //- Does the name exist as a DIRECTORY in the file system?
155 virtual bool isDir
156 (
157 const fileName&,
158 const bool followLink = true
159 ) const;
160
161 //- Does the name exist as a FILE in the file system?
162 // Optionally enable/disable check for gzip file.
163 virtual bool isFile
164 (
165 const fileName&,
166 const bool checkGzip=true,
167 const bool followLink = true
168 ) const;
169
170 //- Return size of file
171 virtual off_t fileSize
172 (
173 const fileName&,
174 const bool followLink = true
175 ) const;
176
177 //- Return time of last file modification
178 virtual time_t lastModified
179 (
180 const fileName&,
181 const bool followLink = true
182 ) const;
183
184 //- Return time of last file modification
185 virtual double highResLastModified
186 (
187 const fileName&,
188 const bool followLink = true
189 ) const;
190
191 //- Read a directory and return the entries as a string list
192 virtual fileNameList readDir
193 (
194 const fileName&,
196 const bool filtergz=true,
197 const bool followLink = true
198 ) const;
199
200 //- Copy, recursively if necessary, the source to the destination
201 virtual bool cp
202 (
203 const fileName& src,
204 const fileName& dst,
205 const bool followLink = true
206 ) const;
207
208 //- Create a softlink. dst should not exist. Returns true if
209 // successful.
210 virtual bool ln(const fileName& src, const fileName& dst) const;
211
212 //- Rename src to dst
213 virtual bool mv
214 (
215 const fileName& src,
216 const fileName& dst,
217 const bool followLink = false
218 ) const;
219
220 //- Rename to a corresponding backup file
221 // If the backup file already exists, attempt with
222 // "01" .. "99" suffix
223 virtual bool mvBak
224 (
225 const fileName&,
226 const std::string& ext = "bak"
227 ) const;
228
229 //- Remove a file, returning true if successful otherwise false
230 virtual bool rm(const fileName&) const;
231
232 //- Remove a directory and its contents
233 // \param dir the directory to remove
234 // \param silent do not report missing directory
235 // \param emptyOnly only remove empty directories (recursive)
236 virtual bool rmDir
237 (
238 const fileName& dir,
239 const bool silent = false,
240 const bool emptyOnly = false
241 ) const;
242
243
244 // (reg)IOobject functionality
245
246 //- Search for an object
247 virtual fileName filePath
248 (
250 const bool checkGlobal,
251 const IOobject& io,
252 const word& typeName,
253 const bool search
254 ) const;
255
256 //- Search for a directory
257 virtual fileName dirPath
258 (
260 const bool checkGlobal,
261 const IOobject& io,
262 const bool search
263 ) const;
264
265 //- Search directory for objects. Used in IOobjectList.
267 (
268 const objectRegistry& db,
269 const fileName& instance,
270 const fileName& local,
271 word& newInstance
272 ) const;
273
274 //- Read object header from supplied file
275 virtual bool readHeader
276 (
277 IOobject&,
278 const fileName&,
279 const word& typeName
280 ) const;
281
282 //- Reads header for regIOobject and returns an ISstream
283 //- to read the contents.
285 (
287 const fileName&,
288 const word& typeName,
289 const bool readOnProc = true
290 ) const;
291
292 //- Top-level read
293 virtual bool read
294 (
296 const bool masterOnly,
300 const word& typeName
301 ) const;
302
303 //- Generate an ISstream that reads a file
304 virtual autoPtr<ISstream> NewIFstream(const fileName&) const;
305
306 //- Generate an OSstream that writes a file
308 (
309 const fileName& pathname,
310 IOstreamOption streamOpt = IOstreamOption(),
311 const bool writeOnProc = true
312 ) const;
313
314 //- Generate an OSstream that writes a file
316 (
318 const fileName& pathname,
319 IOstreamOption streamOpt = IOstreamOption(),
320 const bool writeOnProc = true
321 ) const;
322};
323
324
325// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
326
327} // End namespace fileOperations
328} // End namespace Foam
329
330// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331
332#endif
333
334// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A simple container for options an IOstream can normally have.
streamFormat
Data format (ascii | binary | coherent).
atomicType
Atomic operations (output).
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition Tuple2.H:51
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A class for handling file names.
Definition fileName.H:75
Type
Enumerations to handle directory entry types.
Definition fileName.H:82
@ FILE
A regular file.
Definition fileName.H:84
fileOperation(const label comm, const labelUList &ioRanks=labelUList::null(), const bool distributedRoots=false)
Construct from communicator, optionally with specified io-ranks and/or distributed roots.
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
TypeName("uncollated")
Runtime type information.
fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &io, const bool search) const
Search for an object.
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Generate an OSstream that writes a file.
virtual bool rmDir(const fileName &dir, const bool silent=false, const bool emptyOnly=false) const
Remove a directory and its contents.
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
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 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 readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
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 time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &objectPath) const
Lookup name of processorsDDD using cache.
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of 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?
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
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 bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
virtual fileName filePath(const bool checkGlobal, const IOobject &io, const word &typeName, const bool search) const
Search for an object.
uncollatedFileOperation(bool verbose=false)
Default construct.
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
Registry of regIOobjects.
A class for managing references or pointers (no reference counting).
Definition refPtr.H:54
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
A class for handling words, derived from Foam::string.
Definition word.H:66
bool local
Definition EEqn.H:20
const auto & io
Namespace for implementations of a fileOperation.
Definition regIOobject.H:60
Namespace for OpenFOAM.
List< fileName > fileNameList
List of fileName.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition fileName.C:642
word format(conversionProperties.get< word >("format"))
const volScalarField & cp
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68