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
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38// <summary>
39// Manipulate and get information about regular files
40// </summary>
41// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
42// </reviewed>
43
44// <use visibility=export>
45
46// <prerequisite>
47// <li>Basic knowledge of the UNIX file system
48// <li><linkto class=File>File</linkto>
49// </prerequisite>
50
51// <etymology>
52// The class RegularFile provides functions for manipulating and getting
53// information about regular files. Regular file are files which hold data.
54// </etymology>
55
56// <synopsis>
57// This class provides functions to manipulate and to get information about
58// regular files. The functions for getting information (like ownership, dates)
59// about regular files are inherited from the <linkto class=File>File</linkto>
60// class.
61// <br>
62// The class RegularFile itself provides functions to rename, remove, copy,
63// and move regular files. The file name can be a symbolic link resolving
64// (eventually) to a regular file.
65// </synopsis>
66
67// <example>
68// <srcblock>
69// // Create the object rFile
70// RegularFile rFile ("isFile");
71//
72// // Create file; if the file exists it will be overwritten
73// rFile.create (True);
74// rFile.copy (newPath);
75//
76// cout << rFile.size() << endl; // Get the size of the file
77// cout << rFile.path() << endl; // Show the relative pathname
78//
79// rFile.remove(); // remove the file
80// </srcblock>
81// </example>
82
83// <motivation>
84// Provide functions for manipulating and getting information
85// about regular files.
86// </motivation>
87
88
89class RegularFile: public File
90{
91public:
92
93 // Default constructor sets path to . (working directory).
95
96 // Create a regular file object for a file with the given path name.
97 // An exception is thrown if the file is illegal, i.e. if it does
98 // not exist as a regular file or symbolic link or if cannot be created.
99 // Note that the file is not created if it does not exist yet.
100 // This can be done using the function create.
101 // <br>
102 // When the given path name is a symbolic link, the symbolic link
103 // is resolved (recursively) and the resulting file name is used
104 // instead.
105 // <group>
108 RegularFile (const char* path);
109 RegularFile (const File& file);
110 // </group>
111
112 // Copy constructor (copy semantics).
113 RegularFile (const RegularFile& regularFile);
114
116
117 // Assignment (copy semantics).
118 RegularFile& operator= (const RegularFile& regularFile);
119
120 // Create the regular file.
121 // <br>If the file exists and is not a regular file, an
122 // exception is thrown. Otherwise if overwrite is true the regular file
123 // will be overwritten. If overwrite is false then nothing will be done.
124 // If the file does not exist, it is created.
125 void create (Bool overwrite = True);
126
127 // Remove the file.
128 // If it does not exist, an exception will be thrown.
129 // If a symbolic link is given, the link chain pointing to the file
130 // will also be removed.
131 void remove();
132
133 // Copy the file to the target path using the system command cp.
134 // If the file is a symbolic link, the regular file pointed to
135 // will be copied.
136 // The target path can be a directory or a file (as in cp).
137 // An exception is thrown if:
138 // <br>- the target directory is not writable
139 // <br>- or the target file already exists and overwrite==False
140 // <br>- or the target file already exists and is not writable
141 // <note role=caution>
142 // When a readonly file is copied, the resulting
143 // file is also readonly. Therefore <src>chmod</src> is used to
144 // set user write permission after the copy.
145 // The flag <src>setUserWritePermission</src> can be set to False
146 // when that should not be done.
147 // </note>
148 // <group>
149 void copy (const Path& target, Bool overwrite = True,
150 Bool setUserWritePermission = True) const;
151 void copy (const String& target, Bool overwrite = True,
152 Bool setUserWritePermission = True) const;
153 // </group>
154
155 // Copy the file manually in case the cp command cannot be used.
156 // (like on the Cray XT3).
157 static void manualCopy (const String& source, const String& target);
158
159 // Move the file to the target path using the system command mv.
160 // If the file is a symbolic link, the regular file pointed to
161 // will be moved.
162 // The target path can be a directory or a file (as in mv).
163 // An exception is thrown if:
164 // <br>- the target directory is not writable
165 // <br>- or the target file already exists and overwrite==False
166 // <br>- or the target file already exists and is not writable
167 // <note role=tip> The system command mv is used instead of the
168 // library function rename to be able to move across file systems.
169 // </note>
170 // <group>
171 void move (const Path& target, Bool overwrite = True);
172 void move (const String& target, Bool overwrite = True);
173 // </group>
174
175 // Return the size of the file. If the file
176 // does not exist, an exception will be thrown.
177 virtual Int64 size() const;
178
179private:
180 // Check if the path of the file is valid.
181 // Also resolve possible symlinks.
182 void checkPath();
183
184 // This variable is used when a symbolic link points to the file.
186};
187
188
189inline void RegularFile::copy (const String& target, Bool overwrite,
190 Bool setUserWritePermission) const
191{
192 copy (Path(target), overwrite, setUserWritePermission);
193}
194inline void RegularFile::move (const String& target, Bool overwrite)
195{
196 move (Path(target), overwrite);
197}
198
199
200
201} //# NAMESPACE CASACORE - END
202
203#endif
const Path & path() const
Returns the pathname of the file.
Definition File.h:308
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:223
this file contains all the compiler specific defines
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