casacore
Loading...
Searching...
No Matches
SymLink.h
Go to the documentation of this file.
1//# SymLink.h: Get information about, and manipulate symbolic links
2//# Copyright (C) 1996
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
27#ifndef CASA_SYMLINK_H
28#define CASA_SYMLINK_H
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/OS/Path.h>
33#include <casacore/casa/OS/File.h>
34
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38// <summary>
39// Get information about, and manipulate symbolic links
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 SymLink handles SYMbolic LINKs in the file system.
53// </etymology>
54
55// <synopsis>
56// SymLink provides functions to manipulate and to get information about
57// symbolic links. The functions for getting information (like ownership,
58// dates) about symbolic links are inherited from the
59// <linkto class=File>File</linkto> class.
60// <br>
61// The class SymLink itself provides functions to create, remove, copy, and
62// move symbolic links. There is a function readSymLink which reads a link and
63// then returns a path and there is a function followSymLink which reads a
64// link recursively. If the link eventually refers to itself (a loop),
65// an exception will be thrown.
66// </synopsis>
67
68// <example>
69// <srcblock>
70// SymLink symLink1("isLink");
71// SymLink symLink2("isLink2");
72// SymLink symLinkA("A");
73// SymLink symLinkB("B");
74//
75// symLink1.create("~", True); // Create a symbolic link to the home
76// // directory. When it exists it will be
77// // overwritten.
78// symLink2.create("isLink", False); // Create a symbolic link to
79// // isLink. When it exists it will not
80// // be overwritten.
81// symLinkA.create(Path("B")); // Create a recursive link
82// symLinkB.create(Path("A")); // Create a recursive link
83//
84// cout << symLink1.readSymLink() << endl; // The homedirectory is printed
85// cout << symLink2.readSymLink() << endl; // isLink is printed
86// cout << symLink2.followSymLink() << endl;// The homedirectory is printed
87// cout << symLinkA.readSymLink() << endl; // B is printed
88// cout << symLinkA.followSymLink() << endl;// An exception is thrown (loop)
89// </srcblock>
90// </example>
91
92// <motivation>
93// Provide functions for manipulating and getting information
94// about symbolic links.
95// </motivation>
96
97
98class SymLink: public File
99{
100public:
101
102 // The default constructor creates a SymLink with path ".".
104
105 // Create a SymLink with the given path.
106 // An exception is thrown if the path exist and is no symbolic link
107 // or if it does not exist, but cannot be created.
108 // <group>
109 SymLink (const Path& name);
110 SymLink (const String& name);
111 SymLink (const File& name);
112 // </group>
113
114 // Copy constructor (copy semantics).
115 SymLink (const SymLink& that);
116
118
119 // Assignment (copy semantics).
121
122 // Make a symbolic link to a file given by target.
123 // An exception will be thrown if:
124 // <br>-target already exists and is no symlink
125 // <br>-or target already exists and overwrite==False
126 // <group>
127 void create (const Path& target, Bool overwrite = True);
128 void create (const String& target, Bool overwrite = True);
129 // </group>
130
131 // Copy the symlink to the target path using the system command cp.
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 // <group>
138 void copy (const Path& target, Bool overwrite = True) const;
139 void copy (const String& target, Bool overwrite = True) const;
140 // </group>
141
142 // Move the symlink to the target path using the system command mv.
143 // The target path can be a directory or a file (as in mv).
144 // An exception is thrown if:
145 // <br>- the target directory is not writable
146 // <br>- or the target file already exists and overwrite==False
147 // <br>- or the target file already exists and is not writable
148 // <group>
149 void move (const Path& target, Bool overwrite = True);
150 void move (const String& target, Bool overwrite = True);
151 // </group>
152
153 // Remove a symbolic link.
154 void remove();
155
156 // Read value of a symbolic link and return it as a Path. If
157 // the symlink does not exist, an exception will be thrown.
158 // When the symlink points to a file with a relative name,
159 // the resulting file name gets prepended by the dirname of the symlink,
160 // which is similar to the way a shell handles symlinks.
161 // E.g.
162 // <srcblock>
163 // ls > subdir/a
164 // ln -s a subdir/b
165 // more subdir/b
166 // </srcblock>
167 // The more command shows the results of subdir/a.
169
170 // As readSymLink, but the entire symlink chain is followed
171 // when the symlinks points to other symlinks.
172 // An exception is thrown if this results in a loop (that is, if more
173 // than 25 links are encountered).
175
176private:
177 // Check if the path of the file is valid.
178 // Also resolve possible symlinks.
179 void checkPath() const;
180
181 // Get the value of the symlink.
183};
184
185
186inline void SymLink::create (const String& target, Bool overwrite)
187{
188 create (Path(target), overwrite);
189}
190inline void SymLink::copy (const String& target, Bool overwrite) const
191{
192 copy (Path(target), overwrite);
193}
194inline void SymLink::move (const String& target, Bool overwrite)
195{
196 move (Path(target), overwrite);
197}
198
199
200
201} //# NAMESPACE CASACORE - END
202
203#endif
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
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41