zipios_FilePath - Man Page

Handle a file path and name and its statistics.

Synopsis

#include <filepath.hpp>

Public Member Functions

FilePath (std::string const &path='')
Initialize a FilePath object.
bool exists () const
Check whether the file exists.
std::string filename () const
Retrieve the basename.
size_t fileSize () const
Get the size of the file.
bool isBlockSpecial () const
Check whether the file is a block special file.
bool isCharSpecial () const
Check whether the file is a character special file.
bool isDirectory () const
Check whether the file is a directory.
bool isFifo () const
Check whether the file is a pipe.
bool isRegular () const
Check whether the file is a regular file.
bool isSocket () const
Check whether the file is a socket.
std::time_t lastModificationTime () const
Get the last modification time of the file.
size_t length () const
Get the length of the string.
operator std::string () const
Retrieve the path.
FilePath operator+ (FilePath const &name) const
Append the a child name to this path.
FilePath & operator= (std::string const &path)
Replace the path with a new path.
bool operator== (char const *rhs) const
Check whether two FilePath represent the same file.
bool operator== (FilePath const &rhs) const
Check whether two FilePath represent the same file.
bool operator== (std::string const &rhs) const
Check whether two FilePath represent the same file.
size_t size () const
Get the length of the string.

Private Member Functions

void check () const
Read the file mode.

Private Attributes

bool m_checked = false
bool m_exists = false
std::string m_path
os_stat_t m_stat

Friends

bool operator== (char const *lhs, FilePath const &rhs)
Check whether two FilePath represent the same file.
bool operator== (std::string const &lhs, FilePath const &rhs)
Check whether two FilePath represent the same file.

Detailed Description

The FilePath class represents a path to a file or directory name. FilePath has member functions to check if the file path is a valid file system entity, and to check what kind of file system entity it is, e.g. is it a file, a directory, a pipe, etc.

It also knows of the last modification time and size of the file.

Warning

The information about a file is cached so at the time it gets used the file on disk may have changed, it may even have been deleted.

Definition at line 46 of file filepath.hpp.

Constructor & Destructor Documentation

zipios::FilePath::FilePath (std::string const & path = '')

The constructor saves the path and if check_exists is true, read the file statistics, especially the st_mode.

Parameters

path A string representation of the path.

See also

exists()

pruneTrailingSeparator()

Definition at line 103 of file filepath.cpp.

References m_stat.

Member Function Documentation

void zipios::FilePath::check () const [private]

This function sets m_checked to true, stat()'s the path, to see if it exists and to determine what type of file it is. All the query functions call check() before they test a flag to make sure it is set appropriately.

This means stat()'ing is deferred until it becomes necessary. But also it is cached meaning that if the file changes in between we get the old flags.

Todo

Under MS-Windows, we need to use _wstat() to make it work in Unicode (i.e. UTF-8 to wchar_t then call _wstat()...) Also we want to use the 64 bit variant to make sure that we get a valid size. Any other reference to the stat() command should be replace by using a FilePath().

See zipios/zipios-config.hpp.in

Definition at line 124 of file filepath.cpp.

References m_checked, m_exists, m_path, and m_stat.

Referenced by exists(), fileSize(), isBlockSpecial(), isCharSpecial(), isDirectory(), isFifo(), isRegular(), isSocket(), and lastModificationTime().

bool zipios::FilePath::exists () const

This function calls check() and then returns true if the file exists on disk.

Returns

true If the path is a valid file system entity.

Definition at line 360 of file filepath.cpp.

References check(), and m_exists.

std::string zipios::FilePath::filename () const

This function returns the filename part of the FilePath object by pruning the path off.

Returns

Return the basename of this FilePath filename.

Definition at line 306 of file filepath.cpp.

References zipios::g_separator, and m_path.

Referenced by zipios::FileEntry::getFileName().

size_t zipios::FilePath::fileSize () const

This function returns the size of the file. The size may be a 64 bit size on 64 bit systems.

Note

If the file represents a directory, the size will be zero.

If the file is not considered valid, the size returned is zero.

Warning

There is also a function called size() which actually checks the length of the path and not the size of the file.

Returns

The last modification as a Unix time.

See also

size()

Definition at line 470 of file filepath.cpp.

References check(), and m_stat.

Referenced by zipios::DirectoryEntry::DirectoryEntry().

bool zipios::FilePath::isBlockSpecial () const

This function returns true if the file exists and is a block special file.

Returns

true if the path is block special (a block device file).

Definition at line 416 of file filepath.cpp.

References check(), m_exists, and m_stat.

bool zipios::FilePath::isCharSpecial () const

This function returns true if the file exists and is a character special file.

Returns

true if the path is character special (a character device file).

Definition at line 402 of file filepath.cpp.

References check(), m_exists, and m_stat.

bool zipios::FilePath::isDirectory () const

This function returns true if the file exists and is a directory.

Returns

true if the path is a directory.

Definition at line 388 of file filepath.cpp.

References check(), m_exists, and m_stat.

