E-MailRelay
Public Member Functions | Static Public Member Functions | List of all members
G::Directory Class Reference

An encapsulation of a file system directory that works with G::DirectoryIterator. More...

#include <gdirectory.h>

Public Member Functions

 Directory ()
 Default constructor for the current directory. More...
 
 Directory (const char *path)
 Constructor. More...
 
 Directory (const Path &path)
 Constructor. More...
 
 Directory (const std::string &path)
 Constructor. More...
 
int usable (bool for_creating_files=false) const
 Returns zero if the object represents a valid directory with permissions that dont disallow reading of any contained files. More...
 
bool valid (bool for_creating_files=false) const
 Returns true iff usable() is zero. More...
 
bool writeable (const std::string &probe_filename=tmp()) const
 Tries to create and then delete an empty test file in the directory. More...
 
Path path () const
 Returns the directory's path, as passed in to the ctor. More...
 

Static Public Member Functions

static std::string tmp ()
 A convenience function for constructing a filename for writeable(). More...
 

Detailed Description

An encapsulation of a file system directory that works with G::DirectoryIterator.

See also
G::Path, G::FileSystem, G::File

Definition at line 45 of file gdirectory.h.

Constructor & Destructor Documentation

◆ Directory() [1/4]

G::Directory::Directory ( )

Default constructor for the current directory.

Definition at line 32 of file gdirectory.cpp.

◆ Directory() [2/4]

G::Directory::Directory ( const char *  path)
explicit

Constructor.

Definition at line 37 of file gdirectory.cpp.

◆ Directory() [3/4]

G::Directory::Directory ( const Path path)
explicit

Constructor.

Definition at line 47 of file gdirectory.cpp.

◆ Directory() [4/4]

G::Directory::Directory ( const std::string &  path)
explicit

Constructor.

Definition at line 42 of file gdirectory.cpp.

Member Function Documentation

◆ path()

G::Path G::Directory::path ( ) const

Returns the directory's path, as passed in to the ctor.

Definition at line 52 of file gdirectory.cpp.

◆ tmp()

std::string G::Directory::tmp ( )
static

A convenience function for constructing a filename for writeable().

This is factored-out from writeable() into this public interface so that client code can minimise the time spent with a privileged effective userid.

Definition at line 57 of file gdirectory.cpp.

◆ usable()

int G::Directory::usable ( bool  for_creating_files = false) const

Returns zero if the object represents a valid directory with permissions that dont disallow reading of any contained files.

Returns a non-zero errno otherwise.

Does additional checks if the 'for-creating-files' parameter is true. But note that the answer is not definitive – file creation may fail, even if usable() returns zero. For a more accurate test use writeable().

Definition at line 71 of file gdirectory_unix.cpp.

◆ valid()

bool G::Directory::valid ( bool  for_creating_files = false) const

Returns true iff usable() is zero.

Definition at line 65 of file gdirectory.cpp.

◆ writeable()

bool G::Directory::writeable ( const std::string &  probe_filename = tmp()) const

Tries to create and then delete an empty test file in the directory.

Returns true on success. Precondition: valid()

Definition at line 95 of file gdirectory_unix.cpp.


The documentation for this class was generated from the following files: