Skip to content

Commit d88b7e2

Browse files
committed
impl repo remove, building
1 parent 99f5942 commit d88b7e2

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

build_manifest.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
id: "example_package"
2+
aliases: ["example"]
3+
4+
metadata:
5+
name: "Example Package"
6+
description: "This is an example package. It should include the entire Flint source Repository."
7+
license: "MIT or APACHE-2.0"
8+
homepage_url: "https://github.com/TimelessOS/Flint"
9+
# This package does not have a version.
10+
11+
directory: src

src/build/mod.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
1-
use anyhow::Result;
1+
use anyhow::{Context, Result};
22
use std::{
33
fs,
44
path::{Path, PathBuf},
55
};
66

77
use crate::{
88
chunks::save_tree,
9-
crypto::signing::sign,
10-
repo::{self, Metadata, PackageManifest, update_manifest},
9+
repo::{self, Metadata, PackageManifest, insert_package},
1110
};
1211

1312
#[derive(serde::Deserialize, serde::Serialize, Clone)]
1413
struct BuildManifest {
1514
/// ID of this package, the main alias
1615
id: String,
1716
/// Aliases for installation
17+
#[serde(default)]
1818
aliases: Vec<String>,
1919
/// Package Metadata
2020
metadata: Metadata,
2121
/// A list of commands that this will give access to
22+
#[serde(default)]
2223
commands: Vec<String>,
2324
/// Directory relative to the manifest
2425
directory: PathBuf,
2526
}
2627

2728
pub fn build(build_manifest_path: &Path, repo_path: &Path) -> Result<PackageManifest> {
29+
let build_manifest_path = &build_manifest_path.canonicalize()?;
30+
2831
let build_manifest: BuildManifest =
2932
serde_yaml::from_str(&fs::read_to_string(build_manifest_path)?)?;
3033

31-
let repo_manifest = repo::read_manifest(repo_path)?;
34+
let repo_manifest =
35+
repo::read_manifest(repo_path).with_context(|| "The target Repostiory does not exist")?;
36+
37+
let build_manifest_parent = &build_manifest_path
38+
.parent()
39+
.unwrap_or_else(|| Path::new("/"));
3240

3341
let chunks = save_tree(
34-
&build_manifest_path.join(build_manifest.directory),
42+
&build_manifest_parent.join(build_manifest.directory),
3543
&repo_path.join("chunks"),
3644
repo_manifest.hash_kind,
3745
)?;
@@ -44,13 +52,7 @@ pub fn build(build_manifest_path: &Path, repo_path: &Path) -> Result<PackageMani
4452
chunks,
4553
};
4654

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-
)?;
55+
insert_package(&package_manifest, repo_path)?;
5456

5557
Ok(package_manifest)
5658
}

src/chunks/tree.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ pub fn save_tree(
2929
let hash = hash(hash_kind, &contents);
3030
let mode = file.metadata()?.permissions().mode() & 0o777;
3131

32+
if !chunk_store_path.exists() {
33+
fs::create_dir_all(chunk_store_path)?;
34+
}
35+
3236
let chunk_path = &chunk_store_path.join(get_chunk_filename(&hash, mode));
3337
if fs::hard_link(file.path(), chunk_path).is_err() {
3438
fs::write(chunk_path, contents)?;

src/main.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
use anyhow::Result;
22
use clap::{Parser, Subcommand};
33
use comfy_table::Table;
4-
use flint::repo::{self, update_manifest};
5-
use std::{fs, path::Path};
4+
use flint::{
5+
build::build,
6+
repo::{self, update_manifest},
7+
};
8+
use std::{
9+
fs,
10+
path::{Path, PathBuf},
11+
};
612

713
use crate::{crypto::signing::sign, utils::config::get_repos_dir};
814

@@ -34,7 +40,10 @@ enum Command {
3440
command: RepoCommands,
3541
},
3642
/// Builds a package from a local manifest and directory
37-
Build,
43+
Build {
44+
build_manifest_path: PathBuf,
45+
repo_name: String,
46+
},
3847
/// Install a package
3948
Install,
4049
/// Remove a package
@@ -151,7 +160,9 @@ fn main() -> Result<()> {
151160
remote_url,
152161
} => todo!(),
153162

154-
RepoCommands::Remove { repo_name } => todo!(),
163+
RepoCommands::Remove { repo_name } => {
164+
fs::remove_dir_all(path.join(repo_name))?;
165+
}
155166

156167
RepoCommands::Update {
157168
homepage_url,
@@ -183,7 +194,12 @@ fn main() -> Result<()> {
183194
}
184195
},
185196

186-
Command::Build => todo!(),
197+
Command::Build {
198+
build_manifest_path,
199+
repo_name,
200+
} => {
201+
build(&build_manifest_path, &path.join(repo_name))?;
202+
}
187203

188204
Command::Install => todo!(),
189205

0 commit comments

Comments
 (0)