Files
FESADev/src/fesa/io/hdf5/hdf5_atomic_file.h
T

38 lines
1.1 KiB
C++

#ifndef FESA_IO_HDF5_HDF5_ATOMIC_FILE_H_
#define FESA_IO_HDF5_HDF5_ATOMIC_FILE_H_
#include <filesystem>
#include "fesa/core/status.h"
namespace fesa::hdf5_internal {
/// @brief Removes an uncommitted same-directory candidate on failure.
class CandidateFileGuard {
public:
explicit CandidateFileGuard(std::filesystem::path path);
CandidateFileGuard(const CandidateFileGuard&) = delete;
CandidateFileGuard& operator=(const CandidateFileGuard&) = delete;
~CandidateFileGuard();
void Release() noexcept;
private:
std::filesystem::path path_;
bool active_{true};
};
/// @brief Selects a unique same-directory candidate path.
std::filesystem::path MakeCandidatePath(
const std::filesystem::path& output_path);
/// @brief Publishes only a successfully self-checked candidate.
/// @note Validation failure removes the candidate and preserves any final.
Status AtomicFinalizeValidatedCandidate(
const std::filesystem::path& candidate_path,
const std::filesystem::path& output_path, const Status& validation);
} // namespace fesa::hdf5_internal
#endif // FESA_IO_HDF5_HDF5_ATOMIC_FILE_H_