mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 03:55:28 +00:00
decompressors/tar: Add confirmation dialog for file overwriting
This commit is contained in:
parent
7954eb07fd
commit
03d6fc1e60
@ -8,7 +8,7 @@ use colored::Colorize;
|
|||||||
use tar::{self, Archive};
|
use tar::{self, Archive};
|
||||||
|
|
||||||
use super::decompressor::{DecompressionResult, Decompressor};
|
use super::decompressor::{DecompressionResult, Decompressor};
|
||||||
use crate::{file::File, utils};
|
use crate::{file::File, utils, dialogs::Confirmation};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TarDecompressor {}
|
pub struct TarDecompressor {}
|
||||||
@ -21,6 +21,7 @@ impl TarDecompressor {
|
|||||||
&from.path
|
&from.path
|
||||||
);
|
);
|
||||||
let mut files_unpacked = vec![];
|
let mut files_unpacked = vec![];
|
||||||
|
let confirm = Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE"));
|
||||||
|
|
||||||
let mut archive: Archive<Box<dyn Read>> = match from.contents_in_memory {
|
let mut archive: Archive<Box<dyn Read>> = match from.contents_in_memory {
|
||||||
Some(bytes) => tar::Archive::new(Box::new(Cursor::new(bytes))),
|
Some(bytes) => tar::Archive::new(Box::new(Cursor::new(bytes))),
|
||||||
@ -32,8 +33,15 @@ impl TarDecompressor {
|
|||||||
|
|
||||||
for file in archive.entries()? {
|
for file in archive.entries()? {
|
||||||
let mut file = file?;
|
let mut file = file?;
|
||||||
|
|
||||||
// TODO: check if file/folder already exists and ask user's permission for overwriting
|
let file_path = PathBuf::from(into).join(file.path()?);
|
||||||
|
if file_path.exists() {
|
||||||
|
let file_path_str = &*file_path.to_string_lossy();
|
||||||
|
if confirm.ask(Some(file_path_str))? {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
file.unpack_in(into)?;
|
file.unpack_in(into)?;
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user