From 2333a847f7e974670e9d1b2576dfd51d029ecbc1 Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Sat, 8 Jun 2024 13:26:45 -0700 Subject: [PATCH] ci(fuzz): Fix inaccuracies in `cargo fuzz fmt` --- fuzz/fuzz_targets/fuzz_write.rs | 14 +++++++------- src/types.rs | 13 ++++++++++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/fuzz/fuzz_targets/fuzz_write.rs b/fuzz/fuzz_targets/fuzz_write.rs index 55779a20..d7670ec7 100755 --- a/fuzz/fuzz_targets/fuzz_write.rs +++ b/fuzz/fuzz_targets/fuzz_write.rs @@ -45,10 +45,11 @@ impl <'k> Debug for FileOperation<'k> { match &self.basic { BasicFileOperation::WriteNormalFile {contents, options} => { f.write_fmt(format_args!("let options = {:?};\n\ - writer.start_file_from_path({:?}, options)?;\n\ - writer.write_all(&({:?}[..] as [u8]))?;\n\ - drop(options);\n", - options, self.path, contents)) + writer.start_file_from_path({:?}, options)?;\n", options, self.path))?; + for content_slice in contents { + f.write_fmt("writer.write_all(&({ : ? }[..] as [u8]))?;\n", content_slice)?; + } + f.write_str("drop(options);\n") }, BasicFileOperation::WriteDirectory(options) => { f.write_fmt(format_args!("let options = {:?};\n\ @@ -73,8 +74,7 @@ impl <'k> Debug for FileOperation<'k> { {{\n\ {:?} }}\n\ - writer.shallow_copy_file_from_path(path, {:?})?;\n\ - drop(path);\n", base.path, base, self.path)) + writer.deep_copy_file_from_path(path, {:?})?;\n", base.path, base, self.path)) }, BasicFileOperation::MergeWithOtherFile {operations} => { f.write_str("let sub_writer = {\n\ @@ -89,7 +89,7 @@ impl <'k> Debug for FileOperation<'k> { }).collect::>()?; f.write_str("writer\n\ };\n\ - writer = sub_writer;\n") + writer.merge_archive(sub_writer.finish_into_readable()?)?;\n") }, }?; match &self.reopen { diff --git a/src/types.rs b/src/types.rs index 25e5df06..db08cc55 100644 --- a/src/types.rs +++ b/src/types.rs @@ -3,6 +3,7 @@ use crate::cp437::FromCp437; use crate::write::{FileOptionExtension, FileOptions}; use path::{Component, Path, PathBuf}; use std::fmt; +use std::fmt::{Debug, Formatter}; use std::mem; use std::path; use std::sync::{Arc, OnceLock}; @@ -77,7 +78,7 @@ impl From for u8 { /// /// Modern zip files store more precise timestamps; see [`crate::extra_fields::ExtendedTimestamp`] /// for details. -#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct DateTime { year: u16, month: u8, @@ -87,6 +88,16 @@ pub struct DateTime { second: u8, } +impl Debug for DateTime { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + if *self == Self::default() { + return f.write_str("DateTime::default()"); + } + f.write_fmt(format_args!("DateTime::from_date_and_time({}, {}, {}, {}, {}, {})?", + self.year, self.month, self.day, self.hour, self.minute, self.second)) + } +} + impl DateTime { /// Returns the current time if possible, otherwise the default of 1980-01-01. #[cfg(feature = "time")]