Webserv
Loading...
Searching...
No Matches
utils::TempFile Class Reference

#include <filesystem.hpp>

Public Types

enum  MoveStatus { MOVE_SUCCESS , MOVE_IO_ERR , MOVE_SYS_ERR , MOVE_INVALID_STATE }

Public Member Functions

 TempFile ()
 ~TempFile ()
bool open ()
void close ()
 operator int () const
int fd () const
std::string const & path () const
bool isOpen () const
MoveStatus moveTo (const std::string &destPath)
 Moves the temporary file to a new permanent location.

Private Member Functions

 TempFile (TempFile const &TempFile)
TempFileoperator= (TempFile const &rhs)

Private Attributes

int fd_
std::string filePath_

Member Enumeration Documentation

◆ MoveStatus

Enumerator
MOVE_SUCCESS 

File moved successfully (atomic or copy)

MOVE_IO_ERR 

Disk Full, Permission on dest, or other IO error.

MOVE_SYS_ERR 

Permission on src, rename() failed for system reasons.

MOVE_INVALID_STATE 

File is not open or already moved.

Constructor & Destructor Documentation

◆ TempFile() [1/2]

utils::TempFile::TempFile ( )

◆ ~TempFile()

utils::TempFile::~TempFile ( )

◆ TempFile() [2/2]

utils::TempFile::TempFile ( TempFile const & TempFile)
private

Member Function Documentation

◆ close()

void utils::TempFile::close ( )

◆ fd()

int utils::TempFile::fd ( ) const

◆ isOpen()

bool utils::TempFile::isOpen ( ) const

◆ moveTo()

TempFile::MoveStatus utils::TempFile::moveTo ( const std::string & destPath)

Moves the temporary file to a new permanent location.

Attempts an atomic rename(). If that fails (e.g. cross-device move), it falls back to a manual copy followed by unlinking the source.

Note
IMPORTANT: On success, this TempFile object is invalidated (FD closed, path cleared). Ownership of the physical file is transferred to destPath. The file will NOT be deleted when this object is destroyed.
Parameters
destPathAbsolute path to the destination file.
Returns
MoveStatus indicating success or the specific type of failure.

◆ open()

bool utils::TempFile::open ( )

◆ operator int()

utils::TempFile::operator int ( ) const

◆ operator=()

TempFile & utils::TempFile::operator= ( TempFile const & rhs)
private

◆ path()

std::string const & utils::TempFile::path ( ) const

Member Data Documentation

◆ fd_

int utils::TempFile::fd_
private

◆ filePath_

std::string utils::TempFile::filePath_
private

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