Skip to content

Commit 34dceaa

Browse files
committed
feat: networking almost complete
1 parent bcb244a commit 34dceaa

File tree

6 files changed

+261
-76
lines changed

6 files changed

+261
-76
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ serde = { version = "1.0.219", features = ["derive"] }
1717
serde_json = "1.0.140"
1818
walkdir = { version = "2.5.0", optional = true }
1919
xxhash-rust = { version = "0.8.15", features = ["xxh3"] }
20-
zstd = "0.13.3"
20+
zstd = { version = "0.13.3", default-features = false, features = ["arrays"]}
2121

2222
[features]
2323
default = ["decoding"]
2424
encoding = ["dep:walkdir"]
2525
decoding = []
2626
https = []
27+
28+
[package.metadata.docs.rs]
29+
features = ["encoding", "decoding", "https"]

examples/basic.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use anyhow::Result;
1+
#![warn(clippy::pedantic)]
22

3+
use anyhow::Result;
34
#[cfg(all(feature = "encoding", feature = "decoding"))]
45
fn main() -> Result<()> {
56
use std::path::absolute;
67
use std::{fs, path::Path};
78

8-
use lcas::{build, create_repo, create_store, install_artifact};
9+
use lcas::{RepoType, Store, build, create_repo, create_store, install_artifact};
910

1011
// Helper variables
1112
// `input_dir` is the artifact, likely produced by a build system etc. This is what we want to "transmit".
@@ -14,10 +15,19 @@ fn main() -> Result<()> {
1415
let repo_dir = absolute(Path::new("./example_repo"))?;
1516
// `store_dir` is the local path for the local store, and will be where the Store is placed, and each artifact inside.
1617
let store_dir = absolute(Path::new("./example_store"))?;
18+
// `store_dir` is the local path for the local store, and will be where the Store is placed, and each artifact inside.
19+
let cache_path = absolute(Path::new("./example_cache"))?;
20+
21+
let store = Store {
22+
kind: RepoType::Local,
23+
cache_path: cache_path,
24+
repo_path: repo_dir.to_string_lossy().to_string(),
25+
path: store_dir,
26+
};
1727

1828
// Create an example repo and a store, *locally*
1929
let _ = create_repo(repo_dir.as_path());
20-
let _ = create_store(&store_dir);
30+
let _ = create_store(&store);
2131

2232
// Create an example artifact
2333
fs::create_dir_all(Path::new("./example_dir/nested_dir/super_nested_dir"))?;
@@ -37,7 +47,7 @@ fn main() -> Result<()> {
3747
)?;
3848

3949
// Install the resulting manifest into an artifact in the `store_dir`
40-
install_artifact(&"generic".to_string(), store_dir.as_path(), &repo_dir)?;
50+
install_artifact(&"generic".to_string(), &store)?;
4151

4252
Ok(())
4353
}
@@ -51,6 +61,18 @@ fn main() -> Result<()> {
5161

5262
#[test]
5363
#[cfg(all(feature = "encoding", feature = "decoding"))]
54-
fn test_example() {
55-
main().unwrap();
64+
fn test_example() -> Result<()> {
65+
let _ = remove_dir_all(Path::new("./example_dir"));
66+
let _ = remove_dir_all(Path::new("./example_store"));
67+
let _ = remove_dir_all(Path::new("./example_repo"));
68+
let _ = remove_dir_all(Path::new("./example_cache"));
69+
70+
let val = main();
71+
72+
let _ = remove_dir_all(Path::new("./example_dir"));
73+
let _ = remove_dir_all(Path::new("./example_store"));
74+
let _ = remove_dir_all(Path::new("./example_repo"));
75+
let _ = remove_dir_all(Path::new("./example_cache"));
76+
77+
val
5678
}

src/artifacts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
use std::{fs, path::Path};
24

35
fn read_artifacts_file(artifacts_file_path: &Path) -> Vec<(String, String)> {

src/compression.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
// Compresses with ZSTD
24
#[cfg(feature = "encoding")]
35
pub fn compress_file(input: &Vec<u8>, level: i32) -> Vec<u8> {

src/hash.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#![warn(clippy::pedantic)]
2+
13
use xxhash_rust::xxh3::xxh3_64;
24

35
// Hashes with xxh3
46
#[cfg(any(feature = "decoding", feature = "encoding"))]
5-
pub fn hash(input: &Vec<u8>) -> String {
6-
xxh3_64(&input).to_string()
7+
pub fn hash(input: &[u8]) -> String {
8+
xxh3_64(input).to_string()
79
}
810

911
// Converts the manifest to a string, and then hashes it

0 commit comments

Comments
 (0)