Merge pull request #322 from wyatt-herkamp/master
Clippy Warnings Patch
This commit is contained in:
commit
f6357c5993
10 changed files with 28 additions and 35 deletions
|
@ -21,7 +21,7 @@ hmac = { version = "0.12.1", optional = true, features = ["reset"] }
|
||||||
pbkdf2 = {version = "0.11.0", optional = true }
|
pbkdf2 = {version = "0.11.0", optional = true }
|
||||||
sha1 = {version = "0.10.1", optional = true }
|
sha1 = {version = "0.10.1", optional = true }
|
||||||
time = { version = "0.3.7", features = ["formatting", "macros" ], 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]
|
[target.'cfg(any(all(target_arch = "arm", target_pointer_width = "32"), target_arch = "mips", target_arch = "powerpc"))'.dependencies]
|
||||||
crossbeam-utils = "0.8.8"
|
crossbeam-utils = "0.8.8"
|
||||||
|
|
|
@ -42,7 +42,7 @@ fn real_main() -> i32 {
|
||||||
);
|
);
|
||||||
if let Some(p) = outpath.parent() {
|
if let Some(p) = outpath.parent() {
|
||||||
if !p.exists() {
|
if !p.exists() {
|
||||||
fs::create_dir_all(&p).unwrap();
|
fs::create_dir_all(p).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut outfile = fs::File::create(&outpath).unwrap();
|
let mut outfile = fs::File::create(&outpath).unwrap();
|
||||||
|
|
|
@ -11,7 +11,7 @@ fn real_main() -> i32 {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
let fname = std::path::Path::new(&*args[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();
|
let mut archive = zip::ZipArchive::new(zipfile).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ fn real_main() -> i32 {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
let fname = std::path::Path::new(&*args[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 reader = BufReader::new(file);
|
||||||
|
|
||||||
let mut archive = zip::ZipArchive::new(reader).unwrap();
|
let mut archive = zip::ZipArchive::new(reader).unwrap();
|
||||||
|
|
|
@ -114,7 +114,7 @@ fn doit(
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = Path::new(dst_file);
|
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 walkdir = WalkDir::new(src_dir);
|
||||||
let it = walkdir.into_iter();
|
let it = walkdir.into_iter();
|
||||||
|
|
|
@ -23,7 +23,7 @@ fn real_main() -> i32 {
|
||||||
|
|
||||||
fn doit(filename: &str) -> zip::result::ZipResult<()> {
|
fn doit(filename: &str) -> zip::result::ZipResult<()> {
|
||||||
let path = std::path::Path::new(filename);
|
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);
|
let mut zip = zip::ZipWriter::new(file);
|
||||||
|
|
||||||
|
|
27
src/read.rs
27
src/read.rs
|
@ -448,21 +448,24 @@ impl<R: Read + io::Seek> ZipArchive<R> {
|
||||||
pub fn extract<P: AsRef<Path>>(&mut self, directory: P) -> ZipResult<()> {
|
pub fn extract<P: AsRef<Path>>(&mut self, directory: P) -> ZipResult<()> {
|
||||||
use std::fs;
|
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
|
let filepath = file
|
||||||
.enclosed_name()
|
.enclosed_name()
|
||||||
.ok_or(ZipError::InvalidArchive("Invalid file path"))?;
|
.ok_or(ZipError::InvalidArchive("Invalid file path"))?;
|
||||||
|
|
||||||
let outpath = directory.join(filepath);
|
let outpath = directory.as_ref().join(filepath);
|
||||||
|
|
||||||
if file.name().ends_with('/') {
|
if file.name().ends_with('/') {
|
||||||
fs::create_dir_all(&outpath)?;
|
fs::create_dir_all(&outpath)?;
|
||||||
} else {
|
} else {
|
||||||
if let Some(p) = outpath.parent() {
|
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)?;
|
let mut outfile = fs::File::create(&outpath)?;
|
||||||
io::copy(file, &mut outfile)?;
|
io::copy(&mut file, &mut outfile)?;
|
||||||
}
|
}
|
||||||
// Get and Set permissions
|
// Get and Set permissions
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -472,15 +475,7 @@ impl<R: Read + io::Seek> ZipArchive<R> {
|
||||||
fs::set_permissions(&outpath, fs::Permissions::from_mode(mode))?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,11 +681,11 @@ pub(crate) fn central_header_to_zip_file<R: Read + io::Seek>(
|
||||||
reader.read_exact(&mut file_comment_raw)?;
|
reader.read_exact(&mut file_comment_raw)?;
|
||||||
|
|
||||||
let file_name = match is_utf8 {
|
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(),
|
false => file_name_raw.clone().from_cp437(),
|
||||||
};
|
};
|
||||||
let file_comment = match is_utf8 {
|
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(),
|
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)?;
|
reader.read_exact(&mut extra_field)?;
|
||||||
|
|
||||||
let file_name = match is_utf8 {
|
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(),
|
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");
|
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_crc32 = result.crc32;
|
||||||
let result_compression_method = result.compression_method;
|
let result_compression_method = result.compression_method;
|
||||||
|
|
|
@ -64,12 +64,12 @@ impl CentralDirectoryEnd {
|
||||||
|
|
||||||
let mut pos = file_length - HEADER_SIZE;
|
let mut pos = file_length - HEADER_SIZE;
|
||||||
while pos >= search_upper_bound {
|
while pos >= search_upper_bound {
|
||||||
reader.seek(io::SeekFrom::Start(pos as u64))?;
|
reader.seek(io::SeekFrom::Start(pos))?;
|
||||||
if reader.read_u32::<LittleEndian>()? == CENTRAL_DIRECTORY_END_SIGNATURE {
|
if reader.read_u32::<LittleEndian>()? == CENTRAL_DIRECTORY_END_SIGNATURE {
|
||||||
reader.seek(io::SeekFrom::Current(
|
reader.seek(io::SeekFrom::Current(
|
||||||
BYTES_BETWEEN_MAGIC_AND_COMMENT_SIZE as i64,
|
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));
|
return CentralDirectoryEnd::parse(reader).map(|cde| (cde, cde_start_pos));
|
||||||
}
|
}
|
||||||
pos = match pos.checked_sub(1) {
|
pos = match pos.checked_sub(1) {
|
||||||
|
|
18
src/types.rs
18
src/types.rs
|
@ -44,7 +44,7 @@ mod atomic {
|
||||||
#[cfg(feature = "time")]
|
#[cfg(feature = "time")]
|
||||||
use time::{error::ComponentRange, Date, Month, OffsetDateTime, PrimitiveDateTime, Time};
|
use time::{error::ComponentRange, Date, Month, OffsetDateTime, PrimitiveDateTime, Time};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum System {
|
pub enum System {
|
||||||
Dos = 0,
|
Dos = 0,
|
||||||
Unix = 3,
|
Unix = 3,
|
||||||
|
@ -115,7 +115,7 @@ impl DateTime {
|
||||||
let years = (datepart & 0b1111111000000000) >> 9;
|
let years = (datepart & 0b1111111000000000) >> 9;
|
||||||
|
|
||||||
DateTime {
|
DateTime {
|
||||||
year: (years + 1980) as u16,
|
year: years + 1980,
|
||||||
month: months as u8,
|
month: months as u8,
|
||||||
day: days as u8,
|
day: days as u8,
|
||||||
hour: hours as u8,
|
hour: hours as u8,
|
||||||
|
@ -143,10 +143,8 @@ impl DateTime {
|
||||||
second: u8,
|
second: u8,
|
||||||
) -> Result<DateTime, ()> {
|
) -> Result<DateTime, ()> {
|
||||||
if (1980..=2107).contains(&year)
|
if (1980..=2107).contains(&year)
|
||||||
&& month >= 1
|
&& (1..=12).contains(&month)
|
||||||
&& month <= 12
|
&& (1..=31).contains(&day)
|
||||||
&& day >= 1
|
|
||||||
&& day <= 31
|
|
||||||
&& hour <= 23
|
&& hour <= 23
|
||||||
&& minute <= 59
|
&& minute <= 59
|
||||||
&& second <= 60
|
&& second <= 60
|
||||||
|
@ -174,10 +172,10 @@ impl DateTime {
|
||||||
Ok(DateTime {
|
Ok(DateTime {
|
||||||
year: (dt.year()) as u16,
|
year: (dt.year()) as u16,
|
||||||
month: (dt.month()) as u8,
|
month: (dt.month()) as u8,
|
||||||
day: dt.day() as u8,
|
day: dt.day(),
|
||||||
hour: dt.hour() as u8,
|
hour: dt.hour(),
|
||||||
minute: dt.minute() as u8,
|
minute: dt.minute(),
|
||||||
second: dt.second() as u8,
|
second: dt.second(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(())
|
Err(())
|
||||||
|
|
|
@ -1301,7 +1301,7 @@ fn path_to_string(path: &std::path::Path) -> String {
|
||||||
if !path_str.is_empty() {
|
if !path_str.is_empty() {
|
||||||
path_str.push('/');
|
path_str.push('/');
|
||||||
}
|
}
|
||||||
path_str.push_str(&*os_str.to_string_lossy());
|
path_str.push_str(&os_str.to_string_lossy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
path_str
|
path_str
|
||||||
|
|
Loading…
Add table
Reference in a new issue