From 4ec3524379f4dc59bc2550d06cf40d8dbeec7208 Mon Sep 17 00:00:00 2001 From: Nikolay Govorov Date: Thu, 12 Mar 2026 15:47:10 +0000 Subject: Fix trash reloads minisigs --- crates/repos/src/go.rs | 2 +- crates/repos/src/lib.rs | 6 +++--- crates/repos/src/zig.rs | 4 ++-- crates/zorian/src/storage.rs | 30 +++++++++++++++++++----------- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/crates/repos/src/go.rs b/crates/repos/src/go.rs index 758a5ac..d591e7d 100644 --- a/crates/repos/src/go.rs +++ b/crates/repos/src/go.rs @@ -21,7 +21,7 @@ impl Default for GoConfig { Self { enabled: true, upstream: Url::parse("https://go.dev/dl/").unwrap(), - refresh_interval: 60 * 10, + refresh_interval: 60 * 60, } } } diff --git a/crates/repos/src/lib.rs b/crates/repos/src/lib.rs index 14fd3a9..1f70f0a 100644 --- a/crates/repos/src/lib.rs +++ b/crates/repos/src/lib.rs @@ -313,8 +313,8 @@ pub trait BackendStorage: Send + Sync { meta_null_field: Option<&str>, ) -> Result, BackendError>; - /// Update a single file. - async fn update_file(&self, file: &RawReleaseFile) -> Result; + /// Update file metadata (e.g. after fetching a signature). + async fn update_file_meta(&self, file: &RawReleaseFile) -> Result; } /// Delegate provides I/O primitives to backends. @@ -404,7 +404,7 @@ impl Backend { for file in files { match S::fetch_signature(&file, &self.config, &self.source, &*self.network).await { Ok(updated) => { - if let Err(e) = self.storage.update_file(&updated).await { + if let Err(e) = self.storage.update_file_meta(&updated).await { tracing::debug!( filename = file.filename, "failed to store signature: {e}" diff --git a/crates/repos/src/zig.rs b/crates/repos/src/zig.rs index 44b0630..c9a8b8f 100644 --- a/crates/repos/src/zig.rs +++ b/crates/repos/src/zig.rs @@ -26,7 +26,7 @@ impl Default for ZigConfig { Self { enabled: true, upstream: Url::parse("https://ziglang.org").unwrap(), - refresh_interval: 60 * 10, + refresh_interval: 60 * 60, } } } @@ -70,7 +70,7 @@ where pub struct ZigFileMeta { pub target: String, - #[serde(default)] + #[serde(default, skip_serializing_if = "Option::is_none")] pub minisig: Option, } diff --git a/crates/zorian/src/storage.rs b/crates/zorian/src/storage.rs index fe5b734..0e7f3ac 100644 --- a/crates/zorian/src/storage.rs +++ b/crates/zorian/src/storage.rs @@ -721,13 +721,11 @@ impl StorageService { checksum = excluded.checksum, size = excluded.size, os = excluded.os, - arch = excluded.arch, - meta = excluded.meta + arch = excluded.arch WHERE checksum IS NOT excluded.checksum OR size IS NOT excluded.size OR os IS NOT excluded.os OR arch IS NOT excluded.arch - OR meta IS NOT excluded.meta RETURNING 1", ) .bind(backend) @@ -824,12 +822,22 @@ impl StorageService { .collect() } - /// Update a single file entry. - pub async fn update_file(&self, file: &RawReleaseFile) -> Result { - let mut tx = self.sqlite.begin().await?; - let changed = Self::insert_file(&mut tx, &file.backend, &file.version, file).await?; - tx.commit().await?; - Ok(changed) + /// Update file metadata (e.g. after fetching a signature). + pub async fn update_file_meta(&self, file: &RawReleaseFile) -> Result { + let meta_json = file.meta.as_ref().map(|m| serde_json::to_vec(m).unwrap()); + + let result = query( + "UPDATE files SET meta = ?1 + WHERE backend = ?2 AND version = ?3 AND filename = ?4", + ) + .bind(meta_json.as_deref()) + .bind(&file.backend) + .bind(&file.version) + .bind(&file.filename) + .execute(&self.sqlite) + .await?; + + Ok(result.rows_affected() > 0) } } @@ -872,8 +880,8 @@ impl BackendStorage for StorageService { .map_err(|e| BackendError::Storage(e.to_string())) } - async fn update_file(&self, file: &RawReleaseFile) -> Result { - StorageService::update_file(self, file) + async fn update_file_meta(&self, file: &RawReleaseFile) -> Result { + StorageService::update_file_meta(self, file) .await .map_err(|e| BackendError::Storage(e.to_string())) } -- Gilti