diff --git a/Cargo.toml b/Cargo.toml index a6996fc6..fdeb9e76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ hmac = { version = "0.12.1", optional = true, features = ["reset"] } pbkdf2 = {version = "0.11.0", optional = true } sha1 = {version = "0.10.1", optional = true } time = { version = "0.3.7", features = ["formatting", "macros" ], optional = true } -zstd = { version = "0.11.0", optional = true } +zstd = { version = "0.11.2", optional = true } [target.'cfg(any(all(target_arch = "arm", target_pointer_width = "32"), target_arch = "mips", target_arch = "powerpc"))'.dependencies] crossbeam-utils = "0.8.8" diff --git a/examples/extract.rs b/examples/extract.rs index 7b8860ca..3519ebaf 100644 --- a/examples/extract.rs +++ b/examples/extract.rs @@ -42,7 +42,7 @@ fn real_main() -> i32 { ); if let Some(p) = outpath.parent() { if !p.exists() { - fs::create_dir_all(&p).unwrap(); + fs::create_dir_all(p).unwrap(); } } let mut outfile = fs::File::create(&outpath).unwrap(); diff --git a/examples/extract_lorem.rs b/examples/extract_lorem.rs index a34a04f4..4b3773a0 100644 --- a/examples/extract_lorem.rs +++ b/examples/extract_lorem.rs @@ -11,7 +11,7 @@ fn real_main() -> i32 { return 1; } let fname = std::path::Path::new(&*args[1]); - let zipfile = std::fs::File::open(&fname).unwrap(); + let zipfile = std::fs::File::open(fname).unwrap(); let mut archive = zip::ZipArchive::new(zipfile).unwrap(); diff --git a/examples/file_info.rs b/examples/file_info.rs index 64969b66..0513c3a3 100644 --- a/examples/file_info.rs +++ b/examples/file_info.rs @@ -12,7 +12,7 @@ fn real_main() -> i32 { return 1; } let fname = std::path::Path::new(&*args[1]); - let file = fs::File::open(&fname).unwrap(); + let file = fs::File::open(fname).unwrap(); let reader = BufReader::new(file); let mut archive = zip::ZipArchive::new(reader).unwrap(); diff --git a/examples/write_dir.rs b/examples/write_dir.rs index 8cc561ff..20e599c1 100644 --- a/examples/write_dir.rs +++ b/examples/write_dir.rs @@ -114,7 +114,7 @@ fn doit( } let path = Path::new(dst_file); - let file = File::create(&path).unwrap(); + let file = File::create(path).unwrap(); let walkdir = WalkDir::new(src_dir); let it = walkdir.into_iter(); diff --git a/examples/write_sample.rs b/examples/write_sample.rs index b5749509..97a5515b 100644 --- a/examples/write_sample.rs +++ b/examples/write_sample.rs @@ -23,7 +23,7 @@ fn real_main() -> i32 { fn doit(filename: &str) -> zip::result::ZipResult<()> { let path = std::path::Path::new(filename); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let mut zip = zip::ZipWriter::new(file); diff --git a/src/read.rs b/src/read.rs index 0addf416..bdfbb0c3 100644 --- a/src/read.rs +++ b/src/read.rs @@ -448,21 +448,24 @@ impl ZipArchive { pub fn extract>(&mut self, directory: P) -> ZipResult<()> { use std::fs; - fn inner(file: &mut ZipFile<'_>, directory: &Path) -> ZipResult<()> { + for i in 0..self.len() { + let mut file = self.by_index(i)?; let filepath = file .enclosed_name() .ok_or(ZipError::InvalidArchive("Invalid file path"))?; - let outpath = directory.join(filepath); + let outpath = directory.as_ref().join(filepath); if file.name().ends_with('/') { fs::create_dir_all(&outpath)?; } else { if let Some(p) = outpath.parent() { - fs::create_dir_all(&p)?; + if !p.exists() { + fs::create_dir_all(p)?; + } } let mut outfile = fs::File::create(&outpath)?; - io::copy(file, &mut outfile)?; + io::copy(&mut file, &mut outfile)?; } // Get and Set permissions #[cfg(unix)] @@ -472,15 +475,7 @@ impl ZipArchive { fs::set_permissions(&outpath, fs::Permissions::from_mode(mode))?; } } - Ok(()) } - - for i in 0..self.len() { - let mut file = self.by_index(i)?; - - inner(&mut file, directory.as_ref())?; - } - Ok(()) } @@ -686,11 +681,11 @@ pub(crate) fn central_header_to_zip_file( reader.read_exact(&mut file_comment_raw)?; let file_name = match is_utf8 { - true => String::from_utf8_lossy(&*file_name_raw).into_owned(), + true => String::from_utf8_lossy(&file_name_raw).into_owned(), false => file_name_raw.clone().from_cp437(), }; let file_comment = match is_utf8 { - true => String::from_utf8_lossy(&*file_comment_raw).into_owned(), + true => String::from_utf8_lossy(&file_comment_raw).into_owned(), false => file_comment_raw.from_cp437(), }; @@ -1090,7 +1085,7 @@ pub fn read_zipfile_from_stream<'a, R: io::Read>( reader.read_exact(&mut extra_field)?; let file_name = match is_utf8 { - true => String::from_utf8_lossy(&*file_name_raw).into_owned(), + true => String::from_utf8_lossy(&file_name_raw).into_owned(), false => file_name_raw.clone().from_cp437(), }; @@ -1134,7 +1129,7 @@ pub fn read_zipfile_from_stream<'a, R: io::Read>( return unsupported_zip_error("The file length is not available in the local header"); } - let limit_reader = (reader as &'a mut dyn io::Read).take(result.compressed_size as u64); + let limit_reader = (reader as &'a mut dyn io::Read).take(result.compressed_size); let result_crc32 = result.crc32; let result_compression_method = result.compression_method; diff --git a/src/spec.rs b/src/spec.rs index 3ffcf732..2ed051b1 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -64,12 +64,12 @@ impl CentralDirectoryEnd { let mut pos = file_length - HEADER_SIZE; while pos >= search_upper_bound { - reader.seek(io::SeekFrom::Start(pos as u64))?; + reader.seek(io::SeekFrom::Start(pos))?; if reader.read_u32::()? == CENTRAL_DIRECTORY_END_SIGNATURE { reader.seek(io::SeekFrom::Current( BYTES_BETWEEN_MAGIC_AND_COMMENT_SIZE as i64, ))?; - let cde_start_pos = reader.seek(io::SeekFrom::Start(pos as u64))?; + let cde_start_pos = reader.seek(io::SeekFrom::Start(pos))?; return CentralDirectoryEnd::parse(reader).map(|cde| (cde, cde_start_pos)); } pos = match pos.checked_sub(1) { diff --git a/src/types.rs b/src/types.rs index b65fad40..da4a42e3 100644 --- a/src/types.rs +++ b/src/types.rs @@ -44,7 +44,7 @@ mod atomic { #[cfg(feature = "time")] use time::{error::ComponentRange, Date, Month, OffsetDateTime, PrimitiveDateTime, Time}; -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum System { Dos = 0, Unix = 3, @@ -115,7 +115,7 @@ impl DateTime { let years = (datepart & 0b1111111000000000) >> 9; DateTime { - year: (years + 1980) as u16, + year: years + 1980, month: months as u8, day: days as u8, hour: hours as u8, @@ -143,10 +143,8 @@ impl DateTime { second: u8, ) -> Result { if (1980..=2107).contains(&year) - && month >= 1 - && month <= 12 - && day >= 1 - && day <= 31 + && (1..=12).contains(&month) + && (1..=31).contains(&day) && hour <= 23 && minute <= 59 && second <= 60 @@ -174,10 +172,10 @@ impl DateTime { Ok(DateTime { year: (dt.year()) as u16, month: (dt.month()) as u8, - day: dt.day() as u8, - hour: dt.hour() as u8, - minute: dt.minute() as u8, - second: dt.second() as u8, + day: dt.day(), + hour: dt.hour(), + minute: dt.minute(), + second: dt.second(), }) } else { Err(()) diff --git a/src/write.rs b/src/write.rs index 61ce378c..e43cc85f 100644 --- a/src/write.rs +++ b/src/write.rs @@ -1301,7 +1301,7 @@ fn path_to_string(path: &std::path::Path) -> String { if !path_str.is_empty() { path_str.push('/'); } - path_str.push_str(&*os_str.to_string_lossy()); + path_str.push_str(&os_str.to_string_lossy()); } } path_str