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#ifndef CASA_SYMLINK_H
27#define CASA_SYMLINK_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
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Get information about, and manipulate symbolic links
38// </summary>
39// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
40// </reviewed>
41
42// <use visibility=export>
43
44// <prerequisite>
45// <li> Basic knowledge of the UNIX file system
46// <li> <linkto class=File>File</linkto>
47// </prerequisite>
48
49// <etymology>
50// The class SymLink handles SYMbolic LINKs in the file system.
51// </etymology>
52
53// <synopsis>
54// SymLink provides functions to manipulate and to get information about
55// symbolic links. The functions for getting information (like ownership,
56// dates) about symbolic links are inherited from the
57// <linkto class=File>File</linkto> class.
58// <br>
59// The class SymLink itself provides functions to create, remove, copy, and
60// move symbolic links. There is a function readSymLink which reads a link and
61// then returns a path and there is a function followSymLink which reads a
62// link recursively. If the link eventually refers to itself (a loop),
63// an exception will be thrown.
64// </synopsis>
65
66// <example>
67// <srcblock>
68// SymLink symLink1("isLink");
69// SymLink symLink2("isLink2");
70// SymLink symLinkA("A");
71// SymLink symLinkB("B");
72//
73// symLink1.create("~", True); // Create a symbolic link to the home
74// // directory. When it exists it will be
75// // overwritten.
76// symLink2.create("isLink", False); // Create a symbolic link to
77// // isLink. When it exists it will not
78// // be overwritten.
79// symLinkA.create(Path("B")); // Create a recursive link
80// symLinkB.create(Path("A")); // Create a recursive link
81//
82// cout << symLink1.readSymLink() << endl; // The homedirectory is printed
83// cout << symLink2.readSymLink() << endl; // isLink is printed
84// cout << symLink2.followSymLink() << endl;// The homedirectory is printed
85// cout << symLinkA.readSymLink() << endl; // B is printed
86// cout << symLinkA.followSymLink() << endl;// An exception is thrown (loop)
87// </srcblock>
88// </example>
89
90// <motivation>
91// Provide functions for manipulating and getting information
92// about symbolic links.
93// </motivation>
94
95class SymLink : public File {
96 public:
97 // The default constructor creates a SymLink with path ".".
99
100 // Create a SymLink with the given path.
101 // An exception is thrown if the path exist and is no symbolic link
102 // or if it does not exist, but cannot be created.
103 // <group>
107 // </group>
108
109 // Copy constructor (copy semantics).
110 SymLink(const SymLink& that);
111
113
114 // Assignment (copy semantics).
115 SymLink& operator=(const SymLink& that);
116
117 // Make a symbolic link to a file given by target.
118 // An exception will be thrown if:
119 // <br>-target already exists and is no symlink
120 // <br>-or target already exists and overwrite==False
121 // <group>
122 void create(const Path& target, Bool overwrite = True);
123 void create(const String& target, Bool overwrite = True);
124 // </group>
125
126 // Copy the symlink to the target path using the system command cp.
127 // The target path can be a directory or a file (as in cp).
128 // An exception is thrown if:
129 // <br>- the target directory is not writable
130 // <br>- or the target file already exists and overwrite==False
131 // <br>- or the target file already exists and is not writable
132 // <group>
133 void copy(const Path& target, Bool overwrite = True) const;
134 void copy(const String& target, Bool overwrite = True) const;
135 // </group>
136
137 // Move the symlink to the target path using the system command mv.
138 // The target path can be a directory or a file (as in mv).
139 // An exception is thrown if:
140 // <br>- the target directory is not writable
141 // <br>- or the target file already exists and overwrite==False
142 // <br>- or the target file already exists and is not writable
143 // <group>
144 void move(const Path& target, Bool overwrite = True);
145 void move(const String& target, Bool overwrite = True);
146 // </group>
147
148 // Remove a symbolic link.
149 void remove();
150
151 // Read value of a symbolic link and return it as a Path. If
152 // the symlink does not exist, an exception will be thrown.
153 // When the symlink points to a file with a relative name,
154 // the resulting file name gets prepended by the dirname of the symlink,
155 // which is similar to the way a shell handles symlinks.
156 // E.g.
157 // <srcblock>
158 // ls > subdir/a
159 // ln -s a subdir/b
160 // more subdir/b
161 // </srcblock>
162 // The more command shows the results of subdir/a.
164
165 // As readSymLink, but the entire symlink chain is followed
166 // when the symlinks points to other symlinks.
167 // An exception is thrown if this results in a loop (that is, if more
168 // than 25 links are encountered).
170
171 private:
172 // Check if the path of the file is valid.
173 // Also resolve possible symlinks.
174 void checkPath() const;
175
176 // Get the value of the symlink.
178};
179
180inline void SymLink::create(const String& target, Bool overwrite) {
181 create(Path(target), overwrite);
182}
183inline void SymLink::copy(const String& target, Bool overwrite) const {
184 copy(Path(target), overwrite);
185}
186inline void SymLink::move(const String& target, Bool overwrite) { move(Path(target), overwrite); }
187
188} // namespace casacore
189
190#endif
File()
Construct a File object whose Path is set to the current working directory.
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
String name() const
Return the name of the field.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41