mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 03:55:28 +00:00
Use the -y and -n flags when decompressing single-file compression formats
This commit is contained in:
parent
1c0e883d99
commit
cb10a45661
@ -3,7 +3,7 @@ use std::{ffi::OsStr, fs, io::Write, path::PathBuf};
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::{Flags, Command, CommandKind},
|
cli::{Command, CommandKind, Flags},
|
||||||
compressors::{
|
compressors::{
|
||||||
BzipCompressor, Compressor, Entry, GzipCompressor, LzmaCompressor, TarCompressor,
|
BzipCompressor, Compressor, Entry, GzipCompressor, LzmaCompressor, TarCompressor,
|
||||||
ZipCompressor,
|
ZipCompressor,
|
||||||
@ -12,8 +12,8 @@ use crate::{
|
|||||||
BzipDecompressor, DecompressionResult, Decompressor, GzipDecompressor, LzmaDecompressor,
|
BzipDecompressor, DecompressionResult, Decompressor, GzipDecompressor, LzmaDecompressor,
|
||||||
TarDecompressor, ZipDecompressor,
|
TarDecompressor, ZipDecompressor,
|
||||||
},
|
},
|
||||||
extension::{CompressionFormat, Extension},
|
|
||||||
dialogs::Confirmation,
|
dialogs::Confirmation,
|
||||||
|
extension::{CompressionFormat, Extension},
|
||||||
file::File,
|
file::File,
|
||||||
utils,
|
utils,
|
||||||
};
|
};
|
||||||
@ -104,7 +104,7 @@ impl Evaluator {
|
|||||||
decompressor: Option<Box<dyn Decompressor>>,
|
decompressor: Option<Box<dyn Decompressor>>,
|
||||||
output_file: &Option<File>,
|
output_file: &Option<File>,
|
||||||
extension: Option<Extension>,
|
extension: Option<Extension>,
|
||||||
flags: Flags
|
flags: Flags,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let output_file_path = utils::get_destination_path(output_file);
|
let output_file_path = utils::get_destination_path(output_file);
|
||||||
|
|
||||||
@ -119,7 +119,6 @@ impl Evaluator {
|
|||||||
}
|
}
|
||||||
let filename = PathBuf::from(filename);
|
let filename = PathBuf::from(filename);
|
||||||
|
|
||||||
|
|
||||||
// If there is a decompressor to use, we'll create a file in-memory and decompress it
|
// If there is a decompressor to use, we'll create a file in-memory and decompress it
|
||||||
let decompressor = match decompressor {
|
let decompressor = match decompressor {
|
||||||
Some(decompressor) => decompressor,
|
Some(decompressor) => decompressor,
|
||||||
@ -127,7 +126,15 @@ impl Evaluator {
|
|||||||
// There is no more processing to be done on the input file (or there is but currently unsupported)
|
// There is no more processing to be done on the input file (or there is but currently unsupported)
|
||||||
// Therefore, we'll save what we have in memory into a file.
|
// Therefore, we'll save what we have in memory into a file.
|
||||||
println!("{}: saving to {:?}.", "info".yellow(), filename);
|
println!("{}: saving to {:?}.", "info".yellow(), filename);
|
||||||
// TODO: use -y and -n flags
|
|
||||||
|
if filename.exists() {
|
||||||
|
let confirm =
|
||||||
|
Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE"));
|
||||||
|
if !utils::permission_for_overwriting(&filename, flags, &confirm)? {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut f = fs::File::create(output_file_path.join(filename))?;
|
let mut f = fs::File::create(output_file_path.join(filename))?;
|
||||||
f.write_all(&bytes)?;
|
f.write_all(&bytes)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@ -162,7 +169,6 @@ impl Evaluator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let bytes = match first_compressor {
|
let bytes = match first_compressor {
|
||||||
Some(first_compressor) => {
|
Some(first_compressor) => {
|
||||||
let mut entry = Entry::Files(files);
|
let mut entry = Entry::Files(files);
|
||||||
@ -207,7 +213,7 @@ impl Evaluator {
|
|||||||
first_decompressor,
|
first_decompressor,
|
||||||
output,
|
output,
|
||||||
extension,
|
extension,
|
||||||
flags
|
flags,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
DecompressionResult::FilesUnpacked(_files) => {
|
DecompressionResult::FilesUnpacked(_files) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user