Skip to content

Commit 5dbaa1e

Browse files
committed
Creating repos, Listing repos, and Updating repos
1 parent ba827e4 commit 5dbaa1e

File tree

8 files changed

+435
-12
lines changed

8 files changed

+435
-12
lines changed

Cargo.lock

Lines changed: 156 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ edition = "2024"
1111
[dependencies]
1212
anyhow = "1.0.99"
1313
blake3 = { version = "1.8.2", features = ["digest"] }
14-
clap = "4.5.47"
14+
clap = { version = "4.5.47", features = ["derive"] }
15+
clap-cargo = "0.17.0"
16+
comfy-table = "7.2.0"
1517
directories = "6.0.0"
1618
ed25519-dalek = { version = "=3.0.0-pre.0", features = [
1719
"pem",
@@ -20,7 +22,6 @@ ed25519-dalek = { version = "=3.0.0-pre.0", features = [
2022
"signature",
2123
] }
2224
futures = "0.3.31"
23-
hex = "0.4.3"
2425
rand_core = { version = "0.9.3", features = ["os_rng"] }
2526
reqwest = "0.12.23"
2627
serde = { version = "1.0.219", features = ["derive"] }

src/build/mod.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use anyhow::Result;
2+
use std::{
3+
fs,
4+
path::{Path, PathBuf},
5+
};
6+
7+
use crate::{
8+
chunks::save_tree,
9+
crypto::signing::sign,
10+
repo::{self, Metadata, PackageManifest, update_manifest},
11+
};
12+
13+
#[derive(serde::Deserialize, serde::Serialize, Clone)]
14+
struct BuildManifest {
15+
/// ID of this package, the main alias
16+
id: String,
17+
/// Aliases for installation
18+
aliases: Vec<String>,
19+
/// Package Metadata
20+
metadata: Metadata,
21+
/// A list of commands that this will give access to
22+
commands: Vec<String>,
23+
/// Directory relative to the manifest
24+
directory: PathBuf,
25+
}
26+
27+
pub fn build(build_manifest_path: &Path, repo_path: &Path) -> Result<PackageManifest> {
28+
let build_manifest: BuildManifest =
29+
serde_yaml::from_str(&fs::read_to_string(build_manifest_path)?)?;
30+
31+
let repo_manifest = repo::read_manifest_unsigned(repo_path)?;
32+
33+
let chunks = save_tree(
34+
&build_manifest_path.join(build_manifest.directory),
35+
&repo_path.join("chunks"),
36+
repo_manifest.hash_kind,
37+
)?;
38+
39+
let package_manifest = PackageManifest {
40+
aliases: build_manifest.aliases,
41+
commands: build_manifest.commands,
42+
id: build_manifest.id,
43+
metadata: build_manifest.metadata,
44+
chunks,
45+
};
46+
47+
let package_manifest_serialized = &serde_yaml::to_string(&package_manifest)?;
48+
49+
update_manifest(
50+
repo_path,
51+
package_manifest_serialized,
52+
&sign(repo_path, package_manifest_serialized)?.to_bytes(),
53+
)?;
54+
55+
Ok(package_manifest)
56+
}

src/chunks/hash.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt;
2+
13
/// WARNING: Only Blake3 is currently implemented for the time being.
24
35
#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, Copy)]
@@ -7,6 +9,16 @@ pub enum HashKind {
79
Sha256,
810
}
911

12+
impl fmt::Display for HashKind {
13+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14+
match *self {
15+
Self::Blake3 => write!(f, "Blake3"),
16+
Self::Sha512 => write!(f, "Sha512"),
17+
Self::Sha256 => write!(f, "Sha256"),
18+
}
19+
}
20+
}
21+
1022
pub fn hash(hash_kind: HashKind, data: &[u8]) -> String {
1123
match hash_kind {
1224
HashKind::Blake3 => blake3::hash(data).to_hex().to_string(),

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod build;
12
pub mod bundle;
23
pub mod chunks;
34
mod crypto;

0 commit comments

Comments
 (0)