libept
Classes | Public Member Functions | List of all members
ept::sys::Path Struct Reference

Wrap a path on the file system opened with O_PATH. More...

#include <sys.h>

Inheritance diagram for ept::sys::Path:
ept::sys::NamedFileDescriptor ept::sys::FileDescriptor

Classes

struct  iterator
 Iterator for directory entries. More...
 

Public Member Functions

 Path (const char *pathname, int flags=0)
 Open the given pathname with flags | O_PATH. More...
 
 Path (const std::string &pathname, int flags=0)
 Open the given pathname with flags | O_PATH. More...
 
 Path (Path &parent, const char *pathname, int flags=0)
 Open the given pathname calling parent.openat, with flags | O_PATH. More...
 
 Path (const Path &)=delete
 
 Path (Path &&)=default
 
Pathoperator= (const Path &)=delete
 
Pathoperator= (Path &&)=default
 
 ~Path ()
 The destructor closes the file descriptor, but does not check errors on ::close(). More...
 
DIR * fdopendir ()
 
iterator begin ()
 Begin iterator on all directory entries. More...
 
iterator end ()
 End iterator on all directory entries. More...
 
int openat (const char *pathname, int flags, mode_t mode=0777)
 
void fstatat (const char *pathname, struct stat &st)
 
void lstatat (const char *pathname, struct stat &st)
 fstatat with the AT_SYMLINK_NOFOLLOW flag set More...
 
void unlinkat (const char *pathname)
 
void rmdirat (const char *pathname)
 unlinkat with the AT_REMOVEDIR flag set More...
 
void rmtree ()
 Delete the directory pointed to by this Path, with all its contents. More...
 
- Public Member Functions inherited from ept::sys::NamedFileDescriptor
 NamedFileDescriptor (int fd, const std::string &pathname)
 
 NamedFileDescriptor (NamedFileDescriptor &&)
 
NamedFileDescriptoroperator= (NamedFileDescriptor &&)
 
virtual void throw_error (const char *desc)
 Throw an exception based on errno and the given message. More...
 
const std::string & name () const
 Return the file pathname. More...
 
- Public Member Functions inherited from ept::sys::FileDescriptor
 FileDescriptor ()
 
 FileDescriptor (FileDescriptor &&o)
 
 FileDescriptor (int fd)
 
virtual ~FileDescriptor ()
 
void close ()
 
void fstat (struct stat &st)
 
void fchmod (mode_t mode)
 
size_t write (const void *buf, size_t count)
 
void write_all (const void *buf, size_t count)
 Write all the data in buf, retrying partial writes. More...
 
MMap mmap (size_t length, int prot, int flags, off_t offset=0)
 
 operator int () const
 

Additional Inherited Members

- Protected Attributes inherited from ept::sys::NamedFileDescriptor
std::string pathname
 
- Protected Attributes inherited from ept::sys::FileDescriptor
int fd = -1
 

Detailed Description

Wrap a path on the file system opened with O_PATH.

Constructor & Destructor Documentation

◆ Path() [1/5]

ept::sys::Path::Path ( const char *  pathname,
int  flags = 0 
)

Open the given pathname with flags | O_PATH.

References ept::sys::FileDescriptor::fd, O_PATH, and ept::sys::NamedFileDescriptor::throw_error().

◆ Path() [2/5]

ept::sys::Path::Path ( const std::string &  pathname,
int  flags = 0 
)

Open the given pathname with flags | O_PATH.

References ept::sys::FileDescriptor::fd, O_PATH, and ept::sys::NamedFileDescriptor::throw_error().

◆ Path() [3/5]

ept::sys::Path::Path ( Path parent,
const char *  pathname,
int  flags = 0 
)

Open the given pathname calling parent.openat, with flags | O_PATH.

◆ Path() [4/5]

ept::sys::Path::Path ( const Path )
delete

◆ Path() [5/5]

ept::sys::Path::Path ( Path &&  )
default

◆ ~Path()

ept::sys::Path::~Path ( )

The destructor closes the file descriptor, but does not check errors on ::close().

In normal program flow, it is a good idea to explicitly call Path::close() in places where it can throw safely.

References ept::sys::FileDescriptor::close(), and ept::sys::FileDescriptor::fd.

Member Function Documentation

◆ begin()

Path::iterator ept::sys::Path::begin ( )

Begin iterator on all directory entries.

References ept::sys::FileDescriptor::fd.

Referenced by rmtree().

◆ end()

Path::iterator ept::sys::Path::end ( )

End iterator on all directory entries.

Referenced by rmtree().

◆ fdopendir()

DIR * ept::sys::Path::fdopendir ( )

◆ fstatat()

void ept::sys::Path::fstatat ( const char *  pathname,
struct stat st 
)

◆ lstatat()

void ept::sys::Path::lstatat ( const char *  pathname,
struct stat st 
)

fstatat with the AT_SYMLINK_NOFOLLOW flag set

References ept::sys::FileDescriptor::fd, fstatat(), and ept::sys::NamedFileDescriptor::throw_error().

◆ openat()

int ept::sys::Path::openat ( const char *  pathname,
int  flags,
mode_t  mode = 0777 
)

◆ operator=() [1/2]

Path& ept::sys::Path::operator= ( const Path )
delete

◆ operator=() [2/2]

Path& ept::sys::Path::operator= ( Path &&  )
default

◆ rmdirat()

void ept::sys::Path::rmdirat ( const char *  pathname)

unlinkat with the AT_REMOVEDIR flag set

References ept::sys::FileDescriptor::fd, ept::sys::NamedFileDescriptor::throw_error(), and unlinkat().

◆ rmtree()

void ept::sys::Path::rmtree ( )

Delete the directory pointed to by this Path, with all its contents.

The path must point to a directory.

References begin(), end(), ept::sys::NamedFileDescriptor::name(), ept::sys::rmdir(), rmtree(), and unlinkat().

Referenced by rmtree(), and ept::sys::rmtree().

◆ unlinkat()

void ept::sys::Path::unlinkat ( const char *  pathname)

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