IBR-DTNSuite  0.12
ibrcommon::File Class Reference

#include <File.h>

Inheritance diagram for ibrcommon::File:
Inheritance graph
Collaboration diagram for ibrcommon::File:
Collaboration graph

Public Member Functions

 File ()
 
 File (const std::string &path)
 
virtual ~File ()
 
unsigned char getType () const
 
int getFiles (std::list< File > &files) const
 
bool isRoot () const
 
bool isSystem () const
 
bool isDirectory () const
 
std::string getPath () const
 
std::string getBasename () const
 
virtual int remove (bool recursive=false)
 
File get (const std::string &filename) const
 
File getParent () const
 
virtual bool exists () const
 
virtual void update ()
 
virtual size_t size () const
 
virtual time_t lastaccess () const
 
virtual time_t lastmodify () const
 
virtual time_t laststatchange () const
 
bool operator== (const ibrcommon::File &other) const
 
bool operator< (const ibrcommon::File &other) const
 

Static Public Member Functions

static void createDirectory (File &path)
 

Protected Member Functions

 File (const std::string &path, const unsigned char t)
 

Protected Attributes

unsigned char _type
 

Detailed Description

A File object can hold a reference to any existing or non-existing files/directories. It provides a common set of file operations.

Definition at line 45 of file File.h.

Constructor & Destructor Documentation

ibrcommon::File::File ( )

Instantiate a File object without a reference to a file.

Definition at line 53 of file File.cpp.

Referenced by getParent().

ibrcommon::File::File ( const std::string &  path)

Instantiate a File object with a reference to a existing and non-existing file.

Parameters
pathFilename or path to reference to.

Definition at line 65 of file File.cpp.

References update().

Here is the call graph for this function:

ibrcommon::File::~File ( )
virtual

Destructor of the file.

Definition at line 156 of file File.cpp.

ibrcommon::File::File ( const std::string &  path,
const unsigned char  t 
)
protected

Definition at line 58 of file File.cpp.

Member Function Documentation

void ibrcommon::File::createDirectory ( File path)
static

This method creates a directory. This is done recursively.

Parameters
pathThe path to create.

Definition at line 293 of file File.cpp.

References exists(), getParent(), getPath(), and update().

Referenced by dtn::storage::SQLiteBundleStorage::clear(), dtn::storage::DataStorage::DataStorage(), dtn::daemon::Configuration::Security::load(), main(), io::TarUtils::read(), dtn::data::MemoryBundleSet::setPath(), and dtn::storage::SQLiteBundleStorage::SQLiteBundleStorage().

Here is the call graph for this function:

File ibrcommon::File::get ( const std::string &  filename) const

Get a specific file in this directory.

Parameters
filenameThe name of the file (not the full path).
Returns
A file object of the contained file.

Definition at line 233 of file File.cpp.

References FILE_DELIMITER_CHAR, getPath(), and isRoot().

Referenced by io::FATFile::get(), dtn::security::SecurityKeyManager::get(), dtn::security::SecurityKeyManager::hasKey(), io::TarUtils::read(), dtn::storage::DataStorage::retrieve(), dtn::storage::DataStorage::run(), dtn::storage::SQLiteBundleStorage::SQLiteBundleStorage(), and dtn::security::SecurityKeyManager::store().

Here is the call graph for this function:

std::string ibrcommon::File::getBasename ( ) const

Returns the basename of the file.

Returns
Basename of the file.

Definition at line 221 of file File.cpp.

Referenced by isSystem(), and main().

int ibrcommon::File::getFiles ( std::list< File > &  files) const

Get all files in the directory. The given path in the constructor has to be a directory in this case.

Parameters
filesA (empty) list to put the new file objects in.
Returns
Returns zero on success and an error number on failure.

Definition at line 164 of file File.cpp.

References FILE_DELIMITER_CHAR, getPath(), and isDirectory().

Referenced by dtn::storage::DataStorage::DataStorage(), io::ObservedFile::findFiles(), ibrcommon::TLSStream::init(), dtn::storage::DataStorage::iterateAll(), and remove().

Here is the call graph for this function:

File ibrcommon::File::getParent ( ) const

Get the parent of this file. This is always the containing directory.

