userver: fs::blocking::FileDescriptor Class Reference
Loading...
Searching...
No Matches
fs::blocking::FileDescriptor Class Referencefinal

#include <userver/fs/blocking/file_descriptor.hpp>

Detailed Description

A file descriptor wrapper.

The file is closed in the destructor

Note
The operations on the file are blocking and not thread-safe

Definition at line 22 of file file_descriptor.hpp.

Public Member Functions

 FileDescriptor (FileDescriptor &&other) noexcept
 
FileDescriptoroperator= (FileDescriptor &&other) noexcept
 
bool IsOpen () const
 Checks if the file is open.
 
void Close () &&
 Closes the file manually.
 
int GetNative () const
 Returns the native file handle.
 
int Release () &&
 Passes the ownership of the file descriptor to the caller.
 
void Write (std::string_view contents)
 Writes data to the file.
 
std::size_t Read (char *buffer, std::size_t max_size)
 Reads data from the file at current offset.
 
void Seek (std::size_t offset_in_bytes)
 Sets the file read/write offset from the beginning of the file.
 
void FSync ()
 Makes sure the written data is actually stored on disk.
 
std::size_t GetSize () const
 Fetches the file size.
 

Static Public Member Functions

static FileDescriptor Open (const std::string &path, OpenMode flags, boost::filesystem::perms perms=boost::filesystem::perms::owner_read|boost::filesystem::perms::owner_write)
 Open a file using ::open.
 
static FileDescriptor OpenDirectory (const std::string &path)
 Open a directory node.
 
static FileDescriptor AdoptFd (int fd) noexcept
 Use the file descriptor directly.
 

Member Function Documentation

◆ Close()

void fs::blocking::FileDescriptor::Close ( ) &&

Closes the file manually.

Exceptions
std::runtime_error

◆ FSync()

void fs::blocking::FileDescriptor::FSync ( )

Makes sure the written data is actually stored on disk.

Exceptions
std::runtime_error

◆ GetSize()

std::size_t fs::blocking::FileDescriptor::GetSize ( ) const

Fetches the file size.

Exceptions
std::runtime_error

◆ IsOpen()

bool fs::blocking::FileDescriptor::IsOpen ( ) const

Checks if the file is open.

Note
Operations can only be performed on an open FileDescriptor.

◆ Open()

static FileDescriptor fs::blocking::FileDescriptor::Open ( const std::string & path,
OpenMode flags,
boost::filesystem::perms perms = boost::filesystem::perms::owner_read|boost::filesystem::perms::owner_write )
static

Open a file using ::open.

Exceptions
std::runtime_error

◆ OpenDirectory()

static FileDescriptor fs::blocking::FileDescriptor::OpenDirectory ( const std::string & path)
static

Open a directory node.

Note
The only valid operation for such a FileDescriptor is FSync.
Exceptions
std::runtime_error

◆ Read()

std::size_t fs::blocking::FileDescriptor::Read ( char * buffer,
std::size_t max_size )

Reads data from the file at current offset.

Returns
The amount of bytes actually acquired, which can be equal to max_size, or less on end-of-file
Exceptions
std::runtime_error

◆ Seek()

void fs::blocking::FileDescriptor::Seek ( std::size_t offset_in_bytes)

Sets the file read/write offset from the beginning of the file.

Exceptions
std::runtime_error

◆ Write()

void fs::blocking::FileDescriptor::Write ( std::string_view contents)

Writes data to the file.

Warning
Unless FSync is called, there is no guarantee the data is stored on disk safely.
Exceptions
std::runtime_error

Friends And Related Symbol Documentation

◆ TempFile

friend class TempFile
friend

Definition at line 85 of file file_descriptor.hpp.


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