feat: Fallback to system commands for disabled compression features
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -74,15 +74,24 @@ pub trait CompressionEngine {
|
||||
|
||||
lazy_static! {
|
||||
pub static ref COMPRESSION_PROGRAMS: EnumMap<CompressionType, Option<CompressionEngineProgram>> = enum_map! {
|
||||
CompressionType::LZ4 => None,
|
||||
CompressionType::GZip => None,
|
||||
CompressionType::LZ4 => {
|
||||
let program = CompressionEngineProgram::new("lz4", vec!["-c"], vec!["-d", "-c"]);
|
||||
if program.supported { Some(program) } else { None }
|
||||
},
|
||||
CompressionType::GZip => {
|
||||
let program = CompressionEngineProgram::new("gzip", vec!["-c"], vec!["-d", "-c"]);
|
||||
if program.supported { Some(program) } else { None }
|
||||
},
|
||||
#[cfg(feature = "bzip2")]
|
||||
CompressionType::BZip2 => {
|
||||
let program = CompressionEngineProgram::new("bzip2", vec!["-qcf"], vec!["-dcf"]);
|
||||
if program.supported { Some(program) } else { None }
|
||||
},
|
||||
#[cfg(not(feature = "bzip2"))]
|
||||
CompressionType::BZip2 => None,
|
||||
CompressionType::BZip2 => {
|
||||
let program = CompressionEngineProgram::new("bzip2", vec!["-qcf"], vec!["-dcf"]);
|
||||
if program.supported { Some(program) } else { None }
|
||||
},
|
||||
CompressionType::XZ => {
|
||||
let program = CompressionEngineProgram::new("xz", vec!["-qcf"], vec!["-dcf"]);
|
||||
if program.supported { Some(program) } else { None }
|
||||
@@ -99,14 +108,42 @@ pub fn get_compression_engine(
|
||||
compression_type: CompressionType,
|
||||
) -> Result<Box<dyn CompressionEngine>> {
|
||||
match compression_type {
|
||||
CompressionType::LZ4 => Ok(Box::new(CompressionEngineLZ4::new())),
|
||||
CompressionType::GZip => Ok(Box::new(CompressionEngineGZip::new())),
|
||||
CompressionType::LZ4 => {
|
||||
#[cfg(feature = "lz4")]
|
||||
{
|
||||
Ok(Box::new(CompressionEngineLZ4::new()))
|
||||
}
|
||||
#[cfg(not(feature = "lz4"))]
|
||||
{
|
||||
if let Some(engine) = COMPRESSION_PROGRAMS[compression_type].clone() {
|
||||
Ok(Box::new(engine))
|
||||
} else {
|
||||
Err(anyhow!("LZ4 not available: feature disabled and program not found"))
|
||||
}
|
||||
}
|
||||
},
|
||||
CompressionType::GZip => {
|
||||
#[cfg(feature = "gzip")]
|
||||
{
|
||||
Ok(Box::new(CompressionEngineGZip::new()))
|
||||
}
|
||||
#[cfg(not(feature = "gzip"))]
|
||||
{
|
||||
if let Some(engine) = COMPRESSION_PROGRAMS[compression_type].clone() {
|
||||
Ok(Box::new(engine))
|
||||
} else {
|
||||
Err(anyhow!("GZip not available: feature disabled and program not found"))
|
||||
}
|
||||
}
|
||||
},
|
||||
CompressionType::None => Ok(Box::new(CompressionEngineNone::new())),
|
||||
compression_type => Ok(Box::new(
|
||||
COMPRESSION_PROGRAMS[compression_type.clone()]
|
||||
.clone()
|
||||
.unwrap(),
|
||||
)),
|
||||
compression_type => {
|
||||
if let Some(engine) = COMPRESSION_PROGRAMS[compression_type].clone() {
|
||||
Ok(Box::new(engine))
|
||||
} else {
|
||||
Err(anyhow!("Compression type {:?} not supported", compression_type))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user