xapian-core  2.0.0
Typedefs | Functions
filetests.h File Reference

Utility functions for testing files. More...

#include "safesysstat.h"
#include <cerrno>
#include <string>
#include <type_traits>
+ 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.

Typedefs

typedef std::make_unsigned_t< off_t > file_size_type
 Unsigned return type of file_size() function. More...
 

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...
 
file_size_type file_size (const char *path)
 Returns the size of a file. More...
 
file_size_type file_size (const std::string &path)
 Returns the size of a file. More...
 
file_size_type 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.

Typedef Documentation

◆ file_size_type

typedef std::make_unsigned_t<off_t> file_size_type

Unsigned return type of file_size() function.

Definition at line 57 of 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 145 of file filetests.h.

References S_ISDIR.

Referenced by Xapian::Database::compact_(), BackendManager::create_dir_if_needed(), DEFINE_TESTCASE(), dir_exists(), BackendManagerGlass::do_get_database_path(), BackendManagerHoney::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 157 of file filetests.h.

References dir_exists().

◆ file_exists() [1/2]

bool file_exists ( const char *  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 40 of file filetests.h.

References S_ISREG.

Referenced by check_db_dir(), check_glass_table(), Xapian::Database::compact_(), BackendManagerMulti::createdb_multi(), Xapian::Database::Database(), DEFINE_TESTCASE(), BackendManagerSingleFile::do_get_database_path(), GlassTable::exists(), file_exists(), test_driver::get_srcdir(), Xapian::DatabaseReplicator::open(), and Xapian::WritableDatabase::WritableDatabase().

◆ 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 52 of file filetests.h.

References file_exists().

◆ file_size() [1/3]

file_size_type 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. The return type is file_size_type.

Definition at line 76 of file filetests.h.

References S_ISREG.

Referenced by GlassDatabase::compact(), HoneyDatabase::compact(), file_size(), replicate_with_brokenness(), and RemoteConnection::send_file().

◆ file_size() [2/3]

file_size_type file_size ( const std::string &  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. The return type is file_size_type.

Definition at line 105 of file filetests.h.

References file_size().

◆ file_size() [3/3]

file_size_type file_size ( int  fd)
inline

Returns the size of a file.

Parameters
fdThe file descriptor for the file.

errno is set to 0 (upon success), or the error returned by fstat(), or EINVAL (if the fd 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. The return type is file_size_type.

Definition at line 126 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 167 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 178 of file filetests.h.

References path_exists().