Skip to content

Commit

Permalink
Merge pull request #300 from figsoda/remove-progress
Browse files Browse the repository at this point in the history
Remove progress feature
  • Loading branch information
marcospb19 authored Oct 16, 2022
2 parents f610ff5 + ad50bcc commit fc5205c
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 336 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Categories Used:
### Regression

- Remove automatic detection for partial compression [\#286](https://github.com/ouch-org/ouch/pull/286) ([marcospb19](https://github.com/marcospb19))
- Remove progress feature [\#300](https://github.com/ouch-org/ouch/pull/300) ([figsoda](https://github.com/figsoda))

### New Contributors

Expand Down
54 changes: 0 additions & 54 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@ description = "A command-line utility for easily compressing and decompressing f
atty = "0.2.14"
bzip2 = "0.4.3"
clap = { version = "4.0.13", features = ["derive", "env"] }
filetime = "0.2.17"
flate2 = { version = "1.0.24", default-features = false }
fs-err = "2.8.1"
humansize = "2.1.0"
ignore = "0.4.18"
libc = "0.2.135"
linked-hash-map = "0.5.6"
lzzzz = "1.0.3"
once_cell = "1.15.0"
same-file = "1.0.6"
snap = "1.0.5"
tar = "0.4.38"
tempfile = "3.3.0"
xz2 = "0.1.7"
zip = { version = "0.6.2", default-features = false, features = ["time"] }
zstd = { version = "0.11.2", default-features = false }
tempfile = "3.3.0"
ignore = "0.4.18"
indicatif = "0.17.1"
filetime = "0.2.17"

[target.'cfg(unix)'.dependencies]
time = { version = "0.3.15", default-features = false }
Expand Down
1 change: 0 additions & 1 deletion src/accessible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use once_cell::sync::OnceCell;

/// Whether to enable accessible output (removes info output and reduces other
/// output, removes visual markers like '[' and ']').
/// Removes th progress bar as well
pub static ACCESSIBLE: OnceCell<bool> = OnceCell::new();

pub fn is_running_in_accessible_mode() -> bool {
Expand Down
15 changes: 3 additions & 12 deletions src/archive/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ use crate::{
error::FinalError,
info,
list::FileInArchive,
progress::OutputLine,
utils::{self, FileVisibilityPolicy},
warning,
};

/// Unpacks the archive given by `archive` into the folder given by `into`.
/// Assumes that output_folder is empty
pub fn unpack_archive(
reader: Box<dyn Read>,
output_folder: &Path,
mut log_out: impl OutputLine,
) -> crate::Result<Vec<PathBuf>> {
pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path) -> crate::Result<Vec<PathBuf>> {
assert!(output_folder.read_dir().expect("dir exists").count() == 0);
let mut archive = tar::Archive::new(reader);

Expand All @@ -44,7 +39,6 @@ pub fn unpack_archive(
// and so on

info!(
@log_out,
inaccessible,
"{:?} extracted. ({})",
utils::strip_cur_dir(&output_folder.join(file.path()?)),
Expand Down Expand Up @@ -87,16 +81,14 @@ pub fn list_archive(
}

/// Compresses the archives given by `input_filenames` into the file given previously to `writer`.
pub fn build_archive_from_paths<W, D>(
pub fn build_archive_from_paths<W>(
input_filenames: &[PathBuf],
output_path: &Path,
writer: W,
file_visibility_policy: FileVisibilityPolicy,
mut log_out: D,
) -> crate::Result<W>
where
W: Write,
D: OutputLine,
{
let mut builder = tar::Builder::new(writer);
let output_handle = Handle::from_path(output_path);
Expand All @@ -115,7 +107,6 @@ where
if let Ok(ref handle) = output_handle {
if matches!(Handle::from_path(path), Ok(x) if &x == handle) {
warning!(
@log_out,
"The output file and the input file are the same: `{}`, skipping...",
output_path.display()
);
Expand All @@ -127,7 +118,7 @@ where
// little importance for most users, but would generate lots of
// spoken text for users using screen readers, braille displays
// and so on
info!(@log_out, inaccessible, "Compressing '{}'.", utils::to_utf(path));
info!(inaccessible, "Compressing '{}'.", utils::to_utf(path));

if path.is_dir() {
builder.append_dir(path, path)?;
Expand Down
18 changes: 4 additions & 14 deletions src/archive/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::{
error::FinalError,
info,
list::FileInArchive,
progress::OutputLine,
utils::{
self, cd_into_same_dir_as, get_invalid_utf8_paths, pretty_format_list_of_paths, strip_cur_dir, to_utf,
FileVisibilityPolicy,
Expand All @@ -30,14 +29,9 @@ use crate::{

/// Unpacks the archive given by `archive` into the folder given by `output_folder`.
/// Assumes that output_folder is empty
pub fn unpack_archive<R, D>(
mut archive: ZipArchive<R>,
output_folder: &Path,
mut log_out: D,
) -> crate::Result<Vec<PathBuf>>
pub fn unpack_archive<R>(mut archive: ZipArchive<R>, output_folder: &Path) -> crate::Result<Vec<PathBuf>>
where
R: Read + Seek,
D: OutputLine,
{
assert!(output_folder.read_dir().expect("dir exists").count() == 0);

Expand All @@ -60,7 +54,7 @@ where
// importance for most users, but would generate lots of
// spoken text for users using screen readers, braille displays
// and so on
info!(@log_out, inaccessible, "File {} extracted to \"{}\"", idx, file_path.display());
info!(inaccessible, "File {} extracted to \"{}\"", idx, file_path.display());
fs::create_dir_all(&file_path)?;
}
_is_file @ false => {
Expand All @@ -73,7 +67,6 @@ where

// same reason is in _is_dir: long, often not needed text
info!(
@log_out,
inaccessible,
"{:?} extracted. ({})",
file_path.display(),
Expand Down Expand Up @@ -137,16 +130,14 @@ where
}

/// Compresses the archives given by `input_filenames` into the file given previously to `writer`.
pub fn build_archive_from_paths<W, D>(
pub fn build_archive_from_paths<W>(
input_filenames: &[PathBuf],
output_path: &Path,
writer: W,
file_visibility_policy: FileVisibilityPolicy,
mut log_out: D,
) -> crate::Result<W>
where
W: Write + Seek,
D: OutputLine,
{
let mut writer = zip::ZipWriter::new(writer);
let options = zip::write::FileOptions::default();
Expand Down Expand Up @@ -183,7 +174,6 @@ where
if let Ok(ref handle) = output_handle {
if matches!(Handle::from_path(path), Ok(x) if &x == handle) {
warning!(
@log_out,
"The output file and the input file are the same: `{}`, skipping...",
output_path.display()
);
Expand All @@ -195,7 +185,7 @@ where
// little importance for most users, but would generate lots of
// spoken text for users using screen readers, braille displays
// and so on
info!(@log_out, inaccessible, "Compressing '{}'.", to_utf(path));
info!(inaccessible, "Compressing '{}'.", to_utf(path));

let metadata = match path.metadata() {
Ok(metadata) => metadata,
Expand Down
67 changes: 6 additions & 61 deletions src/commands/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ use std::{
use fs_err as fs;

use crate::{
accessible::is_running_in_accessible_mode,
archive,
commands::warn_user_about_loading_zip_in_memory,
extension::{
split_first_compression_format,
CompressionFormat::{self, *},
Extension,
},
progress::Progress,
utils::{user_wants_to_continue, FileVisibilityPolicy},
QuestionAction, QuestionPolicy, BUFFER_CAPACITY,
};
Expand All @@ -37,15 +35,7 @@ pub fn compress_files(
question_policy: QuestionPolicy,
file_visibility_policy: FileVisibilityPolicy,
) -> crate::Result<bool> {
// The next lines are for displaying the progress bar
// If the input files contain a directory, then the total size will be underestimated
let (total_input_size, precise) = files
.iter()
.map(|f| (f.metadata().expect("file exists").len(), f.is_file()))
.fold((0, true), |(total_size, and_precise), (size, precise)| {
(total_size + size, and_precise & precise)
});

let file_writer = BufWriter::with_capacity(BUFFER_CAPACITY, output_file);

let mut writer: Box<dyn Write> = Box::new(file_writer);
Expand Down Expand Up @@ -81,37 +71,11 @@ pub fn compress_files(
writer = chain_writer_encoder(&first_format, writer)?;
let mut reader = fs::File::open(&files[0]).unwrap();

if is_running_in_accessible_mode() {
io::copy(&mut reader, &mut writer)?;
} else {
io::copy(
&mut Progress::new(total_input_size, precise, true).wrap_read(reader),
&mut writer,
)?;
}
io::copy(&mut reader, &mut writer)?;
}
Tar => {
if is_running_in_accessible_mode() {
archive::tar::build_archive_from_paths(
&files,
output_path,
&mut writer,
file_visibility_policy,
io::stderr(),
)?;
writer.flush()?;
} else {
let mut progress = Progress::new(total_input_size, precise, true);
let mut writer = progress.wrap_write(writer);
archive::tar::build_archive_from_paths(
&files,
output_path,
&mut writer,
file_visibility_policy,
&mut progress,
)?;
writer.flush()?;
}
archive::tar::build_archive_from_paths(&files, output_path, &mut writer, file_visibility_policy)?;
writer.flush()?;
}
Zip => {
if !formats.is_empty() {
Expand All @@ -124,28 +88,9 @@ pub fn compress_files(

let mut vec_buffer = Cursor::new(vec![]);

if is_running_in_accessible_mode() {
archive::zip::build_archive_from_paths(
&files,
output_path,
&mut vec_buffer,
file_visibility_policy,
io::stderr(),
)?;
vec_buffer.rewind()?;
io::copy(&mut vec_buffer, &mut writer)?;
} else {
let mut progress = Progress::new(total_input_size, precise, true);
archive::zip::build_archive_from_paths(
&files,
output_path,
&mut vec_buffer,
file_visibility_policy,
&mut progress,
)?;
vec_buffer.rewind()?;
io::copy(&mut progress.wrap_read(vec_buffer), &mut writer)?;
}
archive::zip::build_archive_from_paths(&files, output_path, &mut vec_buffer, file_visibility_policy)?;
vec_buffer.rewind()?;
io::copy(&mut vec_buffer, &mut writer)?;
}
}

Expand Down
Loading

0 comments on commit fc5205c

Please sign in to comment.