Loading...
Searching...
No Matches
casacore::RegularFile Class Reference
casa package (libcasa_casa) » OS_module

More...

`#include <RegularFile.h>`

## Public Member Functions

| RegularFile ()
| Default constructor sets path to.
| RegularFile (const Path &path)
| Create a regular file object for a file with the given path name.
| RegularFile (const String &path)
| RegularFile (const char *path)
| RegularFile (const File &file)
| RegularFile (const RegularFile &regularFile)
| Copy constructor (copy semantics).
| ~RegularFile ()
RegularFile & | operator= (const RegularFile &regularFile)
| Assignment (copy semantics).
void | create (Bool overwrite=True)
| Create the regular file.
void | remove ()
| Remove the file.
void | copy (const Path &target, Bool overwrite=True, Bool setUserWritePermission=True) const
| Copy the file to the target path using the system command cp.
void | copy (const String &target, Bool overwrite=True, Bool setUserWritePermission=True) const
void | move (const Path &target, Bool overwrite=True)
| Move the file to the target path using the system command mv.
void | move (const String &target, Bool overwrite=True)
virtual Int64 | size () const
| Return the size of the file.
Public Member Functions inherited from casacore::File
| File ()
| Construct a File object whose Path is set to the current working directory.
| File (const Path &path)
| Construct a File object whose Path is set to the given Path.
| File (const String &path)
| File (const File &that)
| Copy constructor (copy semantics).
virtual | ~File ()
File & | operator= (const File &that)
| Assignment (copy semantics).
const Path & | path () const
| Returns the pathname of the file.
Bool | isRegular (Bool followSymLink=True) const
| Check if the file is a regular file.
Bool | isDirectory (Bool followSymLink=True) const
| Check if the file is a directory.
Bool | isSymLink () const
| Check if the file is a symbolic link.
Bool | isPipe () const
| Check if the file is a pipe.
Bool | isCharacterSpecial () const
| Check if the file is a character special file.
Bool | isBlockSpecial () const
| Check if the file is a block special file.
Bool | isSocket () const
| Check if the file is a socket.
Bool | exists () const
| Check if the file exists.
Bool | isReadable () const
| Check if the file is readable.
Bool | isWritable () const
| Check if the file is writable.
Bool | isExecutable () const
| Check if the file is executable.
Bool | canCreate () const
| Check if a file can be created.
long | userID () const
| Return the userID of the file.
long | groupID () const
| Return the groupID of the file.
uInt | readPermissions () const
| Return the permissions as a decimal value.
void | setPermissions (uInt permissions)
| Set permission with perm.
void | touch (uInt time)
| Update access time and modification time of a file.
void | touch ()
| Update access time and modification time of a file.
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.
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.
uInt | modifyTime () const
| Return the time when the file was last modified in seconds since 00:00:00 GMT Jan 1, 1970.
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.
uInt | statusChangeTime () const
| Return the time when the file status was last changed in seconds since 00:00:00 GMT Jan 1, 1970.
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
FileWriteStatus | getWriteStatus () const
| get write status of the file.
String | getFSType () const
| Return the filesystem type.

## Static Public Member Functions

static void | manualCopy (const String &source, const String &target)
| Copy the file manually in case the cp command cannot be used.
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:
static Path | newUniqueName (const String &directory)
| Create a new unique filename without a prefix.

## Private Member Functions

void | checkPath ()
| Check if the path of the file is valid.

## Private Attributes

File | itsFile
| This variable is used when a symbolic link points to the file.

## Additional Inherited Members

Public Types inherited from casacore::File
enum | FileWriteStatus { OVERWRITABLE , NOT_OVERWRITABLE , CREATABLE , NOT_CREATABLE }
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.
void | checkTarget (Path &targetName, Bool overwrite, Bool forDirectory=False) const
| Check if the new path for a copy or move is valid.

## Detailed Description

Manipulate and get information about regular files

### Review Status

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

### Intended use:

Public interface

### Prerequisite

- Basic knowledge of the UNIX file system
- File

### Etymology

The class RegularFile provides functions for manipulating and getting information about regular files. Regular file are files which hold data.

### Synopsis

This class provides functions to manipulate and to get information about regular files. The functions for getting information (like ownership, dates) about regular files are inherited from the File class.
The class RegularFile itself provides functions to rename, remove, copy, and move regular files. The file name can be a symbolic link resolving (eventually) to a regular file.

### Example