Returns
The parent directory of this file.

Definition at line 283 of file File.cpp.

References File(), FILE_DELIMITER, FILE_DELIMITER_CHAR, and isRoot().

Referenced by createDirectory(), io::FATFile::getParent(), and io::TarUtils::read().

Here is the call graph for this function:

unsigned char ibrcommon::File::getType ( ) const

Returns the type of the file. The type is only updated when calling update().

See Also
update()
Returns
The filetype of the file (e.g. DT_REG, DT_LNK, DT_DIR, DT_UNKNOWN)

Definition at line 159 of file File.cpp.

References _type.

bool ibrcommon::File::isDirectory ( ) const
bool ibrcommon::File::isRoot ( ) const

Checks if a file is the root of the file-system

Returns
True, if the file is root.

Definition at line 200 of file File.cpp.

References FILE_DELIMITER.

Referenced by get(), getParent(), io::FatImageReader::isDirectory(), io::FatImageReader::lastaccess(), and io::FatImageReader::size().

bool ibrcommon::File::isSystem ( ) const

Checks if a file is a system file like ".." and ".".

Returns
True, if the file is a system file.

Definition at line 205 of file File.cpp.

References getBasename().

Referenced by io::ObservedFile::findFiles(), and remove().

Here is the call graph for this function:

time_t ibrcommon::File::lastaccess ( ) const
virtual

Get the timestamp of the last access

Reimplemented in io::FATFile.

Definition at line 319 of file File.cpp.

References getPath().

Referenced by dtn::storage::SimpleBundleStorage::get(), and dtn::storage::SQLiteBundleStorage::get().

Here is the call graph for this function:

time_t ibrcommon::File::lastmodify ( ) const
virtual

Get the timestamp of the last modification

Reimplemented in io::FATFile.

Definition at line 326 of file File.cpp.

References getPath().

Referenced by dtn::security::SecurityKeyManager::get(), dtn::storage::SimpleBundleStorage::get(), and dtn::storage::SQLiteBundleStorage::get().

Here is the call graph for this function:

time_t ibrcommon::File::laststatchange ( ) const
virtual

Get the timestamp of the last status change

Reimplemented in io::FATFile.

Definition at line 333 of file File.cpp.

References getPath().

Here is the call graph for this function:

bool ibrcommon::File::operator< ( const ibrcommon::File other) const

Definition at line 345 of file File.cpp.

bool ibrcommon::File::operator== ( const ibrcommon::File other) const

Definition at line 340 of file File.cpp.

int ibrcommon::File::remove ( bool  recursive = false)
virtual

Remove a file.

Parameters
recursiveIf set to true, the deletion works recursive and deletes directories with files too.
Returns
Returns zero on success and an error number on failure.

Reimplemented in io::FATFile.

Definition at line 244 of file File.cpp.

References _type, getFiles(), getPath(), isDirectory(), isSystem(), and remove().

Referenced by dtn::storage::SQLiteBundleStorage::clear(), dtn::net::FileConvergenceLayer::componentRun(), dtn::storage::SQLiteDatabase::expire(), main(), remove(), dtn::storage::SQLiteDatabase::remove(), dtn::storage::DataStorage::run(), dtn::storage::SQLiteBundleStorage::SQLiteBundleStorage(), dtn::security::SecurityKeyManager::store(), and dtn::storage::SQLiteBundleStorage::store().

Here is the call graph for this function:

size_t ibrcommon::File::size ( ) const
virtual

Get the size of the file.

Returns
The size in bytes.

Reimplemented in io::FATFile.

Definition at line 312 of file File.cpp.

References getPath().

Referenced by ibrcommon::FileBLOB::__get_size(), dtn::storage::SQLiteBundleStorage::store(), and io::TarUtils::write().

Here is the call graph for this function:

void ibrcommon::File::update ( )
virtual

Updates file information like file type

See Also
getType()

Reimplemented in io::FATFile.

Definition at line 114 of file File.cpp.

References _type.

Referenced by createDirectory(), and File().

Member Data Documentation

unsigned char ibrcommon::File::_type
protected

Definition at line 173 of file File.h.

Referenced by getType(), isDirectory(), remove(), io::FATFile::update(), and update().


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