// Copyright (c) 2026 Juhapekka Piiroinen // All Rights Reserved. // AmoosedWeb project: https://amoosed.com #pragma once #include "AmoosedWeb/Reader.hpp" #include #include #include namespace amoosed { // Writes to a new temporary sibling and publishes only after the Reader's // final digest passes. The caller chooses an absolute path inside a trusted // output directory; never derive that path directly from untrusted content. // Existing targets are never replaced. Not safe for concurrent method calls. class WindowsFileOutput final : public OutputHost { public: enum class Failure { None, InvalidPath, AlreadyExists, Io }; explicit WindowsFileOutput(std::string_view absolute_utf8_path, std::string& error); ~WindowsFileOutput() override; WindowsFileOutput(const WindowsFileOutput&) = delete; WindowsFileOutput& operator=(const WindowsFileOutput&) = delete; bool ready() const noexcept { return ready_; } Failure failure() const noexcept { return failure_; } bool write(const std::uint8_t* bytes, std::size_t length) override; bool commit() override; void abort() override; private: std::wstring target_, temporary_; void* handle_ = nullptr; std::vector directory_handles_; bool ready_ = false, committed_ = false; Failure failure_ = Failure::None; }; }