core/types: make results explicit for cleanup()

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I5795e5c6eb10d9a869d3cc88f2fdbb926a6a6964
This commit is contained in:
raf 2026-03-17 21:25:22 +03:00
commit c71c576c29
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -4,9 +4,11 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[must_use]
pub struct ContentHash(pub String); pub struct ContentHash(pub String);
impl ContentHash { impl ContentHash {
/// Creates a new content hash.
pub fn new(hash: impl Into<String>) -> Self { pub fn new(hash: impl Into<String>) -> Self {
Self(hash.into()) Self(hash.into())
} }
@ -19,6 +21,7 @@ impl AsRef<str> for ContentHash {
} }
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[must_use]
pub struct JobId(pub uuid::Uuid); pub struct JobId(pub uuid::Uuid);
impl JobId { impl JobId {
@ -34,6 +37,7 @@ impl Default for JobId {
} }
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[must_use]
pub struct RunId(pub uuid::Uuid); pub struct RunId(pub uuid::Uuid);
impl RunId { impl RunId {
@ -50,6 +54,7 @@ impl Default for RunId {
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
#[must_use]
pub enum JobStatus { pub enum JobStatus {
Discovered, Discovered,
Fetching, Fetching,
@ -60,6 +65,7 @@ pub enum JobStatus {
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[must_use]
pub struct SourceProvenance { pub struct SourceProvenance {
pub source_id: String, pub source_id: String,
pub entity_type: EntityType, pub entity_type: EntityType,
@ -69,6 +75,7 @@ pub struct SourceProvenance {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
#[must_use]
pub enum EntityType { pub enum EntityType {
Repository, Repository,
Wiki, Wiki,
@ -89,6 +96,7 @@ pub struct Artifact {
} }
impl Artifact { impl Artifact {
#[must_use]
pub const fn new( pub const fn new(
content_hash: ContentHash, content_hash: ContentHash,
size_bytes: u64, size_bytes: u64,
@ -103,18 +111,27 @@ impl Artifact {
} }
} }
/// Returns the path to the temporary file.
#[must_use]
pub fn temp_path(&self) -> &std::path::Path { pub fn temp_path(&self) -> &std::path::Path {
&self.temp_path &self.temp_path
} }
/// Explicitly clean up the temporary file. /// Explicitly clean up the temporary file. This should be called after all
/// This should be called after all sinks have processed the artifact. /// sinks have processed the artifact.
pub async fn cleanup(&self) { ///
let _ = tokio::fs::remove_file(&self.temp_path).await; /// # Errors
///
/// Returns an error if the file cannot be removed (e.g., permissions,
/// file not found, or IO errors).
pub async fn cleanup(&self) -> anyhow::Result<()> {
tokio::fs::remove_file(&self.temp_path).await?;
Ok(())
} }
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[must_use]
pub struct SinkJobState { pub struct SinkJobState {
pub status: JobStatus, pub status: JobStatus,
pub receipt: Option<StorageReceipt>, pub receipt: Option<StorageReceipt>,
@ -122,6 +139,7 @@ pub struct SinkJobState {
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[must_use]
pub struct StorageReceipt { pub struct StorageReceipt {
pub sink_id: String, pub sink_id: String,
pub uri: String, pub uri: String,
@ -129,6 +147,7 @@ pub struct StorageReceipt {
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[must_use]
pub struct ManifestEntry { pub struct ManifestEntry {
pub hash: ContentHash, pub hash: ContentHash,
pub size: u64, pub size: u64,
@ -149,6 +168,7 @@ pub struct Job {
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[must_use]
pub struct Manifest { pub struct Manifest {
pub run_id: RunId, pub run_id: RunId,
pub created_at: DateTime<Utc>, pub created_at: DateTime<Utc>,