refactor: Use PathBuf for local block source config

This commit is contained in:
sprites0
2025-07-04 18:23:08 +00:00
parent d660af0896
commit f6830a67cd
3 changed files with 11 additions and 8 deletions

View File

@ -41,7 +41,7 @@ impl BlockSourceArgs {
if let Some(bucket) = value.strip_prefix("s3://") {
Ok(BlockSourceConfig::s3(bucket.to_string()).await)
} else {
Ok(BlockSourceConfig::local(value.to_string()))
Ok(BlockSourceConfig::local(value.into()))
}
}

View File

@ -1,12 +1,11 @@
use aws_config::BehaviorVersion;
use super::{
consts::DEFAULT_S3_BUCKET,
sources::{
BlockSourceBoxed, CachedBlockSource, HlNodeBlockSource, LocalBlockSource, S3BlockSource,
},
};
use std::{path::PathBuf, sync::Arc};
use aws_config::BehaviorVersion;
use std::{env::home_dir, path::PathBuf, sync::Arc};
#[derive(Debug, Clone)]
pub struct BlockSourceConfig {
@ -17,7 +16,7 @@ pub struct BlockSourceConfig {
#[derive(Debug, Clone)]
pub enum BlockSourceType {
S3 { bucket: String },
Local { path: String },
Local { path: PathBuf },
}
impl BlockSourceConfig {
@ -32,7 +31,7 @@ impl BlockSourceConfig {
Self { source_type: BlockSourceType::S3 { bucket }, block_source_from_node: None }
}
pub fn local(path: String) -> Self {
pub fn local(path: PathBuf) -> Self {
Self { source_type: BlockSourceType::Local { path }, block_source_from_node: None }
}

View File

@ -1,3 +1,5 @@
use std::path::Path;
use crate::pseudo_peer::{prelude::*, BlockSourceType};
#[tokio::test]
@ -10,8 +12,10 @@ async fn test_block_source_config_s3() {
#[tokio::test]
async fn test_block_source_config_local() {
let config = BlockSourceConfig::local("/test/path".to_string());
assert!(matches!(config.source_type, BlockSourceType::Local { path } if path == "/test/path"));
let config = BlockSourceConfig::local("/test/path".into());
assert!(
matches!(config.source_type, BlockSourceType::Local { path } if path == Path::new("/test/path"))
);
}
#[test]