this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: default extracted filename for gzip

+64 -2
+11
src/gzip.rs
··· 27 27 "gzip" 28 28 } 29 29 30 + /// Generate a default extracted filename 31 + /// gzip does not support extracting to a directory, so we return a default filename 32 + fn default_extracted_filename(&self, in_path: &std::path::Path) -> String { 33 + // If the file has no extension, return a default filename 34 + if in_path.extension().is_none() { 35 + return "archive".to_string(); 36 + } 37 + // Otherwise, return the filename without the extension 38 + in_path.file_stem().unwrap().to_str().unwrap().to_string() 39 + } 40 + 30 41 fn compress(&self, input: CmprssInput, output: CmprssOutput) -> Result<(), io::Error> { 31 42 if let CmprssOutput::Path(out_path) = &output { 32 43 if out_path.is_dir() {
+3 -1
src/main.rs
··· 222 222 .default_compressed_filename(get_input_filename(&cmprss_input)?), 223 223 )) 224 224 } 225 - Action::Extract => CmprssOutput::Path(PathBuf::from(".")), 225 + Action::Extract => CmprssOutput::Path(PathBuf::from( 226 + compressor.default_extracted_filename(get_input_filename(&cmprss_input)?), 227 + )), 226 228 } 227 229 } 228 230 }
+5
src/utils.rs
··· 23 23 24 24 // Generate the default extracted filename 25 25 fn default_extracted_filename(&self, in_path: &Path) -> String { 26 + // If the file has no extension, return the current directory 27 + if in_path.extension().is_none() { 28 + return ".".to_string(); 29 + } 30 + // Otherwise, return the filename without the extension 26 31 in_path.file_stem().unwrap().to_str().unwrap().to_string() 27 32 } 28 33
+45 -1
tests/cli.rs
··· 1 1 use assert_cmd::prelude::*; 2 2 use assert_fs::prelude::*; 3 3 use predicates::prelude::*; 4 - use std::process::Command; 4 + use std::{ 5 + fs::File, 6 + process::{Command, Stdio}, 7 + }; 5 8 6 9 /// Tar roundtrip with a single file 7 10 /// ··· 172 175 173 176 Ok(()) 174 177 } 178 + 179 + /// Gzip roundtrip using stdin 180 + /// Compressing: input = stdin, output = archive.gz 181 + /// Extracting: input = archive.gz, output = stdout 182 + #[test] 183 + fn gzip_roundtrip_stdin() -> Result<(), Box<dyn std::error::Error>> { 184 + let file = assert_fs::NamedTempFile::new("test.txt")?; 185 + file.write_str("garbage data for testing")?; 186 + let working_dir = assert_fs::TempDir::new()?; 187 + let archive = working_dir.child("test.txt.gz"); 188 + archive.assert(predicate::path::missing()); 189 + 190 + // Pipe file to stdin 191 + let mut compress = Command::cargo_bin("cmprss")?; 192 + compress 193 + .current_dir(&working_dir) 194 + .arg("gzip") 195 + .arg("--compression") 196 + .arg("0") 197 + // TODO: add a flag to ignore just stdout so we can test each side 198 + .arg("test.txt.gz") 199 + .stdin(Stdio::from(File::open(file.path())?)); 200 + compress.assert().success(); 201 + archive.assert(predicate::path::is_file()); 202 + 203 + let mut extract = Command::cargo_bin("cmprss")?; 204 + extract 205 + .current_dir(&working_dir) 206 + .arg("gzip") 207 + .arg("--ignore-pipes") 208 + .arg("--extract") 209 + .arg(archive.path()); 210 + extract.assert().success(); 211 + 212 + // Assert the files are identical 213 + working_dir 214 + .child("test.txt") 215 + .assert(predicate::path::eq_file(file.path())); 216 + 217 + Ok(()) 218 + }