fix some silly mistakes
This commit is contained in:
parent
2c252a42c5
commit
202b222b83
2 changed files with 11 additions and 12 deletions
|
@ -2,8 +2,8 @@ use std::collections::HashSet;
|
||||||
|
|
||||||
use anyhow::{Context, Error, Result};
|
use anyhow::{Context, Error, Result};
|
||||||
use log::{debug, error, trace};
|
use log::{debug, error, trace};
|
||||||
use nix_compat::nixhash::CAHash;
|
|
||||||
use nix_compat::store_path::StorePath;
|
use nix_compat::store_path::StorePath;
|
||||||
|
use nix_compat::{nixbase32, nixhash::CAHash};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
|
@ -97,12 +97,9 @@ impl PathInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn check_upstream_hit(&self, upstreams: &[Url]) -> bool {
|
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 {
|
for upstream in upstreams {
|
||||||
let upstream = upstream
|
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");
|
.expect("adding <hash>.narinfo should make a valid url");
|
||||||
let res_status = reqwest::Client::new()
|
let res_status = reqwest::Client::new()
|
||||||
.head(upstream.as_str())
|
.head(upstream.as_str())
|
||||||
|
@ -121,8 +118,8 @@ impl PathInfo {
|
||||||
self.path.to_absolute_path()
|
self.path.to_absolute_path()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn digest(&self) -> &str {
|
pub fn digest(&self) -> String {
|
||||||
str::from_utf8(self.path.digest()).expect("digest should be valid string")
|
nixbase32::encode(self.path.digest())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,10 @@ impl<'a> Uploader<'a> {
|
||||||
nar_info.file_size = Some(nar.len() as u64);
|
nar_info.file_size = Some(nar.len() as u64);
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(&nar);
|
hasher.update(&nar);
|
||||||
nar_info.file_hash = Some(hasher.finalize().into());
|
let hash: [u8; 32] = hasher.finalize().into();
|
||||||
let nar_url = self.nar_url(&nar);
|
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 {
|
if nar.len() < MULTIPART_CUTOFF {
|
||||||
let put_object = self
|
let put_object = self
|
||||||
|
@ -120,8 +122,6 @@ impl<'a> Uploader<'a> {
|
||||||
debug!("complete multipart upload: {:#?}", complete_mp_upload);
|
debug!("complete multipart upload: {:#?}", complete_mp_upload);
|
||||||
}
|
}
|
||||||
|
|
||||||
nar_info.add_signature(self.signing_key);
|
|
||||||
|
|
||||||
self.s3_client
|
self.s3_client
|
||||||
.put_object()
|
.put_object()
|
||||||
.bucket(&self.bucket)
|
.bucket(&self.bucket)
|
||||||
|
@ -147,7 +147,7 @@ impl<'a> Uploader<'a> {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(nar);
|
hasher.update(nar);
|
||||||
let nar_hash: [u8; 32] = hasher.finalize().into();
|
let nar_hash: [u8; 32] = hasher.finalize().into();
|
||||||
let nar_info = NarInfo {
|
let mut nar_info = NarInfo {
|
||||||
flags: narinfo::Flags::empty(),
|
flags: narinfo::Flags::empty(),
|
||||||
store_path: self.path.path.as_ref(),
|
store_path: self.path.path.as_ref(),
|
||||||
nar_hash,
|
nar_hash,
|
||||||
|
@ -162,6 +162,8 @@ impl<'a> Uploader<'a> {
|
||||||
file_size: None,
|
file_size: None,
|
||||||
url: "",
|
url: "",
|
||||||
};
|
};
|
||||||
|
// signature consists of: store_path, nar_hash, nar_size, and references
|
||||||
|
nar_info.add_signature(self.signing_key);
|
||||||
Ok(nar_info)
|
Ok(nar_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue