Feature/registry package index (#2623)

* include system images in compat s9pk

* wip

* wip

* update types

* wip

* fix signature serialization

* Add SignatureHeader conversions

* finish display impl for get

---------

Co-authored-by: Shadowy Super Coder <musashidisciple@proton.me>
This commit is contained in:
Aiden McClelland
2024-05-31 12:13:23 -06:00
committed by GitHub
parent 0ccbb52c1f
commit fd7c2fbe93
113 changed files with 3265 additions and 1436 deletions

View File

@@ -1,3 +1,4 @@
use std::path::Path;
use clap::Parser;
use rpc_toolkit::{from_fn_async, Context, ParentHandler};
@@ -9,9 +10,11 @@ use crate::context::CliContext;
use crate::prelude::*;
use crate::s9pk::merkle_archive::source::http::HttpSource;
use crate::s9pk::merkle_archive::source::multi_cursor_file::MultiCursorFile;
use crate::s9pk::merkle_archive::source::{ArchiveSource, DynFileSource, FileSource};
use crate::s9pk::merkle_archive::source::ArchiveSource;
use crate::util::io::ParallelBlake3Writer;
use crate::util::serde::Base16;
use crate::util::Apply;
use crate::CAP_10_MiB;
pub fn util<C: Context>() -> ParentHandler<C> {
ParentHandler::new().subcommand("b3sum", from_fn_async(b3sum))
@@ -28,26 +31,29 @@ pub async fn b3sum(
ctx: CliContext,
B3sumParams { file, allow_mmap }: B3sumParams,
) -> Result<Base16<[u8; 32]>, Error> {
let source = if let Ok(url) = file.parse::<Url>() {
async fn b3sum_source<S: ArchiveSource>(source: S) -> Result<Base16<[u8; 32]>, Error> {
let mut hasher = ParallelBlake3Writer::new(CAP_10_MiB);
source.copy_all_to(&mut hasher).await?;
hasher.finalize().await.map(|h| *h.as_bytes()).map(Base16)
}
async fn b3sum_file(
path: impl AsRef<Path>,
allow_mmap: bool,
) -> Result<Base16<[u8; 32]>, Error> {
let file = MultiCursorFile::from(File::open(path).await?);
if allow_mmap {
return file.blake3_mmap().await.map(|h| *h.as_bytes()).map(Base16);
}
b3sum_source(file).await
}
if let Ok(url) = file.parse::<Url>() {
if url.scheme() == "file" {
let file = MultiCursorFile::from(File::open(url.path()).await?);
if allow_mmap {
return file.blake3_mmap().await.map(|h| *h.as_bytes()).map(Base16);
}
DynFileSource::new(file.section(
0,
file.size().await.ok_or_else(|| {
Error::new(eyre!("failed to get file size"), ErrorKind::Filesystem)
})?,
))
b3sum_file(url.path(), allow_mmap).await
} else if url.scheme() == "http" || url.scheme() == "https" {
let file = HttpSource::new(ctx.client.clone(), url).await?;
DynFileSource::new(file.section(
0,
file.size().await.ok_or_else(|| {
Error::new(eyre!("failed to get file size"), ErrorKind::Filesystem)
})?,
))
HttpSource::new(ctx.client.clone(), url)
.await?
.apply(b3sum_source)
.await
} else {
return Err(Error::new(
eyre!("unknown scheme: {}", url.scheme()),
@@ -55,18 +61,6 @@ pub async fn b3sum(
));
}
} else {
let file = MultiCursorFile::from(File::open(file).await?);
if allow_mmap {
return file.blake3_mmap().await.map(|h| *h.as_bytes()).map(Base16);
}
DynFileSource::new(file.section(
0,
file.size().await.ok_or_else(|| {
Error::new(eyre!("failed to get file size"), ErrorKind::Filesystem)
})?,
))
};
let mut hasher = ParallelBlake3Writer::new(crate::s9pk::merkle_archive::hash::BUFFER_CAPACITY);
source.copy(&mut hasher).await?;
hasher.finalize().await.map(|h| *h.as_bytes()).map(Base16)
b3sum_file(file, allow_mmap).await
}
}