casa
$Rev:20696$
|
Manipulate and get information about regular files. 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 &string) | |
RegularFile (const File &file) | |
RegularFile (const RegularFile ®ularFile) | |
Copy constructor (copy semantics). | |
~RegularFile () | |
RegularFile & | operator= (const RegularFile ®ularFile) |
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. | |
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. | |
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. |
Manipulate and get information about regular files.
<h3>Intended use:</h3> Public interface
The class RegularFile provides functions for manipulating and getting information about regular files. Regular file are files which hold data.
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.
// 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
Provide functions for manipulating and getting information about regular files.
Definition at line 91 of file RegularFile.h.
Default constructor sets path to .
(working directory).
casa::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.
casa::RegularFile::RegularFile | ( | const String & | string | ) |
casa::RegularFile::RegularFile | ( | const File & | file | ) |
casa::RegularFile::RegularFile | ( | const RegularFile & | regularFile | ) |
Copy constructor (copy semantics).
void casa::RegularFile::checkPath | ( | ) | [private] |
Check if the path of the file is valid.
Also resolve possible symlinks.
void casa::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;
Referenced by copy().
void casa::RegularFile::copy | ( | const String & | target, |
Bool | overwrite = True , |
||
Bool | setUserWritePermission = True |
||
) | const [inline] |
Definition at line 190 of file RegularFile.h.
References copy().
void casa::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.
static void casa::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).
void casa::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;
Referenced by move().
void casa::RegularFile::move | ( | const String & | target, |
Bool | overwrite = True |
||
) | [inline] |
Definition at line 195 of file RegularFile.h.
References move().
RegularFile& casa::RegularFile::operator= | ( | const RegularFile & | regularFile | ) |
Assignment (copy semantics).
void casa::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.
virtual Int64 casa::RegularFile::size | ( | ) | const [virtual] |
Return the size of the file.
If the file does not exist, an exception will be thrown.
Reimplemented from casa::File.
File casa::RegularFile::itsFile [private] |
This variable is used when a symbolic link points to the file.
Definition at line 186 of file RegularFile.h.