casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | List of all members
casacore::SymLink Class Reference

Get information about, and manipulate symbolic links. More...

#include <SymLink.h>

Inheritance diagram for casacore::SymLink:
casacore::File

Public Member Functions

 SymLink ()
 The default constructor creates a SymLink with path ".". More...
 
 SymLink (const Path &name)
 Create a SymLink with the given path. More...
 
 SymLink (const String &name)
 
 SymLink (const File &name)
 
 SymLink (const SymLink &that)
 Copy constructor (copy semantics). More...
 
 ~SymLink ()
 
SymLinkoperator= (const SymLink &that)
 Assignment (copy semantics). More...
 
void create (const Path &target, Bool overwrite=True)
 Make a symbolic link to a file given by target. More...
 
void create (const String &target, Bool overwrite=True)
 
void copy (const Path &target, Bool overwrite=True) const
 Copy the symlink to the target path using the system command cp. More...
 
void copy (const String &target, Bool overwrite=True) const
 
void move (const Path &target, Bool overwrite=True)
 Move the symlink to the target path using the system command mv. More...
 
void move (const String &target, Bool overwrite=True)
 
void remove ()
 Remove a symbolic link. More...
 
Path readSymLink () const
 Read value of a symbolic link and return it as a Path. More...
 
Path followSymLink () const
 As readSymLink, but the entire symlink chain is followed when the symlinks points to other symlinks. More...
 
- Public Member Functions inherited from casacore::File
 File ()
 Construct a File object whose Path is set to the current working directory. More...
 
 File (const Path &path)
 Construct a File object whose Path is set to the given Path. More...
 
 File (const String &path)
 
 File (const File &that)
 Copy constructor (copy semantics). More...
 
virtual ~File ()
 
Fileoperator= (const File &that)
 Assignment (copy semantics). More...
 
const Pathpath () const
 Returns the pathname of the file. More...
 
Bool isRegular (Bool followSymLink=True) const
 Check if the file is a regular file. More...
 
Bool isDirectory (Bool followSymLink=True) const
 Check if the file is a directory. More...
 
Bool isSymLink () const
 Check if the file is a symbolic link. More...
 
Bool isPipe () const
 Check if the file is a pipe. More...
 
Bool isCharacterSpecial () const
 Check if the file is a character special file. More...
 
Bool isBlockSpecial () const
 Check if the file is a block special file. More...
 
Bool isSocket () const
 Check if the file is a socket. More...
 
Bool exists () const
 Check if the file exists. More...
 
Bool isReadable () const
 Check if the file is readable. More...
 
Bool isWritable () const
 Check if the file is writable. More...
 
Bool isExecutable () const
 Check if the file is executable. More...
 
Bool canCreate () const
 Check if a file can be created. More...
 
long userID () const
 Return the userID of the file. More...
 
long groupID () const
 Return the groupID of the file. More...
 
virtual Int64 size () const
 Return the size of the file. More...
 
uInt readPermissions () const
 Return the permissions as a decimal value. More...
 
void setPermissions (uInt permissions)
 Set permission with perm. More...
 
void touch (uInt time)
 Update access time and modification time of a file. More...
 
void touch ()
 Update access time and modification time of a file. More...
 
uInt accessTime () const
 Time related fucnctions: Return the time when the file was last accessed in seconds since 00:00:00 GMT Jan 1, 1970. More...
 
String accessTimeString () const
 Return the time when the file was last accessed as a 26-characters String of the form: Thu Feb 3 13:40:11 1994. More...
 
uInt modifyTime () const
 Return the time when the file was last modified in seconds since 00:00:00 GMT Jan 1, 1970. More...
 
String modifyTimeString () const
 Return the time when the file was last modified as a 26-characters String of the form: Thu Feb 3 13:40:11 1994. More...
 
uInt statusChangeTime () const
 Return the time when the file status was last changed in seconds since 00:00:00 GMT Jan 1, 1970. More...
 
String statusChangeTimeString () const
 return the time when the file status was last changed as a 26-characters String of the form: Thu Feb 3 13:40:11 1994 More...
 
FileWriteStatus getWriteStatus () const
 get write status of the file. More...
 
String getFSType () const
 Return the filesystem type. More...
 

Private Member Functions

void checkPath () const
 Check if the path of the file is valid. More...
 
String getSymLink () const
 Get the value of the symlink. More...
 

Additional Inherited Members

- Public Types inherited from casacore::File
enum  FileWriteStatus {
  OVERWRITABLE,
  NOT_OVERWRITABLE,
  CREATABLE,
  NOT_CREATABLE
}
 
- Static Public Member Functions inherited from casacore::File
static Path newUniqueName (const String &directory, const String &prefix)
 Create a new unique path name in the specified directory, with the specified prefix and random trailing characters: More...
 
