mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 18:31:52 +00:00
* start consolidating * add start-cli flash-os * combine install and setup and refactor all * use http * undo mock * fix translation * translations * use dialogservice wrapper * better ST messaging on setup * only warn on update if breakages (#3097) * finish setup wizard and ui language-keyboard feature * fix typo * wip: localization * remove start-tunnel readme * switch to posix strings for language internal * revert mock * translate backend strings * fix missing about text * help text for args * feat: add "Add new gateway" option (#3098) * feat: add "Add new gateway" option * Update web/projects/ui/src/app/routes/portal/components/form/controls/select.component.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * add translation --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Matt Hill <mattnine@protonmail.com> * fix dns selection * keyboard keymap also * ability to shutdown after install * revert mock * working setup flow + manifest localization * (mostly) redundant localization on frontend * version bump * omit live medium from disk list and better space management * ignore missing package archive on 035 migration * fix device migration * add i18n helper to sdk * fix install over 0.3.5.1 * fix grub config --------- Co-authored-by: Matt Hill <mattnine@protonmail.com> Co-authored-by: Matt Hill <MattDHill@users.noreply.github.com> Co-authored-by: Alex Inkin <alexander@inkin.ru> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
67 lines
2.2 KiB
Rust
67 lines
2.2 KiB
Rust
use std::path::Path;
|
|
|
|
use clap::Parser;
|
|
use rpc_toolkit::{Context, HandlerExt, ParentHandler, from_fn_async};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::CAP_10_MiB;
|
|
use crate::context::CliContext;
|
|
use crate::prelude::*;
|
|
use crate::s9pk::merkle_archive::source::ArchiveSource;
|
|
use crate::s9pk::merkle_archive::source::http::HttpSource;
|
|
use crate::s9pk::merkle_archive::source::multi_cursor_file::MultiCursorFile;
|
|
use crate::util::io::{ParallelBlake3Writer, open_file};
|
|
use crate::util::serde::Base16;
|
|
use crate::util::{Apply, PathOrUrl};
|
|
|
|
pub fn util<C: Context>() -> ParentHandler<C> {
|
|
ParentHandler::new().subcommand(
|
|
"b3sum",
|
|
from_fn_async(b3sum).with_about("about.calculate-blake3-hash-for-file"),
|
|
)
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, Parser)]
|
|
pub struct B3sumParams {
|
|
#[arg(long = "no-mmap", action = clap::ArgAction::SetFalse, help = "help.arg.no-mmap")]
|
|
allow_mmap: bool,
|
|
file: String,
|
|
}
|
|
|
|
pub async fn b3sum(
|
|
ctx: CliContext,
|
|
B3sumParams { file, allow_mmap }: B3sumParams,
|
|
) -> Result<Base16<[u8; 32]>, Error> {
|
|
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(open_file(path).await?);
|
|
if allow_mmap {
|
|
return file.blake3_mmap().await.map(|h| *h.as_bytes()).map(Base16);
|
|
}
|
|
b3sum_source(file).await
|
|
}
|
|
match file.parse::<PathOrUrl>()? {
|
|
PathOrUrl::Path(path) => b3sum_file(path, allow_mmap).await,
|
|
PathOrUrl::Url(url) => {
|
|
if url.scheme() == "http" || url.scheme() == "https" {
|
|
HttpSource::new(ctx.client.clone(), url)
|
|
.await?
|
|
.apply(b3sum_source)
|
|
.await
|
|
} else {
|
|
Err(Error::new(
|
|
eyre!("{}", t!("util.rpc.unknown-scheme", scheme = url.scheme())),
|
|
ErrorKind::InvalidRequest,
|
|
))
|
|
}
|
|
}
|
|
}
|
|
}
|