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-2021 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{
45namespace fileOperations
46{
47
48/*---------------------------------------------------------------------------*\
49 Class uncollatedFileOperation Declaration
50\*---------------------------------------------------------------------------*/
53:
54 public fileOperation
55{
56protected:
57
58 // Protected Member Functions
59
60 //- Search for an object.
61 // checkGlobal : also check undecomposed case
62 // isFile : true:check for file false:check for directory
64 (
65 const bool checkGlobal,
66 const bool isFile,
67 const IOobject& io,
68 const bool search
69 ) const;
70
71 //- Lookup name of processorsDDD using cache.
72 // \note Do not use any parallel synchronisation
73 // \return empty fileName if not found.
75 (
76 const fileName&
77 ) const;
78
79
80public:
81
82 //- Runtime type information
83 TypeName("uncollated");
84
85
86 // Constructors
87
88 //- Default construct
89 explicit uncollatedFileOperation(bool verbose);
90
91
92 //- Destructor
93 virtual ~uncollatedFileOperation() = default;
94
95
96 // Member Functions
97
98 // OSSpecific equivalents
99
100 //- Make directory
101 virtual bool mkDir(const fileName&, mode_t=0777) const;
102
103 //- Set the file mode
104 virtual bool chMod(const fileName&, const mode_t) const;
105
106 //- Return the file mode
107 virtual mode_t mode
108 (
109 const fileName&,
110 const bool followLink = true
111 ) const;
112
113 //- Return the file type: DIRECTORY, FILE or SYMLINK
114 virtual fileName::Type type
115 (
116 const fileName&,
117 const bool followLink = true
118 ) const;
119
120 //- Does the name exist (as DIRECTORY or FILE) in the file system?
121 // Optionally enable/disable check for gzip file.
122 virtual bool exists
123 (
124 const fileName&,
125 const bool checkGzip=true,
126 const bool followLink = true
127 ) const;
128
129 //- Does the name exist as a DIRECTORY in the file system?
130 virtual bool isDir
131 (
132 const fileName&,
133 const bool followLink = true
134 ) const;
135
136 //- Does the name exist as a FILE in the file system?
137 // Optionally enable/disable check for gzip file.
138 virtual bool isFile
139 (
140 const fileName&,
141 const bool checkGzip=true,
142 const bool followLink = true
143 ) const;
144
145 //- Return size of file
146 virtual off_t fileSize
147 (
148 const fileName&,
149 const bool followLink = true
150 ) const;
151
152 //- Return time of last file modification
153 virtual time_t lastModified
154 (
155 const fileName&,
156 const bool followLink = true
157 ) const;
158
159 //- Return time of last file modification
160 virtual double highResLastModified
161 (
162 const fileName&,
163 const bool followLink = true
164 ) const;
165
166 //- Read a directory and return the entries as a string list
167 virtual fileNameList readDir
168 (
169 const fileName&,
171 const bool filtergz=true,
172 const bool followLink = true
173 ) const;
174
175 //- Copy, recursively if necessary, the source to the destination
176 virtual bool cp
177 (
178 const fileName& src,
179 const fileName& dst,
180 const bool followLink = true
181 ) const;
182
183 //- Create a softlink. dst should not exist. Returns true if
184 // successful.
185 virtual bool ln(const fileName& src, const fileName& dst) const;
186
187 //- Rename src to dst
188 virtual bool mv
189 (
190 const fileName& src,
191 const fileName& dst,
192 const bool followLink = false
193 ) const;
194
195 //- Rename to a corresponding backup file
196 // If the backup file already exists, attempt with
197 // "01" .. "99" suffix
198 virtual bool mvBak
199 (
200 const fileName&,
201 const std::string& ext = "bak"
202 ) const;
203
204 //- Remove a file, returning true if successful otherwise false
205 virtual bool rm(const fileName&) const;
206
207 //- Remove a directory and its contents
208 virtual bool rmDir
209 (
210 const fileName& dir,
211 const bool silent = false
212 ) const;
213
214// //- Open a shared library. Return handle to library. Print error
215// // message if library cannot be loaded (check = true)
216// virtual void* dlOpen
217// (
218// const fileName& lib,
219// const bool check = true
220// ) const;
221
222
223 // (reg)IOobject functionality
224
225 //- Search for an object. checkGlobal : also check undecomposed case
226 virtual fileName filePath
227 (
228 const bool checkGlobal,
229 const IOobject& io,
230 const word& typeName,
231 const bool search
232 ) const;
233
234 //- Search for a directory. checkGlobal : also check undecomposed
235 // case
236 virtual fileName dirPath
237 (
238 const bool checkGlobal,
239 const IOobject& io,
240 const bool search
241 ) const;
242
243 //- Search directory for objects. Used in IOobjectList.
245 (
246 const objectRegistry& db,
247 const fileName& instance,
248 const fileName& local,
249 word& newInstance
250 ) const;
251
252 //- Read object header from supplied file
253 virtual bool readHeader
254 (
255 IOobject&,
256 const fileName&,
257 const word& typeName
258 ) const;
259
260 //- Reads header for regIOobject and returns an ISstream
261 // to read the contents.
263 (
265 const fileName&,
266 const word& typeName,
267 const bool procValid = true
268 ) const;
269
270 //- Top-level read
271 virtual bool read
272 (
274 const bool masterOnly,
276 const word& typeName
277 ) const;
278
279 //- Generate an ISstream that reads a file
280 virtual autoPtr<ISstream> NewIFstream(const fileName&) const;
281
282 //- Generate an OSstream that writes a file
284 (
285 const fileName& pathname,
286 IOstreamOption streamOpt = IOstreamOption(),
287 const bool valid = true
288 ) const;
289};
290
291
292// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293
294} // End namespace fileOperations
295} // End namespace Foam
296
297// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298
299#endif
300
301// ************************************************************************* //
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:170
The IOstreamOption is a simple container for options an IOstream can normally have.
streamFormat
Data format (ascii | binary)
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A class for handling file names.
Definition: fileName.H:76
Type
Enumerations to handle directory entry types.
Definition: fileName.H:81
@ FILE
A regular file.
Definition: fileName.H:83
An encapsulation of filesystem-related operations.
Definition: fileOperation.H:69
fileOperation that assumes file operations are local.
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 mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Generate an OSstream that writes a file.
virtual bool rmDir(const fileName &dir, const bool silent=false) const
Remove a directory and its 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. checkGlobal : also check undecomposed.
virtual ~uncollatedFileOperation()=default
Destructor.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &) const
Lookup name of processorsDDD using cache.
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 autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool procValid=true) const
Reads header for regIOobject and returns an ISstream.
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. checkGlobal : also check undecomposed case.
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:58
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A class for handling words, derived from Foam::string.
Definition: word.H:68
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:624
word format(conversionProperties.get< word >("format"))
const volScalarField & cp
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73