// Create the object rFile
RegularFile rFile ("isFile");
// Create file; if the file exists it will be overwritten
rFile.create (True);
rFile.copy (newPath);
cout << rFile.size() << endl; // Get the size of the file
cout << rFile.path() << endl; // Show the relative pathname
rFile.remove(); // remove the file
casacore::RegularFile::RegularFile
RegularFile()
Default constructor sets path to.
casacore::True
const Bool True
Definition aipstype.h:41

### Motivation

Provide functions for manipulating and getting information about regular files.

Definition at line 89 of file RegularFile.h.

## Constructor & Destructor Documentation

## RegularFile() [1/6]

casacore::RegularFile::RegularFile | ( |  | ) |

Default constructor sets path to.

(working directory).

Referenced by operator=(), and RegularFile().

## RegularFile() [2/6]

casacore::RegularFile::RegularFile | ( | const Path & | path | ) |

Create a regular file object for a file with the given path name.

An exception is thrown if the file is illegal, i.e. if it does not exist as a regular file or symbolic link or if cannot be created. Note that the file is not created if it does not exist yet. This can be done using the function create.
When the given path name is a symbolic link, the symbolic link is resolved (recursively) and the resulting file name is used instead.

References casacore::File::path().

## RegularFile() [3/6]

casacore::RegularFile::RegularFile | ( | const String & | path | ) |

References casacore::File::path().

## RegularFile() [4/6]

casacore::RegularFile::RegularFile | ( | const char * | path | ) |

References casacore::File::path().

## RegularFile() [5/6]

casacore::RegularFile::RegularFile | ( | const File & | file | ) |

References casacore::File::File().

## RegularFile() [6/6]

casacore::RegularFile::RegularFile | ( | const RegularFile & | regularFile | ) |

Copy constructor (copy semantics).

References RegularFile().

## ~RegularFile()

casacore::RegularFile::~RegularFile | ( |  | ) |

## Member Function Documentation

## checkPath()

void casacore::RegularFile::checkPath | ( |  | ) |

private

Check if the path of the file is valid.

Also resolve possible symlinks.

## copy() [1/2]

void casacore::RegularFile::copy | ( | const Path & | target,
|  | Bool | overwrite = True,
|  | Bool | setUserWritePermission = True ) const

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

If the file is a symbolic link, the regular file pointed to will be copied. 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
Caution: When a readonly file is copied, the resulting file is also readonly; Therefore chmod is used to set user write permission after the copy; The flag setUserWritePermission can be set to False when that should not be done;

References casacore::True.

Referenced by copy().

## copy() [2/2]

void casacore::RegularFile::copy | ( | const String & | target,
|  | Bool | overwrite = True,
|  | Bool | setUserWritePermission = True ) const

inline

Definition at line 189 of file RegularFile.h.

References copy().

## create()

void casacore::RegularFile::create | ( | Bool | overwrite = True | ) |

Create the regular file.

If the file exists and is not a regular file, an exception is thrown. Otherwise if overwrite is true the regular file will be overwritten. If overwrite is false then nothing will be done. If the file does not exist, it is created.

References casacore::True.

## manualCopy()

void casacore::RegularFile::manualCopy | ( | const String & | source,
|  | const String & | target )

static

Copy the file manually in case the cp command cannot be used.

(like on the Cray XT3).

## move() [1/2]

void casacore::RegularFile::move | ( | const Path & | target,
|  | Bool | overwrite = True )

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

If the file is a symbolic link, the regular file pointed to will be moved. 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
Tip: The system command mv is used instead of the library function rename to be able to move across file systems;

References casacore::True.

Referenced by move().

## move() [2/2]

void casacore::RegularFile::move | ( | const String & | target,
|  | Bool | overwrite = True )

inline

Definition at line 194 of file RegularFile.h.

References move().

## operator=()

RegularFile & casacore::RegularFile::operator= | ( | const RegularFile & | regularFile | ) |

Assignment (copy semantics).

References RegularFile().

## remove()

void casacore::RegularFile::remove | ( |  | ) |

Remove the file.

If it does not exist, an exception will be thrown. If a symbolic link is given, the link chain pointing to the file will also be removed.

## size()

virtual Int64 casacore::RegularFile::size | ( |  | ) | const

virtual

Return the size of the file.

If the file does not exist, an exception will be thrown.

Reimplemented from casacore::File.

## Member Data Documentation

## itsFile

File casacore::RegularFile::itsFile

private

This variable is used when a symbolic link points to the file.

Definition at line 185 of file RegularFile.h.

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

- casa/OS/RegularFile.h