casacore
Loading...
Searching...
No Matches
RegularFile.h
Go to the documentation of this file.
1// # RegularFile.h: Manipulate and get information about regular files
2// # Copyright (C) 1993,1994,1995,1996,1997,2003
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_REGULARFILE_H
27#define CASA_REGULARFILE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/OS/Path.h>
32#include <casacore/casa/OS/File.h>
33#include <casacore/casa/BasicSL/String.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// <summary>
38// Manipulate and get information about regular files
39// </summary>
40// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
41// </reviewed>
42
43// <use visibility=export>
44
45// <prerequisite>
46// <li>Basic knowledge of the UNIX file system
47// <li><linkto class=File>File</linkto>
48// </prerequisite>
49
50// <etymology>
51// The class RegularFile provides functions for manipulating and getting
52// information about regular files. Regular file are files which hold data.
53// </etymology>
54
55// <synopsis>
56// This class provides functions to manipulate and to get information about
57// regular files. The functions for getting information (like ownership, dates)
58// about regular files are inherited from the <linkto class=File>File</linkto>
59// class.
60// <br>
61// The class RegularFile itself provides functions to rename, remove, copy,
62// and move regular files. The file name can be a symbolic link resolving
63// (eventually) to a regular file.
64// </synopsis>
65
66// <example>
67// <srcblock>
68// // Create the object rFile
69// RegularFile rFile ("isFile");
70//
71// // Create file; if the file exists it will be overwritten
72// rFile.create (True);
73// rFile.copy (newPath);
74//
75// cout << rFile.size() << endl; // Get the size of the file
76// cout << rFile.path() << endl; // Show the relative pathname
77//
78// rFile.remove(); // remove the file
79// </srcblock>
80// </example>
81
82// <motivation>
83// Provide functions for manipulating and getting information
84// about regular files.
85// </motivation>
86
87class RegularFile : public File {
88 public:
89 // Default constructor sets path to . (working directory).
91
92 // Create a regular file object for a file with the given path name.
93 // An exception is thrown if the file is illegal, i.e. if it does
94 // not exist as a regular file or symbolic link or if cannot be created.
95 // Note that the file is not created if it does not exist yet.
96 // This can be done using the function create.
97 // <br>
98 // When the given path name is a symbolic link, the symbolic link
99 // is resolved (recursively) and the resulting file name is used
100 // instead.
101 // <group>
104 RegularFile(const char* path);
105 RegularFile(const File& file);
106 // </group>
107
108 // Copy constructor (copy semantics).
109 RegularFile(const RegularFile& regularFile);
110
112
113 // Assignment (copy semantics).
114 RegularFile& operator=(const RegularFile& regularFile);
115
116 // Create the regular file.
117 // <br>If the file exists and is not a regular file, an
118 // exception is thrown. Otherwise if overwrite is true the regular file
119 // will be overwritten. If overwrite is false then nothing will be done.
120 // If the file does not exist, it is created.
121 void create(Bool overwrite = True);
122
123 // Remove the file.
124 // If it does not exist, an exception will be thrown.
125 // If a symbolic link is given, the link chain pointing to the file
126 // will also be removed.
127 void remove();
128
129 // Copy the file to the target path using the system command cp.
130 // If the file is a symbolic link, the regular file pointed to
131 // will be copied.
132 // The target path can be a directory or a file (as in cp).
133 // An exception is thrown if:
134 // <br>- the target directory is not writable
135 // <br>- or the target file already exists and overwrite==False
136 // <br>- or the target file already exists and is not writable
137 // <note role=caution>
138 // When a readonly file is copied, the resulting
139 // file is also readonly. Therefore <src>chmod</src> is used to
140 // set user write permission after the copy.
141 // The flag <src>setUserWritePermission</src> can be set to False
142 // when that should not be done.
143 // </note>
144 // <group>
145 void copy(const Path& target, Bool overwrite = True, Bool setUserWritePermission = True) const;
146 void copy(const String& target, Bool overwrite = True, Bool setUserWritePermission = True) const;
147 // </group>
148
149 // Copy the file manually in case the cp command cannot be used.
150 // (like on the Cray XT3).
151 static void manualCopy(const String& source, const String& target);
152
153 // Move the file to the target path using the system command mv.
154 // If the file is a symbolic link, the regular file pointed to
155 // will be moved.
156 // The target path can be a directory or a file (as in mv).
157 // An exception is thrown if:
158 // <br>- the target directory is not writable
159 // <br>- or the target file already exists and overwrite==False
160 // <br>- or the target file already exists and is not writable
161 // <note role=tip> The system command mv is used instead of the
162 // library function rename to be able to move across file systems.
163 // </note>
164 // <group>
165 void move(const Path& target, Bool overwrite = True);
166 void move(const String& target, Bool overwrite = True);
167 // </group>
168
169 // Return the size of the file. If the file
170 // does not exist, an exception will be thrown.
171 virtual Int64 size() const;
172
173 private:
174 // Check if the path of the file is valid.
175 // Also resolve possible symlinks.
176 void checkPath();
177
178 // This variable is used when a symbolic link points to the file.
180};
181
182inline void RegularFile::copy(const String& target, Bool overwrite,
183 Bool setUserWritePermission) const {
184 copy(Path(target), overwrite, setUserWritePermission);
185}
186inline void RegularFile::move(const String& target, Bool overwrite) {
187 move(Path(target), overwrite);
188}
189
190} // namespace casacore
191
192#endif
const Path & path() const
Returns the pathname of the file.
Definition File.h:300
File()
Construct a File object whose Path is set to the current working directory.
RegularFile(const File &file)
void move(const Path &target, Bool overwrite=True)
Move the file to the target path using the system command mv.
void remove()
Remove the file.
RegularFile & operator=(const RegularFile &regularFile)
Assignment (copy semantics).
static void manualCopy(const String &source, const String &target)
Copy the file manually in case the cp command cannot be used.
RegularFile(const RegularFile &regularFile)
Copy constructor (copy semantics).
RegularFile(const char *path)
RegularFile(const String &path)
RegularFile()
Default constructor sets path to.
void copy(const Path &target, Bool overwrite=True, Bool setUserWritePermission=True) const
Copy the file to the target path using the system command cp.
File itsFile
This variable is used when a symbolic link points to the file.
virtual Int64 size() const
Return the size of the file.
RegularFile(const Path &path)
Create a regular file object for a file with the given path name.
void create(Bool overwrite=True)
Create the regular file.
void checkPath()
Check if the path of the file is valid.
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41