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 -------------------------------------------------------------------------------
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 fileOperations_uncollatedFileOperation_H
36 #define 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 protected:
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 
80 public:
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 LINK
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.
244  virtual fileNameList readObjects
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  (
264  regIOobject&,
265  const fileName&,
266  const word& typeName,
267  const bool procValid = true
268  ) const;
269 
270  //- Top-level read
271  virtual bool read
272  (
273  regIOobject&,
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 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Foam::fileName::FILE
A file.
Definition: fileName.H:83
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileOperation
An encapsulation of filesystem-related operations.
Definition: fileOperation.H:68
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::fileOperations::uncollatedFileOperation::mkDir
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
Definition: uncollatedFileOperation.C:201
Foam::fileOperations::uncollatedFileOperation::rm
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
Definition: uncollatedFileOperation.C:313
Foam::fileName::Type
Type
Enumerations to handle directory entry types.
Definition: fileName.H:80
Foam::fileOperations::uncollatedFileOperation::mode
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
Definition: uncollatedFileOperation.C:221
Foam::fileOperations::uncollatedFileOperation::filePathInfo
fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &io, const bool search) const
Search for an object.
Definition: uncollatedFileOperation.C:61
Foam::fileOperations::uncollatedFileOperation::mvBak
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
Definition: uncollatedFileOperation.C:303
Foam::fileOperations::uncollatedFileOperation::dirPath
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory. checkGlobal : also check undecomposed.
Definition: uncollatedFileOperation.C:404
Foam::fileOperations::uncollatedFileOperation::lookupProcessorsPath
virtual refPtr< dirIndexList > lookupProcessorsPath(const fileName &) const
Lookup name of processorsDDD using cache.
Definition: uncollatedFileOperation.C:172
Foam::fileOperations::uncollatedFileOperation::chMod
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
Definition: uncollatedFileOperation.C:211
Foam::fileOperations::uncollatedFileOperation::filePath
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.
Definition: uncollatedFileOperation.C:376
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::fileOperations::uncollatedFileOperation::fileSize
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
Definition: uncollatedFileOperation.C:273
format
word format(conversionProperties.get< word >("format"))
Foam::fileOperations::uncollatedFileOperation::readHeader
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
Definition: uncollatedFileOperation.C:480
Foam::fileOperations::uncollatedFileOperation::~uncollatedFileOperation
virtual ~uncollatedFileOperation()=default
Destructor.
Foam::fileOperations::uncollatedFileOperation::highResLastModified
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
Definition: uncollatedFileOperation.C:293
Foam::fileOperations::uncollatedFileOperation::mv
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
Definition: uncollatedFileOperation.C:365
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
fileOperation.H
Foam::fileOperations::uncollatedFileOperation::readObjects
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
Definition: uncollatedFileOperation.C:431
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fileOperations::uncollatedFileOperation::TypeName
TypeName("uncollated")
Runtime type information.
Foam::fileOperations::uncollatedFileOperation::NewIFstream
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
Definition: uncollatedFileOperation.C:703
Foam::fileOperations::uncollatedFileOperation::read
virtual bool read(regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const
Top-level read.
Definition: uncollatedFileOperation.C:609
Foam::fileOperations::uncollatedFileOperation::readDir
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.
Definition: uncollatedFileOperation.C:332
Foam::fileOperations::uncollatedFileOperation::isDir
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
Definition: uncollatedFileOperation.C:252
Foam::fileOperations::uncollatedFileOperation::rmDir
virtual bool rmDir(const fileName &dir, const bool silent=false) const
Remove a directory and its contents.
Definition: uncollatedFileOperation.C:322
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
Foam::fileOperations::uncollatedFileOperation
fileOperation that assumes file operations are local.
Definition: uncollatedFileOperation.H:51
Foam::List< fileName >
Foam::fileOperations::uncollatedFileOperation::ln
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
Definition: uncollatedFileOperation.C:355
Foam::fileOperations::uncollatedFileOperation::uncollatedFileOperation
uncollatedFileOperation(bool verbose)
Default construct.
Definition: uncollatedFileOperation.C:184
Foam::search
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:571
Foam::fileOperations::uncollatedFileOperation::exists
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?
Definition: uncollatedFileOperation.C:241
Foam::fileOperations::uncollatedFileOperation::readStream
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool procValid=true) const
Reads header for regIOobject and returns an ISstream.
Definition: uncollatedFileOperation.C:528
Foam::fileOperations::uncollatedFileOperation::cp
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
Definition: uncollatedFileOperation.C:344
Foam::fileOperations::uncollatedFileOperation::NewOFstream
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Generate an OSstream that writes a file.
Definition: uncollatedFileOperation.C:713
Foam::fileOperations::uncollatedFileOperation::isFile
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?
Definition: uncollatedFileOperation.C:262
Foam::fileOperations::uncollatedFileOperation::type
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or LINK.
Definition: uncollatedFileOperation.C:231
Foam::refPtr
A class for managing references or pointers (no reference counting)
Definition: PtrList.H:60
Foam::fileOperations::uncollatedFileOperation::lastModified
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
Definition: uncollatedFileOperation.C:283