yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
source_artifact_publisher.h
Go to the documentation of this file.
1#ifndef YAZE_CORE_SOURCE_ARTIFACT_PUBLISHER_H_
2#define YAZE_CORE_SOURCE_ARTIFACT_PUBLISHER_H_
3
4#include <filesystem>
5#include <functional>
6#include <memory>
7#include <optional>
8#include <string>
9#include <string_view>
10#include <vector>
11
12#include "absl/status/status.h"
13#include "absl/status/statusor.h"
14
15namespace yaze::core {
16
17// All source-artifact publishers share one persistent lock namespace so that
18// different source domains cannot race while publishing into the same folder.
20 ".yaze-message-source-sync.lock";
21
23 std::filesystem::path target;
24 std::optional<std::string> before;
25 std::string after;
26};
27
28// Labels only affect diagnostics. They let migrated callers retain their
29// existing user-facing errors while the publication machinery stays generic.
31 std::string subject = "source artifact";
32 std::string published_file = "published source artifact";
33};
34
35using SourceArtifactReadbackValidator = std::function<absl::Status()>;
36
37// Holds both the process-local semaphore and the durable per-directory locks
38// for a set of absolute publication targets. Target paths are canonicalized
39// and pinned while acquiring the lock. Callers should acquire this before
40// reading their preflight bytes and keep it alive through publication. Only
41// one publication may use a lock at a time; concurrent reuse fails before
42// touching any target.
44 public:
46
49 const SourceArtifactPublicationLock&) = delete;
50
51 private:
52 struct Impl;
53
54 explicit SourceArtifactPublicationLock(std::unique_ptr<Impl> impl);
55
56 std::unique_ptr<Impl> impl_;
57
58 friend absl::StatusOr<std::unique_ptr<SourceArtifactPublicationLock>>
60 const std::vector<std::filesystem::path>& targets,
61 const SourceArtifactPublisherLabels& labels);
62 friend absl::Status PublishSourceArtifacts(
64 std::vector<SourceArtifactUpdate> updates,
65 std::string_view expected_primary_sha256,
66 SourceArtifactReadbackValidator readback_validator);
67};
68
69// Validates the persistent lock paths without creating or acquiring them.
70// Dry-run workflows use this to retain the same fail-closed path checks as a
71// write without leaving lock files behind.
73 const std::vector<std::filesystem::path>& targets,
74 const SourceArtifactPublisherLabels& labels = {});
75
76absl::StatusOr<std::unique_ptr<SourceArtifactPublicationLock>>
78 const std::vector<std::filesystem::path>& targets,
79 const SourceArtifactPublisherLabels& labels = {});
80
81std::string ComputeSourceArtifactSha256(std::string_view content);
82
83// Publishes all updates as one rollback-protected transaction using atomic
84// replacement for each target. The first update is the primary CAS source and
85// must contain its exact preflight bytes. Exact byte readback is always
86// required; an optional domain validator runs before backups are removed so
87// its failure can still roll the set back. This is not crash-atomic across the
88// complete multi-file set: a process or system crash can interrupt the set
89// between target replacements.
90absl::Status PublishSourceArtifacts(
91 const SourceArtifactPublicationLock& lock,
92 std::vector<SourceArtifactUpdate> updates,
93 std::string_view expected_primary_sha256,
94 SourceArtifactReadbackValidator readback_validator = {});
95
96} // namespace yaze::core
97
98#endif // YAZE_CORE_SOURCE_ARTIFACT_PUBLISHER_H_
friend absl::Status PublishSourceArtifacts(const SourceArtifactPublicationLock &lock, std::vector< SourceArtifactUpdate > updates, std::string_view expected_primary_sha256, SourceArtifactReadbackValidator readback_validator)
SourceArtifactPublicationLock & operator=(const SourceArtifactPublicationLock &)=delete
SourceArtifactPublicationLock(const SourceArtifactPublicationLock &)=delete
friend absl::StatusOr< std::unique_ptr< SourceArtifactPublicationLock > > AcquireSourceArtifactPublicationLock(const std::vector< std::filesystem::path > &targets, const SourceArtifactPublisherLabels &labels)
absl::Status PublishSourceArtifacts(const SourceArtifactPublicationLock &lock, std::vector< SourceArtifactUpdate > updates, std::string_view expected_primary_sha256, SourceArtifactReadbackValidator readback_validator)
constexpr char kSourceArtifactPublicationLockBasename[]
std::string ComputeSourceArtifactSha256(std::string_view content)
absl::Status ValidateSourceArtifactPublicationTargets(const std::vector< fs::path > &targets, const SourceArtifactPublisherLabels &labels)
std::function< absl::Status()> SourceArtifactReadbackValidator
absl::StatusOr< std::unique_ptr< SourceArtifactPublicationLock > > AcquireSourceArtifactPublicationLock(const std::vector< fs::path > &targets, const SourceArtifactPublisherLabels &labels)