Remove backup option

This commit is contained in:
Andrew 2023-08-05 09:35:22 +12:00
parent 009066daf1
commit 04a6f8df2b
2 changed files with 1 additions and 31 deletions

View file

@ -34,7 +34,7 @@ use log::{debug, info, trace, warn};
use rayon::prelude::*; use rayon::prelude::*;
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt; use std::fmt;
use std::fs::{copy, File, Metadata}; use std::fs::{File, Metadata};
use std::io::{stdin, stdout, BufWriter, Read, Write}; use std::io::{stdin, stdout, BufWriter, Read, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
@ -147,10 +147,6 @@ pub type PngResult<T> = Result<T, PngError>;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
/// Options controlling the output of the `optimize` function /// Options controlling the output of the `optimize` function
pub struct Options { pub struct Options {
/// Whether the input file should be backed up before writing the output.
///
/// Default: `false`
pub backup: bool,
/// Attempt to fix errors when decoding the input file rather than returning an `Err`. /// Attempt to fix errors when decoding the input file rather than returning an `Err`.
/// ///
/// Default: `false` /// Default: `false`
@ -303,7 +299,6 @@ impl Default for Options {
fn default() -> Options { fn default() -> Options {
// Default settings based on -o 2 from the CLI interface // Default settings based on -o 2 from the CLI interface
Options { Options {
backup: false,
fix_errors: false, fix_errors: false,
force: false, force: false,
filter: indexset! {RowFilter::None, RowFilter::Sub, RowFilter::Entropy, RowFilter::Bigrams}, filter: indexset! {RowFilter::None, RowFilter::Sub, RowFilter::Entropy, RowFilter::Bigrams},
@ -506,9 +501,6 @@ pub fn optimize(input: &InFile, output: &OutFile, opts: &Options) -> PngResult<(
.as_ref() .as_ref()
.map(|p| p.as_path()) .map(|p| p.as_path())
.unwrap_or_else(|| input.path().unwrap()); .unwrap_or_else(|| input.path().unwrap());
if opts.backup {
perform_backup(output_path)?;
}
let out_file = File::create(output_path).map_err(|err| { let out_file = File::create(output_path).map_err(|err| {
PngError::new(&format!( PngError::new(&format!(
"Unable to write to file {}: {}", "Unable to write to file {}: {}",
@ -988,19 +980,6 @@ fn is_fully_optimized(original_size: usize, optimized_size: usize, opts: &Option
original_size <= optimized_size && !opts.force original_size <= optimized_size && !opts.force
} }
fn perform_backup(input_path: &Path) -> PngResult<()> {
let backup_file = input_path.with_extension(format!(
"bak.{}",
input_path.extension().unwrap().to_str().unwrap()
));
copy(input_path, &backup_file).map(|_| ()).map_err(|_| {
PngError::new(&format!(
"Unable to write to backup file at {}",
backup_file.display()
))
})
}
#[cfg(not(unix))] #[cfg(not(unix))]
fn copy_permissions(metadata_input: &Metadata, out_file: &File) -> PngResult<()> { fn copy_permissions(metadata_input: &Metadata, out_file: &File) -> PngResult<()> {
let readonly_input = metadata_input.permissions().readonly(); let readonly_input = metadata_input.permissions().readonly();

View file

@ -56,13 +56,6 @@ fn main() {
.value_name("level") .value_name("level")
.value_parser(["0", "1", "2", "3", "4", "5", "6", "max"]), .value_parser(["0", "1", "2", "3", "4", "5", "6", "max"]),
) )
.arg(
Arg::new("backup")
.help("Back up modified files")
.short('b')
.long("backup")
.action(ArgAction::SetTrue),
)
.arg( .arg(
Arg::new("recursive") Arg::new("recursive")
.help("Recurse into subdirectories and optimize all *.png/*.apng files") .help("Recurse into subdirectories and optimize all *.png/*.apng files")
@ -485,8 +478,6 @@ fn parse_opts_into_struct(
opts.fast_evaluation = matches.get_flag("fast"); opts.fast_evaluation = matches.get_flag("fast");
} }
opts.backup = matches.get_flag("backup");
opts.force = matches.get_flag("force"); opts.force = matches.get_flag("force");
opts.fix_errors = matches.get_flag("fix"); opts.fix_errors = matches.get_flag("fix");