Referenced by zipios::DirectoryCollection::DirectoryCollection(), zipios::DirectoryEntry::DirectoryEntry(), zipios::FileEntry::isDirectory(), and zipios::DirectoryCollection::loadEntries().

bool zipios::FilePath::isFifo () const

This function returns true if the file exists and is a pipe file.

Returns

true if the path is a FIFO.

Definition at line 444 of file filepath.cpp.

References check(), m_exists, and m_stat.

bool zipios::FilePath::isRegular () const

This function returns true if the file exists and is a regular file.

Returns

true if the path is a regular file.

Definition at line 374 of file filepath.cpp.

References check(), m_exists, and m_stat.

Referenced by zipios::DirectoryCollection::DirectoryCollection(), and zipios::DirectoryEntry::DirectoryEntry().

bool zipios::FilePath::isSocket () const

This function returns true if the file exists and is a socket file.

Returns

true if the path is a socket.

Definition at line 430 of file filepath.cpp.

References check(), m_exists, and m_stat.

std::time_t zipios::FilePath::lastModificationTime () const

This function returns the last modification time of the specified file.

Note

If the file is not considered valid, the time returned is zero.

Returns

The last modification as a Unix time.

Definition at line 487 of file filepath.cpp.

References check(), and m_stat.

Referenced by zipios::DirectoryEntry::DirectoryEntry().

size_t zipios::FilePath::length () const

This function returns the length of the string used to represent this FilePath path and filename.

Returns

The length of the string representing this file path.

See also

size()

Definition at line 327 of file filepath.cpp.

References m_path.

Referenced by zipios::ZipCentralDirectoryEntry::getHeaderSize(), zipios::ZipLocalEntry::getHeaderSize(), size(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().

zipios::FilePath::operator std::string () const

This operator can be used to retrieve a copy of the path.

Returns

The m_path string returned as is (i.e. the whole path).

Definition at line 167 of file filepath.cpp.

FilePath zipios::FilePath::operator+ (FilePath const & rhs) const

This function concatenates two FilePath objects and returns another FilePath.

A file separator is inserted between both names if appropriate.

Warning

Note that the function allows you to append two full paths, or even a relative path (left) to a full path (right), which may result in a new path that is not quite sensible.

Parameters

rhs The right hand side.

Definition at line 187 of file filepath.cpp.

References zipios::g_separator, and m_path.

FilePath & zipios::FilePath::operator= (std::string const & path)

This function replaces the internal path of this FilePath with the new specified path.

Parameters

path The new path to save in this object.

Returns

A reference to this object.

Definition at line 154 of file filepath.cpp.

References m_path.

bool zipios::FilePath::operator== (char const * rhs) const

This function compares a FilePath object (this) and a C-string to know whether the two are the same.

A null pointer as the C-string is viewed as an empty string.

Parameters

rhs The right hand side to compare with.

See also

operator == (FilePath const& rhs);

Definition at line 219 of file filepath.cpp.

References m_path.

bool zipios::FilePath::operator== (FilePath const & rhs) const

This function compares two FilePath objects (this and rhs) to know whether the two are the same.

Note

It is important to know that the compare is rather primitive. The two paths must be equal character by character instead of actually representing exactly the same file. Also relative paths will likely be equal and these may not represent the same file at all.

Parameters

rhs The right hand side to compare with.

See also

operator == (char const *rhs);

operator == (std::string const& rhs);

Definition at line 293 of file filepath.cpp.

References m_path.

bool zipios::FilePath::operator== (std::string const & rhs) const

This function compares a FilePath object (this) against a string representing a path to know whether the two are the equal.

Parameters

rhs The right hand side to compare with.

See also

operator == (FilePath const& rhs);

Definition at line 253 of file filepath.cpp.

References m_path.

size_t zipios::FilePath::size () const

This function returns the length of the string used to represent this FilePath path and filename.

Note

This is an overloaded function that calls the length() function. It is defined because the string represents an array of bytes and as such the size() function may be used.

Returns

The length of the string representing this file path.

See also

length()

Definition at line 347 of file filepath.cpp.

References length().

Member Data Documentation

bool zipios::FilePath::m_checked = false [mutable], [private]

Definition at line 78 of file filepath.hpp.

Referenced by check().

bool zipios::FilePath::m_exists = false [mutable], [private]

Definition at line 79 of file filepath.hpp.

Referenced by check(), exists(), isBlockSpecial(), isCharSpecial(), isDirectory(), isFifo(), isRegular(), and isSocket().

std::string zipios::FilePath::m_path [private]

Definition at line 76 of file filepath.hpp.

Referenced by check(), filename(), length(), operator+(), operator=(), operator==(), operator==(), and operator==().

os_stat_t zipios::FilePath::m_stat [mutable], [private]

Definition at line 77 of file filepath.hpp.

Referenced by FilePath(), check(), fileSize(), isBlockSpecial(), isCharSpecial(), isDirectory(), isFifo(), isRegular(), isSocket(), and lastModificationTime().

Author

Generated automatically by Doxygen for zipios from the source code.

Info

Sat Jan 27 2024 00:00:00 Version 2.2.0 zipios