From 04a6f8df2b44ea35cba7883a7852e049d1e4080b Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 5 Aug 2023 09:35:22 +1200 Subject: [PATCH] Remove backup option --- src/lib.rs | 23 +---------------------- src/main.rs | 9 --------- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ec669dad..2530c310 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,7 @@ use log::{debug, info, trace, warn}; use rayon::prelude::*; use std::borrow::Cow; use std::fmt; -use std::fs::{copy, File, Metadata}; +use std::fs::{File, Metadata}; use std::io::{stdin, stdout, BufWriter, Read, Write}; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicBool, Ordering}; @@ -147,10 +147,6 @@ pub type PngResult = Result; #[derive(Clone, Debug)] /// Options controlling the output of the `optimize` function 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`. /// /// Default: `false` @@ -303,7 +299,6 @@ impl Default for Options { fn default() -> Options { // Default settings based on -o 2 from the CLI interface Options { - backup: false, fix_errors: false, force: false, 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() .map(|p| p.as_path()) .unwrap_or_else(|| input.path().unwrap()); - if opts.backup { - perform_backup(output_path)?; - } let out_file = File::create(output_path).map_err(|err| { PngError::new(&format!( "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 } -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))] fn copy_permissions(metadata_input: &Metadata, out_file: &File) -> PngResult<()> { let readonly_input = metadata_input.permissions().readonly(); diff --git a/src/main.rs b/src/main.rs index 5c865d8e..f8d2e31b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,13 +56,6 @@ fn main() { .value_name("level") .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::new("recursive") .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.backup = matches.get_flag("backup"); - opts.force = matches.get_flag("force"); opts.fix_errors = matches.get_flag("fix");