crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
crawlservpp::Helper::FileSystem Namespace Reference

Namespace for global file system helper functions. More...

Classes

class  Exception
 Class for file system exceptions. More...
 

Existence and Validity

bool exists (std::string_view path)
 Checks whether the specified path exists. More...
 
bool isValidDirectory (std::string_view path)
 Checks whether the given path points to a valid directory. More...
 
bool isValidFile (std::string_view path)
 Checks whether the given path points to a valid file. More...
 

Paths and Directories

char getPathSeparator ()
 Gets the preferred separator for file paths in the current operating system. More...
 
std::vector< std::string > listFilesInPath (std::string_view pathToDir, std::string_view fileExtension)
 Lists all files with the given extension in the given directory and its subdirectories. More...
 
bool contains (std::string_view pathToDir, std::string_view pathToCheck)
 Checks whether the given path is located inside the given directory. More...
 
void createDirectory (std::string_view pathToDir)
 Creates a directory at the given path. More...
 
void createDirectoryIfNotExists (std::string_view pathToDir)
 Creates a directory at the given path, if it does not exist already. More...
 
void clearDirectory (std::string_view pathToDir)
 Deletes all files and folders in the given directory. More...
 

Disk Space

std::uintmax_t getFreeSpace (std::string_view path)
 Gets the available disk space at the given location in bytes. More...
 

Detailed Description

Namespace for global file system helper functions.

Function Documentation

◆ clearDirectory()

void crawlservpp::Helper::FileSystem::clearDirectory ( std::string_view  pathToDir)
inline

Deletes all files and folders in the given directory.

Parameters
pathToDirA string view containing a path to the directory which contents should be deleted.
Exceptions
FileSystem::Exceptionif the given path does not point to a valid directory or one of its contents could not be removed.

References isValidDirectory().

Referenced by crawlservpp::Main::Server::tick().

◆ contains()

bool crawlservpp::Helper::FileSystem::contains ( std::string_view  pathToDir,
std::string_view  pathToCheck 
)
inline

Checks whether the given path is located inside the given directory.

Parameters
pathToDirA string view containing the directory in which the given path should be located.
pathToCheckA string view containing the path which should be located inside the directory.
Returns
True, if the given path is or would be located inside the given directory, including its subdirectories. False otherwise.
Exceptions
FileSystem::Exceptionif the given directory does not exist, or the path to check contains an unsupported symlink.

References isValidDirectory().

Referenced by crawlservpp::Main::WebServer::sendFile(), crawlservpp::Network::Curl::setConfigGlobal(), and crawlservpp::Main::Server::tick().

◆ createDirectory()

void crawlservpp::Helper::FileSystem::createDirectory ( std::string_view  pathToDir)
inline

Creates a directory at the given path.

Parameters
pathToDirA string view containing the path to the directory to be created.
Exceptions
FileSystem::Exceptionif the directory could not be created.
See also
createDirectoryIfNotExists

Referenced by createDirectoryIfNotExists(), and crawlservpp::Main::Server::tick().

◆ createDirectoryIfNotExists()

void crawlservpp::Helper::FileSystem::createDirectoryIfNotExists ( std::string_view  pathToDir)
inline

Creates a directory at the given path, if it does not exist already.

Parameters
pathToDirA string view containing the path to the directory to be created, if it does not exist already
Exceptions
FileSystem::Exceptionif the directory does not exist, but could not be created.
See also
createDirectory

References createDirectory(), and isValidDirectory().

Referenced by crawlservpp::Main::Server::tick().

◆ exists()

bool crawlservpp::Helper::FileSystem::exists ( std::string_view  path)
inline

Checks whether the specified path exists.

Parameters
pathA string view containing the path to be checked for existence.
Returns
True if the path exists. False otherwise.
Exceptions
FileSystem::Exceptionif the existence of the path could not be checked.

Referenced by crawlservpp::Main::WebServer::getIP(), isValidDirectory(), isValidFile(), and listFilesInPath().

◆ getFreeSpace()

std::uintmax_t crawlservpp::Helper::FileSystem::getFreeSpace ( std::string_view  path)
inline

Gets the available disk space at the given location in bytes.

Parameters
pathA string view containing a path to the directory for which the available disk space should be determined.
Returns
The available disk space at the given location in bytes.
Exceptions
FileSystem::Exceptionif the available disk space could not be dettermined at the given location.

◆ getPathSeparator()

◆ isValidDirectory()

bool crawlservpp::Helper::FileSystem::isValidDirectory ( std::string_view  path)
inline

Checks whether the given path points to a valid directory.

Parameters
pathA string view containing the path to check.
Returns
True if the path points to a valid directory. False otherwise.
Exceptions
FileSystem::Exceptionif the validity of the directory could not be checked.

References exists().

Referenced by crawlservpp::Main::Database::addWebsite(), clearDirectory(), contains(), createDirectoryIfNotExists(), and crawlservpp::Main::Server::tick().

◆ isValidFile()

bool crawlservpp::Helper::FileSystem::isValidFile ( std::string_view  path)
inline

Checks whether the given path points to a valid file.

Parameters
pathA string view containing the path to check.
Returns
True if the path points to a valid file. False otherwise.
Exceptions
FileSystem::Exceptionif the validity of the file could not be checked.

References exists().

Referenced by crawlservpp::Main::Server::tick().

◆ listFilesInPath()

std::vector< std::string > crawlservpp::Helper::FileSystem::listFilesInPath ( std::string_view  pathToDir,
std::string_view  fileExtension 
)
inline

Lists all files with the given extension in the given directory and its subdirectories.

Note
While the given directory (pathToDir) needs to exist, the given path to check (pathToCheck) does not.
Parameters
pathToDirA string view containing the directory to search for files.
fileExtensionA string view containing the extension of the files to search for. If empty, all files will be returned.
Returns
A vector of strings containing the paths of the files with the given extension in the given directory and its subdirectories.
Exceptions
FileSystem::Exceptionif the given path is invalid or does not exist, or when the iteration over all the contents of the directory has failed.

References exists().

Referenced by crawlservpp::Main::Database::initializeSql(), and crawlservpp::Main::Server::tick().