Skip to content

Commit 295ee2a

Browse files
committed
chore: additional feature gating
1 parent c8fb0fb commit 295ee2a

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

src/artifacts.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fn read_artifacts_file(artifacts_file_path: &Path) -> Vec<(String, String)> {
1818
lines
1919
}
2020

21+
#[cfg(feature = "decoding")]
2122
pub fn get_artifact(artifact_name: &String, artifacts_file_path: &Path) -> Option<String> {
2223
let artifacts = read_artifacts_file(artifacts_file_path);
2324

@@ -30,6 +31,7 @@ pub fn get_artifact(artifact_name: &String, artifacts_file_path: &Path) -> Optio
3031
.map(|artifact| artifact.1.clone())
3132
}
3233

34+
#[cfg(feature = "encoding")]
3335
pub fn add_artifact(artifact_name: String, manifest_hash: String, artifacts_file_path: &Path) {
3436
let mut artifacts: Vec<(String, String)> = read_artifacts_file(&artifacts_file_path)
3537
.iter()
@@ -43,6 +45,7 @@ pub fn add_artifact(artifact_name: String, manifest_hash: String, artifacts_file
4345
.expect("Couldn't write artifacts file");
4446
}
4547

48+
#[cfg(feature = "encoding")]
4649
fn serialize_artifacts(artifacts: Vec<(String, String)>) -> String {
4750
let mut string = String::new();
4851

@@ -60,6 +63,7 @@ mod tests {
6063
use super::*;
6164

6265
#[test]
66+
#[cfg(all(feature = "encoding", feature = "decoding"))]
6367
fn simple_all() {
6468
let artifacts = vec![
6569
("test1".to_string(), 1.to_string()),
@@ -86,6 +90,7 @@ mod tests {
8690
}
8791

8892
#[test]
93+
#[cfg(all(feature = "encoding", feature = "decoding"))]
8994
fn get_artifact_not_found() {
9095
let artifact_file_path = temp_dir().join("LCAS_test_artifact_not_found.test");
9196
// Ensure file is empty
@@ -97,6 +102,7 @@ mod tests {
97102
}
98103

99104
#[test]
105+
#[cfg(feature = "encoding")]
100106
fn add_artifact_overwrites_existing() {
101107
let artifact_file_path = temp_dir().join("LCAS_test_artifact_overwrite.test");
102108
add_artifact(
@@ -132,6 +138,7 @@ mod tests {
132138
}
133139

134140
#[test]
141+
#[cfg(feature = "encoding")]
135142
fn simple_serialize_artifacts() {
136143
let artifacts = vec![
137144
("test1".to_string(), 1.to_string()),

src/compression.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::io;
2-
31
// Compresses with ZSTD
42
#[cfg(feature = "encoding")]
53
pub fn compress_file(input: &Vec<u8>, level: i32) -> Vec<u8> {
4+
use std::io;
5+
66
let mut buf = Vec::new();
77

88
let mut encoder = zstd::stream::Encoder::new(&mut buf, level).unwrap();

src/hash.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use xxhash_rust::xxh3::xxh3_64;
22

33
// Hashes with xxh3
4+
#[cfg(any(feature = "decoding", feature = "encoding"))]
45
pub fn hash(input: &Vec<u8>) -> String {
56
xxh3_64(&input).to_string()
67
}
78

89
// Converts the manifest to a string, and then hashes it
10+
#[cfg(feature = "encoding")]
911
pub fn hash_manifest(input: &Vec<(String, String, bool)>) -> String {
1012
// Not a true hash. Just a temporary place to dump data, which can then be hashed
1113
let mut current_hash = "".to_string();
@@ -25,18 +27,21 @@ mod tests {
2527
use super::*;
2628

2729
#[test]
30+
#[cfg(any(feature = "decoding", feature = "encoding"))]
2831
fn hash_stable() {
2932
let result = hash(&vec![1, 2, 3]);
3033
assert_eq!(result, "16991689376074199867");
3134
}
3235

3336
#[test]
37+
#[cfg(any(feature = "decoding", feature = "encoding"))]
3438
fn hash_empty_vec() {
3539
let result = hash(&vec![]);
3640
assert_eq!(result, "3244421341483603138");
3741
}
3842

3943
#[test]
44+
#[cfg(feature = "encoding")]
4045
fn hash_manifest_stable() {
4146
let manifest = vec![
4247
("file1.txt".to_string(), "hash1".to_string(), false),
@@ -47,13 +52,15 @@ mod tests {
4752
}
4853

4954
#[test]
55+
#[cfg(feature = "encoding")]
5056
fn hash_manifest_empty() {
5157
let manifest: Vec<(String, String, bool)> = vec![];
5258
let result = hash_manifest(&manifest);
5359
assert_eq!(result, "3244421341483603138");
5460
}
5561

5662
#[test]
63+
#[cfg(feature = "encoding")]
5764
fn hash_manifest_single_entry() {
5865
let manifest = vec![("main.rs".to_string(), "abc123".to_string(), true)];
5966
let result = hash_manifest(&manifest);

src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
use std::{
2-
fs::{self, create_dir_all, rename},
3-
os::unix::fs::{PermissionsExt, symlink},
4-
path::Path,
5-
};
6-
7-
use crate::artifacts::get_artifact;
1+
use std::{fs, path::Path};
82

93
mod artifacts;
104
mod compression;
@@ -30,6 +24,7 @@ pub fn create_repo(repo_dir: &Path) -> Result<(), String> {
3024
Ok(())
3125
}
3226

27+
#[cfg(feature = "decoding")]
3328
pub fn create_store(store_path: &Path) -> Result<(), String> {
3429
if store_path.exists() {
3530
return Err("Store already exists! Make sure the directory doesn't exist, or you're operating on the correct directory.".to_string());
@@ -103,6 +98,10 @@ pub fn build(input_dir: &Path, repo_dir: &Path, artifact_name: &String) -> Resul
10398

10499
#[cfg(feature = "decoding")]
105100
pub fn install_artifact(artifact_name: &String, store_path: &Path, repo_cache_path: &Path) {
101+
use crate::artifacts::get_artifact;
102+
use std::fs::{create_dir_all, rename};
103+
use std::os::unix::fs::symlink;
104+
106105
assert!(store_path.is_absolute(), "Store path must be absolute!");
107106
assert!(
108107
repo_cache_path.is_absolute(),
@@ -163,6 +162,7 @@ pub fn install_artifact(artifact_name: &String, store_path: &Path, repo_cache_pa
163162
rename(&tmp_symlink, &final_symlink).unwrap();
164163
}
165164

165+
#[cfg(feature = "decoding")]
166166
fn get_temp_file(potential: Option<u8>, dir: &Path) -> String {
167167
let potential = potential.unwrap_or_default();
168168

@@ -175,7 +175,10 @@ fn get_temp_file(potential: Option<u8>, dir: &Path) -> String {
175175
};
176176
}
177177

178+
#[cfg(feature = "decoding")]
178179
fn make_chunk_executable(chunk_hash: &String, store_path: &Path) {
180+
use std::os::unix::fs::PermissionsExt;
181+
179182
let chunk_path = store_path.join("chunks").join(chunk_hash);
180183

181184
// Read initial permissions first

0 commit comments

Comments
 (0)