static Path newUniqueName (const String &directory)
 Create a new unique filename without a prefix. More...
 
- Protected Member Functions inherited from casacore::File
void removeSymLinks ()
 This function is used by RegularFile and Directory to remove all the links which, when followed, ultimately resolve to a Directory or a RegularFile. More...
 
void checkTarget (Path &targetName, Bool overwrite, Bool forDirectory=False) const
 Check if the new path for a copy or move is valid. More...
 

Detailed Description

Get information about, and manipulate symbolic links.

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Intended use:

Public interface

Prerequisite

Etymology

The class SymLink handles SYMbolic LINKs in the file system.

Synopsis

SymLink provides functions to manipulate and to get information about symbolic links. The functions for getting information (like ownership, dates) about symbolic links are inherited from the File class.
The class SymLink itself provides functions to create, remove, copy, and move symbolic links. There is a function readSymLink which reads a link and then returns a path and there is a function followSymLink which reads a link recursively. If the link eventually refers to itself (a loop), an exception will be thrown.

Example

SymLink symLink1("isLink");
SymLink symLink2("isLink2");
SymLink symLinkA("A");
SymLink symLinkB("B");
symLink1.create("~", True); // Create a symbolic link to the home
// directory. When it exists it will be
// overwritten.
symLink2.create("isLink", False); // Create a symbolic link to
// isLink. When it exists it will not
// be overwritten.
symLinkA.create(Path("B")); // Create a recursive link
symLinkB.create(Path("A")); // Create a recursive link
cout << symLink1.readSymLink() << endl; // The homedirectory is printed
cout << symLink2.readSymLink() << endl; // isLink is printed
cout << symLink2.followSymLink() << endl;// The homedirectory is printed
cout << symLinkA.readSymLink() << endl; // B is printed
cout << symLinkA.followSymLink() << endl;// An exception is thrown (loop)

Motivation

Provide functions for manipulating and getting information about symbolic links.

Definition at line 100 of file SymLink.h.

Constructor & Destructor Documentation

casacore::SymLink::SymLink ( )

The default constructor creates a SymLink with path ".".

casacore::SymLink::SymLink ( const Path name)

Create a SymLink with the given path.

An exception is thrown if the path exist and is no symbolic link or if it does not exist, but cannot be created.

casacore::SymLink::SymLink ( const String name)
casacore::SymLink::SymLink ( const File name)
casacore::SymLink::SymLink ( const SymLink that)

Copy constructor (copy semantics).

casacore::SymLink::~SymLink ( )

Member Function Documentation

void casacore::SymLink::checkPath ( ) const
private

Check if the path of the file is valid.

Also resolve possible symlinks.

void casacore::SymLink::copy ( const Path target,
Bool  overwrite = True 
) const

Copy the symlink to the target path using the system command cp.

The target path can be a directory or a file (as in cp). An exception is thrown if:
- the target directory is not writable
- or the target file already exists and overwrite==False
- or the target file already exists and is not writable

Referenced by copy().

void casacore::SymLink::copy ( const String target,
Bool  overwrite = True 
) const
inline

Definition at line 192 of file SymLink.h.

References copy().

void casacore::SymLink::create ( const Path target,
Bool  overwrite = True 
)

Make a symbolic link to a file given by target.

An exception will be thrown if:
-target already exists and is no symlink
-or target already exists and overwrite==False

Referenced by create().

void casacore::SymLink::create ( const String target,
Bool  overwrite = True 
)
inline

Definition at line 188 of file SymLink.h.

References create().

Path casacore::SymLink::followSymLink ( ) const

As readSymLink, but the entire symlink chain is followed when the symlinks points to other symlinks.

An exception is thrown if this results in a loop (that is, if more than 25 links are encountered).

String casacore::SymLink::getSymLink ( ) const
private

Get the value of the symlink.

void casacore::SymLink::move ( const Path target,
Bool  overwrite = True 
)

Move the symlink to the target path using the system command mv.

The target path can be a directory or a file (as in mv). An exception is thrown if:
- the target directory is not writable
- or the target file already exists and overwrite==False
- or the target file already exists and is not writable

Referenced by move().

void casacore::SymLink::move ( const String target,
Bool  overwrite = True 
)
inline

Definition at line 196 of file SymLink.h.

References move().

SymLink& casacore::SymLink::operator= ( const SymLink that)

Assignment (copy semantics).

Path casacore::SymLink::readSymLink ( ) const

Read value of a symbolic link and return it as a Path.

If the symlink does not exist, an exception will be thrown. When the symlink points to a file with a relative name, the resulting file name gets prepended by the dirname of the symlink, which is similar to the way a shell handles symlinks. E.g.

ls > subdir/a
ln -s a subdir/b
more subdir/b

The more command shows the results of subdir/a.

void casacore::SymLink::remove ( )

Remove a symbolic link.


The documentation for this class was generated from the following file: