Exclusive temporary output file that commit() publishes atomically at a target path.
More...
#include </home/runner/work/Meshkit/Meshkit/src/native/file.hpp>
|
| | 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.
|
| |
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.
◆ 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] | target | Destination file path; copied. |
| [in] | options | Supplies overwrite and durable, copied for commit(). |
- Exceptions
-
| Stop | path 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). |
◆ ~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 |
◆ 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
-
| Stop | write, sync, close or publish (status Failed); the destructor then removes the temporary and any existing target is left as it was. |
◆ file()
| std::FILE * meshkit::native_detail::Transaction::file |
( |
| ) |
const |
|
inline |
The open temporary, owned by this object (do not close it); null after commit().
The documentation for this class was generated from the following file: