Loading...
Searching...
No Matches
meshkit::native_detail::Transaction Class Reference

Exclusive temporary output file that commit() publishes atomically at a target path. More...

#include </home/runner/work/Meshkit/Meshkit/src/native/file.hpp>

Collaboration diagram for meshkit::native_detail::Transaction:

Public Member Functions

 Transaction (const std::filesystem::path &target, const IOOptions &options)
 Validate the target and create its exclusive temporary.
 
 ~Transaction ()
 Close and remove the temporary unless commit() published it; errors ignored.
 
 Transaction (const Transaction &)=delete
 
std::FILE * file () const
 The open temporary, owned by this object (do not close it); null after commit().
 
void commit ()
 Flush, optionally sync, close and publish the temporary at the target; call once.
 

Detailed Description

Exclusive temporary output file that commit() publishes atomically at a target path.

Copy construction is deleted. Destroying an uncommitted transaction closes and removes the temporary (errors ignored), so the target is never partially written.

Constructor & Destructor Documentation

◆ Transaction() [1/2]

meshkit::native_detail::Transaction::Transaction ( const std::filesystem::path & target,
const IOOptions & options )
inline

Validate the target and create its exclusive temporary.

The temporary is .meshkit-<random>.tmp in the target's directory (or the current directory when the target has none), created exclusively (owner read/write only on POSIX); up to 32 random names are tried while candidates already exist.

Parameters
[in]targetDestination file path; copied.
[in]optionsSupplies overwrite and durable, copied for commit().
Exceptions
Stoppath for an empty or NUL-containing path or a file name that is empty, . or ..; open_output when no temporary can be created (both status Failed).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~Transaction()

meshkit::native_detail::Transaction::~Transaction ( )
inline

Close and remove the temporary unless commit() published it; errors ignored.

◆ Transaction() [2/2]

meshkit::native_detail::Transaction::Transaction ( const Transaction & )
delete
Here is the call graph for this function:

Member Function Documentation

◆ commit()

void meshkit::native_detail::Transaction::commit ( )
inline

Flush, optionally sync, close and publish the temporary at the target; call once.

With overwrite the temporary replaces the target (rename(); Windows MoveFileExW with MOVEFILE_REPLACE_EXISTING). Without it POSIX hard-links the temporary to the target, which fails if the target exists, then unlinks the temporary; Windows moves without replacing. With durable the contents are synced (fsync/_commit; MOVEFILE_WRITE_THROUGH) first.

Exceptions
Stopwrite, sync, close or publish (status Failed); the destructor then removes the temporary and any existing target is left as it was.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ file()

std::FILE * meshkit::native_detail::Transaction::file ( ) const
inline

The open temporary, owned by this object (do not close it); null after commit().

Here is the caller graph for this function:

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