mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
Properly detect if we are compressing a partially compressed file
This commit is contained in:
parent
c89c34a91f
commit
9907ebcf36
@ -163,12 +163,24 @@ pub fn run(command: Command, flags: &oof::Flags) -> crate::Result<()> {
|
|||||||
|
|
||||||
fn compress_files(
|
fn compress_files(
|
||||||
files: Vec<PathBuf>,
|
files: Vec<PathBuf>,
|
||||||
formats: Vec<CompressionFormat>,
|
mut formats: Vec<CompressionFormat>,
|
||||||
output_file: fs::File,
|
output_file: fs::File,
|
||||||
_flags: &oof::Flags,
|
_flags: &oof::Flags,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let file_writer = BufWriter::with_capacity(BUFFER_CAPACITY, output_file);
|
let file_writer = BufWriter::with_capacity(BUFFER_CAPACITY, output_file);
|
||||||
|
|
||||||
|
if files.len() == 1 {
|
||||||
|
// It's possible the file is already partially compressed so we don't want to compress it again
|
||||||
|
// `ouch compress file.tar.gz file.tar.gz.xz` should produce `file.tar.gz.xz` and not `file.tar.gz.tar.gz.xz`
|
||||||
|
let cur_extensions = extension::extensions_from_path(&files[0]);
|
||||||
|
|
||||||
|
// If the input is a subset at the start of `formats` then remove the extensions
|
||||||
|
if cur_extensions.len() < formats.len() && cur_extensions.iter().zip(&formats).all(|(inp, out)| inp == out) {
|
||||||
|
let drain_iter = formats.drain(..cur_extensions.len());
|
||||||
|
drop(drain_iter); // Remove the extensions from `formats`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let [Tar | Tgz | Zip] = *formats.as_slice() {
|
if let [Tar | Tgz | Zip] = *formats.as_slice() {
|
||||||
match formats[0] {
|
match formats[0] {
|
||||||
Tar => {
|
Tar => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user