xapian-core  1.4.26
Functions
filetests.h File Reference

Utility functions for testing files. More...

#include "safesysstat.h"
#include <cerrno>
#include <string>
+ Include dependency graph for filetests.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool file_exists (const char *path)
 Test if a file exists. More...
 
bool file_exists (const std::string &path)
 Test if a file exists. More...
 
off_t file_size (const char *path)
 Returns the size of a file. More...
 
off_t file_size (const std::string &path)
 Returns the size of a file. More...
 
off_t file_size (int fd)
 Returns the size of a file. More...
 
bool dir_exists (const char *path)
 Test if a directory exists. More...
 
bool dir_exists (const std::string &path)
 Test if a directory exists. More...
 
bool path_exists (const char *path)
 Test if a path exists. More...
 
bool path_exists (const std::string &path)
 Test if a path exists. More...
 

Detailed Description

Utility functions for testing files.

Definition in file filetests.h.

Function Documentation

◆ dir_exists() [1/2]

bool dir_exists ( const char *  path)
inline

Test if a directory exists.

Parameters
pathThe path to test
Returns
true if path is a directory, or a symbolic link which resolves to a directory.

Definition at line 136 of file filetests.h.

References S_ISDIR.

Referenced by Xapian::Database::compact_(), BackendManager::create_dir_if_needed(), DEFINE_TESTCASE(), dir_exists(), BackendManagerChert::do_get_database_path(), BackendManagerGlass::do_get_database_path(), GlassDatabase::GlassDatabase(), Xapian::DatabaseReplica::Internal::Internal(), main(), and rm_rf().

◆ dir_exists() [2/2]

bool dir_exists ( const std::string &  path)
inline

Test if a directory exists.

Parameters
pathThe path to test
Returns
true if path is a directory, or a symbolic link which resolves to a directory.

Definition at line 148 of file filetests.h.

References dir_exists().

◆ file_exists() [1/2]

bool file_exists ( const char *  path)
inline

◆ file_exists() [2/2]

bool file_exists ( const std::string &  path)
inline

Test if a file exists.

Parameters
pathThe path to test
Returns
true if path is a regular file, or a symbolic link which resolves to a regular file.

Definition at line 51 of file filetests.h.

References file_exists().

◆ file_size() [1/3]

off_t file_size ( const char *  path)
inline

Returns the size of a file.

Parameters
pathThe path to test

errno is set to 0 (upon success), or the error returned by stat(), or EINVAL (if the path isn't a regular file or a symlink resolving to a regular file).

If the file's size is larger than the maximum value off_t can represent, then stat() will fail with errno=EOVERFLOW, and so will this function. There doesn't seem to be a way to determine the file size in this case, short of reading it all. This is only likely if the LFS check in configure doesn't work out how to enable largefile support.

Returns
The size of the file, or 0 if it doesn't exist or isn't a file.

Definition at line 71 of file filetests.h.

References S_ISREG.

Referenced by ChertTableCheck::check(), GlassDatabase::compact(), ChertDatabase::compact(), file_size(), get_file_size(), and RemoteConnection::send_file().

◆ file_size() [2/3]

off_t file_size ( const std::string &  path)
inline

Returns the size of a file.

Parameters
pathThe path to test

Note: If the file's size is larger than the maximum value off_t can represent, then stat() will fail with EOVERFLOW, and so will this function. There doesn't seem to be a way to determine the file size in this case, short of reading it all. This is only likely if the LFS check in configure doesn't work out how to enable largefile support.

Returns
The size of the file, or 0 if it doesn't exist or isn't a file; errno is set to 0 (upon success), or the error returned by stat(), or EINVAL (if the path isn't a regular file or a symlink resolving to a regular file).

Definition at line 98 of file filetests.h.

References file_size().

◆ file_size() [3/3]

off_t file_size ( int  fd)
inline

Returns the size of a file.

Parameters
fdThe file descriptor for the file.

Note: If the file's size is larger than the maximum value off_t can represent, then stat() will fail with EOVERFLOW, and so will this function. There doesn't seem to be a way to determine the file size in this case, short of reading it all. This is only likely if the LFS check in configure doesn't work out how to enable largefile support.

Returns
The size of the file, or 0 if it doesn't exist or isn't a file; errno is set to 0 (upon success), or the error returned by stat(), or EINVAL (if the path isn't a regular file or a symlink resolving to a regular file).

Definition at line 117 of file filetests.h.

References S_ISREG.

◆ path_exists() [1/2]

bool path_exists ( const char *  path)
inline

Test if a path exists.

Parameters
pathThe path to test
Returns
true if path exists (and is not a dangling symlink).

Definition at line 158 of file filetests.h.

Referenced by BackendManager::get_database(), BackendManager::get_database_path(), and path_exists().

◆ path_exists() [2/2]

bool path_exists ( const std::string &  path)
inline

Test if a path exists.

Parameters
pathThe path to test
Returns
true if path exists (and is not a dangling symlink).

Definition at line 169 of file filetests.h.

References path_exists().