make filetime optional and make help for -p explicit

This commit is contained in:
moschroe 2020-12-12 20:25:34 +01:00
parent 1d74044536
commit 557bd1520a
3 changed files with 21 additions and 2 deletions

View file

@ -41,7 +41,10 @@ libdeflater = { version = "0.7.1", optional = true }
log = "0.4.11" log = "0.4.11"
stderrlog = { version = "0.5.0", optional = true } stderrlog = { version = "0.5.0", optional = true }
crossbeam-channel = "0.5.0" crossbeam-channel = "0.5.0"
filetime = "0.2.13"
[dependencies.filetime]
optional = true
version = "0.2.13"
[dependencies.rayon] [dependencies.rayon]
optional = true optional = true
@ -73,7 +76,7 @@ binary = [
"wild", "wild",
"stderrlog", "stderrlog",
] ]
default = ["binary", "parallel", "libdeflater", "zopfli"] default = ["binary", "filetime", "parallel", "libdeflater", "zopfli"]
parallel = ["rayon", "indexmap/rayon"] parallel = ["rayon", "indexmap/rayon"]
[lib] [lib]

View file

@ -988,6 +988,10 @@ fn copy_permissions(metadata_input: &Metadata, out_file: &File) {
warn!("Failed to set permissions on output file"); warn!("Failed to set permissions on output file");
} }
#[cfg(not(feature = "filetime"))]
fn copy_times(_: &Metadata, _: &Path) {}
#[cfg(feature = "filetime")]
fn copy_times(input_path_meta: &Metadata, out_path: &Path) { fn copy_times(input_path_meta: &Metadata, out_path: &Path) {
let atime = filetime::FileTime::from_last_access_time(input_path_meta); let atime = filetime::FileTime::from_last_access_time(input_path_meta);
let mtime = filetime::FileTime::from_last_modification_time(input_path_meta); let mtime = filetime::FileTime::from_last_modification_time(input_path_meta);

View file

@ -1,8 +1,10 @@
use indexmap::IndexSet; use indexmap::IndexSet;
use oxipng::internal_tests::*; use oxipng::internal_tests::*;
use oxipng::{InFile, OutFile}; use oxipng::{InFile, OutFile};
#[cfg(feature = "filetime")]
use std::cell::RefCell; use std::cell::RefCell;
use std::fs::remove_file; use std::fs::remove_file;
#[cfg(feature = "filetime")]
use std::ops::Deref; use std::ops::Deref;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
@ -480,12 +482,15 @@ fn interlaced_0_to_1_other_filter_mode() {
fn preserve_attrs() { fn preserve_attrs() {
let input = PathBuf::from("tests/files/preserve_attrs.png"); let input = PathBuf::from("tests/files/preserve_attrs.png");
#[cfg(feature = "filetime")]
let atime_canon = RefCell::new(filetime::FileTime::from_unix_time(0, 0)); let atime_canon = RefCell::new(filetime::FileTime::from_unix_time(0, 0));
#[cfg(feature = "filetime")]
let mtime_canon = RefCell::new(filetime::FileTime::from_unix_time(0, 0)); let mtime_canon = RefCell::new(filetime::FileTime::from_unix_time(0, 0));
let (output, mut opts) = get_opts(&input); let (output, mut opts) = get_opts(&input);
opts.preserve_attrs = true; opts.preserve_attrs = true;
#[cfg(feature = "filetime")]
let callback_pre = |path_in: &Path| { let callback_pre = |path_in: &Path| {
let meta_input = path_in let meta_input = path_in
.metadata() .metadata()
@ -494,7 +499,10 @@ fn preserve_attrs() {
atime_canon.replace(filetime::FileTime::from_last_access_time(&meta_input)); atime_canon.replace(filetime::FileTime::from_last_access_time(&meta_input));
mtime_canon.replace(filetime::FileTime::from_last_modification_time(&meta_input)); mtime_canon.replace(filetime::FileTime::from_last_modification_time(&meta_input));
}; };
#[cfg(not(feature = "filetime"))]
let callback_pre = |_: &Path| {};
#[cfg(feature = "filetime")]
let callback_post = |path_out: &Path| { let callback_post = |path_out: &Path| {
let meta_output = path_out let meta_output = path_out
.metadata() .metadata()
@ -516,6 +524,8 @@ fn preserve_attrs() {
"expected modification time to be identical to that of input", "expected modification time to be identical to that of input",
); );
}; };
#[cfg(not(feature = "filetime"))]
let callback_post = |_: &Path| {};
test_it_converts_callbacks( test_it_converts_callbacks(
input, input,
@ -528,6 +538,8 @@ fn preserve_attrs() {
callback_pre, callback_pre,
callback_post, callback_post,
); );
// TODO: Actually check permissions
} }
#[test] #[test]