Scroll to navigation

zipios::FilePath(3) zipios zipios::FilePath(3)

NAME

zipios::FilePath - Handle a file path and name and its statistics.

SYNOPSIS

#include <filepath.hpp>

Public Member Functions


FilePath (std::string const &path=std::string())
Initialize a FilePath object. void clear ()
Clear the filename. bool empty () const
Check whether the filename is empty. 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 = std::string()
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 = std::string())

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 102 of file filepath.cpp.

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 119 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().

void zipios::FilePath::clear ()

This function clears the path to an empty string.

Definition at line 301 of file filepath.cpp.

References m_checked, and m_path.

Referenced by zipios::DirectoryCollection::close().

bool zipios::FilePath::empty () const

This function returns true if the filename is empty. In other words, this function returns true if the filename is not currently defined.

Note

This function returns true after a call to the clear() function.

Warning

If you are trying to know whether the file itself is empty, please use the fileSize() instead and check whether it is zero or not:

if(file_path.fileSize() == 0) ...empty file...

Returns

true when the file path is empty.

See also

clear()

fileSize()

Definition at line 381 of file filepath.cpp.

References m_path.

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 394 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 315 of file filepath.cpp.

References zipios::g_separator, and m_path.

Referenced by zipios::DirectoryEntry::computeCRC32(), and 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 504 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 450 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 436 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 422 of file filepath.cpp.

References check(), m_exists, and m_stat.

Referenced by zipios::DirectoryCollection::DirectoryCollection(), zipios::DirectoryEntry::DirectoryEntry(), zipios::DirectoryEntry::computeCRC32(), 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 478 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 408 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 464 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 521 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 336 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 163 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.

Returns

The lhs and rhs concatenated.

Definition at line 185 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 149 of file filepath.cpp.

References m_checked, and 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 217 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 291 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 251 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 356 of file filepath.cpp.

References length().

Friends And Related Symbol Documentation

bool operator== (char const * lhs, FilePath const & rhs) [friend]

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

lhs The left hand side to compare with.
rhs The right hand side to compare with.

See also

operator == (FilePath const & rhs);

Definition at line 235 of file filepath.cpp.

bool operator== (std::string const & lhs, FilePath const & rhs) [friend]

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

Parameters

lhs The left hand side to compare with.
rhs The right hand side to compare with.

See also

operator == (FilePath const & rhs);

Definition at line 268 of file filepath.cpp.

Member Data Documentation

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

Definition at line 80 of file filepath.hpp.

Referenced by check(), clear(), and operator=().

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

Definition at line 81 of file filepath.hpp.

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

std::string zipios::FilePath::m_path = std::string() [private]

Definition at line 78 of file filepath.hpp.

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

os_stat_t zipios::FilePath::m_stat = {} [mutable], [private]

Definition at line 79 of file filepath.hpp.

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

Author

Generated automatically by Doxygen for zipios from the source code.

Sat Dec 30 2023 01:18:29 Version 2.3.2