#pragma once #include #include #include #include #include #include #include #include #include namespace Void::Update { struct PruneReport { std::vector removed{}; std::vector skipped_due_to_pins{}; bool batch_limit_reached{false}; }; struct PendingActivation { std::optional previousVersion; Semver::Version candidateVersion; /// Health-log generation observed before activation. A later /// healthy event for the candidate is the durable commit marker /// used to reconcile an activation journal left behind by a /// post-commit cleanup failure. std::uint64_t healthGeneration{}; }; /// Immutable version directory store with a relative `current` symlink and /// a durable activation journal. An uncommitted activation is rolled back /// by reconcile(), making candidate health checks an explicit commit /// boundary. /// /// The crash-durability and cross-process locking guarantees are provided /// by the POSIX implementation. The current Windows fallback is functional /// but does not yet provide equivalent crash durability or process locking. class VersionStore { public: explicit VersionStore(std::filesystem::path root); [[nodiscard]] Void::Result::Result initialize(); [[nodiscard]] Void::Result::Result prepare(const Semver::Version& version); [[nodiscard]] Void::Result::Result publish(const Semver::Version& version, const std::filesystem::path& stagingDirectory); [[nodiscard]] Void::Result::Result activate(const Semver::Version& version); /// Idempotently accept the candidate. A durable healthy-history /// event is the commit point; activation-journal cleanup after that /// point cannot be reported as a reversible failure. [[nodiscard]] Void::Result::Result commit(); /// Idempotently restore the previous version. The journal is /// retained until restoration succeeds. A candidate whose commit /// marker is newer than the journal baseline is finalized instead /// of rolled back. [[nodiscard]] Void::Result::Result rollback(); [[nodiscard]] Void::Result::Result reconcile(); /// Record a successful activation performed by an external /// lifecycle owner. The published version must be a real immediate /// directory. Every call appends a durable healthy event and /// refreshes retention order. It rejects stores with an internal /// activation journal so it cannot implicitly commit activate(). /// This method does not initialize the store or create staging. [[nodiscard]] Void::Result::Result recordHealthy(const Semver::Version& version); /// Record a failed external activation unless this version's /// current publication lifecycle is already known healthy. A /// retired and later republished SemVer starts a new lifecycle. /// This method does not initialize the store or create staging. [[nodiscard]] Void::Result::Result recordFailed(const Semver::Version& version); /// Return real, currently published versions whose current /// lifecycle is known healthy, newest durable healthy event first. /// Missing, symlinked, failed, retired, and unknown publications /// are excluded. [[nodiscard]] Void::Result::Result> healthyPublishedVersions() const; /// Remove structurally valid, published version directories except /// the active version, an in-flight activation's candidate and /// previous version, and the requested number of most recently /// committed healthy versions. Unknown publication state is /// retained conservatively. Symlinks and the staging tree are never /// traversed or removed. Returns the versions that were quarantined /// and removed. [[nodiscard]] Void::Result::Result> prune(std::size_t retainedPreviousVersions); /// Pin-aware bounded pruning pass. Never deletes the active /// version, pending activation candidate/previous, top /// `retainedPreviousVersions` healthy versions, or any version in /// `pinnedVersions`. Reports pin-blocked candidates and honors /// `batchLimit` (default 16 publications per pass). [[nodiscard]] Void::Result::Result pruneWithPins(std::size_t retainedPreviousVersions, std::span pinnedVersions, std::size_t batchLimit = 16); [[nodiscard]] Void::Result::Result> currentVersion() const; [[nodiscard]] Void::Result::Result> pendingActivation() const; [[nodiscard]] const std::filesystem::path& root() const noexcept; [[nodiscard]] std::filesystem::path versionPath(const Semver::Version& version) const; private: std::filesystem::path m_root; }; } // namespace Void::Update