diff options
| -rw-r--r-- | resources/helps/butck.txt | 8 | ||||
| -rw-r--r-- | scripts/sh/comp_butck.sh | 4 | ||||
| -rw-r--r-- | src/chunker/constants.rs | 2 | ||||
| -rw-r--r-- | src/chunker/context.rs | 18 | ||||
| -rw-r--r-- | src/chunker/rw/storage/build.rs | 9 | ||||
| -rw-r--r-- | src/chunker/rw/storage/write/simple.rs | 16 | ||||
| -rw-r--r-- | src/chunker/rw/storage/write/stream.rs | 6 | ||||
| -rw-r--r-- | src/entry.rs | 26 |
8 files changed, 48 insertions, 41 deletions
diff --git a/resources/helps/butck.txt b/resources/helps/butck.txt index 0886b39..bca4d3d 100644 --- a/resources/helps/butck.txt +++ b/resources/helps/butck.txt @@ -6,7 +6,7 @@ Usage: butck [-v | --version] [-h | --help] [-q | --quiet] [-H | --chunk-hash <blake3/sha256>] [-o | --output-dir <output>] [-O | --output-file <file>] [-r | --recursive] [-R | --register <name>] - [-S | --stream-read <size_byte>] [-m | --memmap-read] + [-S | --stream <size_byte>] [-m | --memmap-read] [+p | +param key=value] @@ -14,9 +14,9 @@ Subcommands: write <file> Write a file and output the index file write <file> -R <name> Then, register the index build <index/name> Input an index file and build the file from the storage - policies Output all available policies (including stream policies) - simple_policies Output only simple policies - stream_policies Output only stream policies + lspolicy List available policies + (`--stream 0` to display stream policies) + lspolicy-all List all policies (including streaming) Butchunker 0.1.0 Copyright (c) 2026 Weicao-CatilGrass diff --git a/scripts/sh/comp_butck.sh b/scripts/sh/comp_butck.sh index b59dc62..1cf0990 100644 --- a/scripts/sh/comp_butck.sh +++ b/scripts/sh/comp_butck.sh @@ -30,7 +30,7 @@ _butck_completion() { ;; -p|--policy) local policies - policies=$(butck policies 2>/dev/null) + policies=$(butck lspolicy-all 2>/dev/null) COMPREPLY=($(compgen -W "$policies" -- "$cur")) return ;; @@ -40,7 +40,7 @@ _butck_completion() { esac if [[ $cword -eq 1 ]]; then - COMPREPLY=($(compgen -W "write build state policies stream_policies simple_policies" -- "$cur")) + COMPREPLY=($(compgen -W "write build lspolicy lspolicy-all" -- "$cur")) fi if [[ $cword -ge 2 ]]; then diff --git a/src/chunker/constants.rs b/src/chunker/constants.rs index 11cb994..af83951 100644 --- a/src/chunker/constants.rs +++ b/src/chunker/constants.rs @@ -1,3 +1,3 @@ -pub const BUTCK_STORAGE_DIR_NAME: &str = ".butck"; +pub const BUTCK_METADATA_DIR_NAME: &str = ".butck"; pub const BUTCK_INDEX_FILE_SUFFIX: &str = "bidx"; pub const BUTCK_INDEX_MAGIC: [u8; 4] = *b"G00d"; diff --git a/src/chunker/context.rs b/src/chunker/context.rs index b7418f0..cf848ef 100644 --- a/src/chunker/context.rs +++ b/src/chunker/context.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, env::current_dir, path::PathBuf, process::exit, use log::{error, warn}; use crate::{ - chunker::{constants::BUTCK_STORAGE_DIR_NAME, rw::storage::hash::ChunkWriteHash}, + chunker::{constants::BUTCK_METADATA_DIR_NAME, rw::storage::hash::ChunkWriteHash}, special_argument, special_flag, utils::file_input_solve::parse_path_input, }; @@ -60,7 +60,7 @@ impl ButckContext { ctx.apply_display_boundaries(&mut args); // Finally, parse path input - ctx.file_paths = parse_path_input(args, recursive, vec![BUTCK_STORAGE_DIR_NAME]); + ctx.file_paths = parse_path_input(args, recursive, vec![BUTCK_METADATA_DIR_NAME]); ctx } @@ -69,7 +69,7 @@ impl ButckContext { } fn apply_stream_read(&mut self, args: &mut Vec<String>) { - if let Some(size_str) = special_argument!(args, "-S", "--stream-read") + if let Some(size_str) = special_argument!(args, "-S", "--stream") && let Ok(size) = size_str.parse::<u32>() { self.stream_read = Some(size); @@ -161,17 +161,17 @@ impl ButckContext { error!("Failed to create directory '{}': {}", path.display(), e); exit(1); } - let butck_dir = path.join(BUTCK_STORAGE_DIR_NAME); + let butck_dir = path.join(BUTCK_METADATA_DIR_NAME); if let Err(e) = std::fs::create_dir_all(&butck_dir) { error!( "Failed to create '{}' directory: {}", - BUTCK_STORAGE_DIR_NAME, e + BUTCK_METADATA_DIR_NAME, e ); exit(1); } Some(path) } else { - let butck_dir = path.join(BUTCK_STORAGE_DIR_NAME); + let butck_dir = path.join(BUTCK_METADATA_DIR_NAME); // Check if Butck Storage already exists if butck_dir.exists() { @@ -188,7 +188,7 @@ impl ButckContext { // Warn about creating storage in non-empty directory warn!( "Creating '{}' storage in non-empty directory: {}", - BUTCK_STORAGE_DIR_NAME, + BUTCK_METADATA_DIR_NAME, path.display() ); } @@ -197,7 +197,7 @@ impl ButckContext { if let Err(e) = std::fs::create_dir_all(&butck_dir) { error!( "Failed to create '{}' directory: {}", - BUTCK_STORAGE_DIR_NAME, e + BUTCK_METADATA_DIR_NAME, e ); exit(1); } @@ -214,7 +214,7 @@ impl ButckContext { }; loop { - let butck_dir = current_dir.join(BUTCK_STORAGE_DIR_NAME); + let butck_dir = current_dir.join(BUTCK_METADATA_DIR_NAME); if butck_dir.is_dir() { return Some(current_dir); } diff --git a/src/chunker/rw/storage/build.rs b/src/chunker/rw/storage/build.rs index 51b5bf5..d565693 100644 --- a/src/chunker/rw/storage/build.rs +++ b/src/chunker/rw/storage/build.rs @@ -8,8 +8,10 @@ use crate::{ chunker::{ constants::BUTCK_INDEX_FILE_SUFFIX, context::ButckContext, - rw::error::{ButckRWError, ButckRWErrorKind}, - rw::storage, + rw::{ + error::{ButckRWError, ButckRWErrorKind}, + storage, + }, }, utils::size_display::size_display, }; @@ -110,6 +112,7 @@ async fn rebuild_from_bidx( progress::update_progress(progress_name.as_str(), 0.0); let step = 1.0 / chunk_count as f64; + let storage_dir = ctx.storage_path.as_ref().unwrap(); let mut tasks = Vec::with_capacity(chunk_count); for (index, hash_bytes) in chunk_hashes.iter().enumerate() { @@ -118,7 +121,7 @@ async fn rebuild_from_bidx( progress_name.as_str(), step, hash_hex, - &ctx.output_dir, + &storage_dir, index, )); } diff --git a/src/chunker/rw/storage/write/simple.rs b/src/chunker/rw/storage/write/simple.rs index 38aecfc..461afff 100644 --- a/src/chunker/rw/storage/write/simple.rs +++ b/src/chunker/rw/storage/write/simple.rs @@ -87,16 +87,20 @@ async fn write_file_to_storage( trace!("file_size={}", raw_data.len()); trace!("output_index_file={}", output_index_file.display()); trace!("policy_name={:?}", ctx.policy_name); - trace!("storage_dir={}", ctx.output_dir.display()); + trace!( + "storage_dir={}", + ctx.storage_path.as_ref().unwrap().display() + ); info!( "{} chunks will be written to {}", chunk_count, - ctx.output_dir.display() + ctx.storage_path.as_ref().unwrap().display() ); - tokio::fs::create_dir_all(&ctx.output_dir).await?; - trace!("Output directory created or already exists"); + let storage_dir = ctx.storage_path.as_ref().unwrap().clone(); + tokio::fs::create_dir_all(&storage_dir).await?; + trace!("Storage directory created or already exists"); let mut tasks = Vec::new(); let mut start = 0; @@ -119,7 +123,7 @@ async fn write_file_to_storage( progress_name: progress_name.clone(), step, chunk_data: chunk_data.to_vec(), - output_dir: ctx.output_dir.clone(), + output_dir: ctx.storage_path.as_ref().unwrap().clone(), chunk_hash: ctx.chunk_hash, chunk_index, }; @@ -149,7 +153,7 @@ async fn write_file_to_storage( progress_name: progress_name.clone(), step, chunk_data: chunk_data.to_vec(), - output_dir: ctx.output_dir.clone(), + output_dir: ctx.storage_path.as_ref().unwrap().clone(), chunk_hash: ctx.chunk_hash, chunk_index, }; diff --git a/src/chunker/rw/storage/write/stream.rs b/src/chunker/rw/storage/write/stream.rs index 092cee7..74a391b 100644 --- a/src/chunker/rw/storage/write/stream.rs +++ b/src/chunker/rw/storage/write/stream.rs @@ -42,7 +42,7 @@ pub async fn write_file_stream( // Collect chunk information let chunk_infos = Arc::new(Mutex::new(Vec::new())); let chunk_counter = Arc::new(Mutex::new(0usize)); - let output_dir = ctx.output_dir.clone(); + let storage_dir = ctx.storage_path.as_ref().unwrap().clone(); let chunk_hash = ctx.chunk_hash; // If only displaying boundaries, use chunk_stream_display_boundaries @@ -80,7 +80,7 @@ pub async fn write_file_stream( stream_read_size, path, |chunk_data: Vec<u8>| { - let output_dir = output_dir.clone(); + let storage_dir = storage_dir.clone(); let chunk_hash = chunk_hash; let progress_name = progress_name.clone(); let chunk_infos = Arc::clone(&chunk_infos); @@ -97,7 +97,7 @@ pub async fn write_file_stream( let hash_hex = hex::encode(hash_bytes); // Build file path - let file_path = get_chunk_path(&output_dir, &hash_hex); + let file_path = get_chunk_path(&storage_dir, &hash_hex); // Create directory if needed if let Some(parent_dir) = file_path.parent() { diff --git a/src/entry.rs b/src/entry.rs index 4e91e59..f1d5203 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -10,7 +10,19 @@ pub async fn entry(ctx: ButckContext, args: Vec<String>) -> Result<(), ButckRWEr return match subcommand.as_str() { "write" => rw::storage::write(ctx).await, "build" => rw::storage::build(ctx).await, - "policies" => { + "lspolicy" => { + if ctx.stream_read.is_some() { + butck_policies::stream_policies() + .iter() + .for_each(|p| println!("{}", p)); + } else { + butck_policies::policies() + .iter() + .for_each(|p| println!("{}", p)); + } + return Ok(()); + } + "lspolicy-all" => { let policies = butck_policies::policies(); let stream_policies = butck_policies::stream_policies(); let mut all_policies: Vec<_> = @@ -20,18 +32,6 @@ pub async fn entry(ctx: ButckContext, args: Vec<String>) -> Result<(), ButckRWEr all_policies.iter().for_each(|p| println!("{}", p)); return Ok(()); } - "simple_policies" => { - butck_policies::policies() - .iter() - .for_each(|p| println!("{}", p)); - return Ok(()); - } - "stream_policies" => { - butck_policies::stream_policies() - .iter() - .for_each(|p| println!("{}", p)); - return Ok(()); - } _ => { print_help(); exit(1) |
