fix some silly mistakes

This commit is contained in:
cy 2025-04-13 20:56:33 -04:00
parent 2c252a42c5
commit 202b222b83
Signed by: cy
SSH key fingerprint: SHA256:o/geVWV4om1QhUSkKvDQeW/eAihwnjyXkqMwrVdbuts
2 changed files with 11 additions and 12 deletions

View file

@ -2,8 +2,8 @@ use std::collections::HashSet;
use anyhow::{Context, Error, Result};
use log::{debug, error, trace};
use nix_compat::nixhash::CAHash;
use nix_compat::store_path::StorePath;
use nix_compat::{nixbase32, nixhash::CAHash};
use regex::Regex;
use serde::{Deserialize, Serialize};
use tokio::process::Command;
@ -97,12 +97,9 @@ impl PathInfo {
}
pub async fn check_upstream_hit(&self, upstreams: &[Url]) -> bool {
let hash =
String::from_utf8(self.path.digest().to_vec()).expect("should be a valid string");
for upstream in upstreams {
let upstream = upstream
.join(format!("{hash}/.narinfo").as_str())
.join(format!("{}/.narinfo", self.digest()).as_str())
.expect("adding <hash>.narinfo should make a valid url");
let res_status = reqwest::Client::new()
.head(upstream.as_str())
@ -121,8 +118,8 @@ impl PathInfo {
self.path.to_absolute_path()
}
pub fn digest(&self) -> &str {
str::from_utf8(self.path.digest()).expect("digest should be valid string")
pub fn digest(&self) -> String {
nixbase32::encode(self.path.digest())
}
}

View file

@ -49,8 +49,10 @@ impl<'a> Uploader<'a> {
nar_info.file_size = Some(nar.len() as u64);
let mut hasher = Sha256::new();
hasher.update(&nar);
nar_info.file_hash = Some(hasher.finalize().into());
let nar_url = self.nar_url(&nar);
let hash: [u8; 32] = hasher.finalize().into();
let nar_url = self.nar_url(&hash);
nar_info.file_hash = Some(hash);
debug!("uploading to bucket with key: {nar_url}");
if nar.len() < MULTIPART_CUTOFF {
let put_object = self
@ -120,8 +122,6 @@ impl<'a> Uploader<'a> {
debug!("complete multipart upload: {:#?}", complete_mp_upload);
}
nar_info.add_signature(self.signing_key);
self.s3_client
.put_object()
.bucket(&self.bucket)
@ -147,7 +147,7 @@ impl<'a> Uploader<'a> {
let mut hasher = Sha256::new();
hasher.update(nar);
let nar_hash: [u8; 32] = hasher.finalize().into();
let nar_info = NarInfo {
let mut nar_info = NarInfo {
flags: narinfo::Flags::empty(),
store_path: self.path.path.as_ref(),
nar_hash,
@ -162,6 +162,8 @@ impl<'a> Uploader<'a> {
file_size: None,
url: "",
};
// signature consists of: store_path, nar_hash, nar_size, and references
nar_info.add_signature(self.signing_key);
Ok(nar_info)
}