diff --git a/examples/extract_file.rs b/examples/extract_file.rs index ee9fad1..92a1c82 100644 --- a/examples/extract_file.rs +++ b/examples/extract_file.rs @@ -6,16 +6,18 @@ extern crate async_tar; -use async_std::io::{copy, stdin, stdout}; -use async_std::path::Path; -use async_std::prelude::*; +use async_std::{ + io::{copy, stdin, stdout}, + path::Path, + prelude::*, +}; use std::env::args_os; use async_tar::Archive; fn main() { async_std::task::block_on(async { - let first_arg = args_os().skip(1).next().unwrap(); + let first_arg = args_os().nth(1).unwrap(); let filename = Path::new(&first_arg); let mut ar = Archive::new(stdin()); let mut entries = ar.entries().unwrap(); diff --git a/examples/list.rs b/examples/list.rs index 606d640..f90b545 100644 --- a/examples/list.rs +++ b/examples/list.rs @@ -4,8 +4,7 @@ extern crate async_tar; -use async_std::io::stdin; -use async_std::prelude::*; +use async_std::{io::stdin, prelude::*}; use async_tar::Archive; diff --git a/examples/raw_list.rs b/examples/raw_list.rs index c027376..9ae3c4d 100644 --- a/examples/raw_list.rs +++ b/examples/raw_list.rs @@ -4,8 +4,7 @@ extern crate async_tar; -use async_std::io::stdin; -use async_std::prelude::*; +use async_std::{io::stdin, prelude::*}; use async_tar::Archive; diff --git a/src/archive.rs b/src/archive.rs index 66d7921..c7d2e87 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -1,22 +1,27 @@ -use std::cell::{Cell, RefCell}; -use std::cmp; -use std::pin::Pin; - -use async_std::io; -use async_std::io::prelude::*; -use async_std::path::Path; -use async_std::prelude::*; -use async_std::stream::Stream; -use async_std::sync::Arc; -use async_std::task::{Context, Poll}; +use std::{ + cell::{Cell, RefCell}, + cmp, + pin::Pin, +}; + +use async_std::{ + io, + io::prelude::*, + path::Path, + prelude::*, + stream::Stream, + sync::Arc, + task::{Context, Poll}, +}; use pin_project::pin_project; use crate::pin_cell::PinCell; -use crate::entry::{EntryFields, EntryIo}; -use crate::error::TarError; -use crate::other; -use crate::{Entry, GnuExtSparseHeader, GnuSparseHeader, Header}; +use crate::{ + entry::{EntryFields, EntryIo}, + error::TarError, + other, Entry, GnuExtSparseHeader, GnuSparseHeader, Header, +}; /// A top-level representation of an archive file. /// @@ -400,11 +405,11 @@ fn poll_next_raw( let data = EntryIo::Data(archive.clone().take(size)); let ret = EntryFields { - size: size, - header_pos: header_pos, - file_pos: file_pos, + size, + header_pos, + file_pos, data: vec![data], - header: header, + header, long_pathname: None, long_linkname: None, pax_extensions: None, diff --git a/src/builder.rs b/src/builder.rs index 88d114d..c6e9916 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,12 +1,16 @@ use std::borrow::Cow; -use async_std::fs; -use async_std::io::{self, Read, Write}; -use async_std::path::Path; -use async_std::prelude::*; - -use crate::header::{bytes2path, path2bytes, HeaderMode}; -use crate::{other, EntryType, Header}; +use async_std::{ + fs, + io::{self, Read, Write}, + path::Path, + prelude::*, +}; + +use crate::{ + header::{bytes2path, path2bytes, HeaderMode}, + other, EntryType, Header, +}; /// A structure for building archives /// @@ -208,7 +212,7 @@ impl Builder { /// # Ok(()) }) } /// ``` pub async fn append_path>(&mut self, path: P) -> io::Result<()> { - let mode = self.mode.clone(); + let mode = self.mode; let follow = self.follow; append_path_with_name(self.get_mut(), path.as_ref(), None, mode, follow).await?; Ok(()) @@ -248,7 +252,7 @@ impl Builder { path: P, name: N, ) -> io::Result<()> { - let mode = self.mode.clone(); + let mode = self.mode; let follow = self.follow; append_path_with_name( self.get_mut(), @@ -296,7 +300,7 @@ impl Builder { path: P, file: &mut fs::File, ) -> io::Result<()> { - let mode = self.mode.clone(); + let mode = self.mode; append_file(self.get_mut(), path.as_ref(), file, mode).await?; Ok(()) } @@ -335,7 +339,7 @@ impl Builder { P: AsRef, Q: AsRef, { - let mode = self.mode.clone(); + let mode = self.mode; append_dir(self.get_mut(), path.as_ref(), src_path.as_ref(), mode).await?; Ok(()) } @@ -371,7 +375,7 @@ impl Builder { P: AsRef, Q: AsRef, { - let mode = self.mode.clone(); + let mode = self.mode; let follow = self.follow; append_dir_all( self.get_mut(), @@ -495,7 +499,7 @@ async fn append_dir( Ok(()) } -fn prepare_header(size: u64, entry_type: u8) -> Header { +fn prepare_header(size: u64, entry_type: EntryType) -> Header { let mut header = Header::new_gnu(); let name = b"././@LongLink"; header.as_gnu_mut().unwrap().name[..name.len()].clone_from_slice(&name[..]); @@ -505,7 +509,7 @@ fn prepare_header(size: u64, entry_type: u8) -> Header { header.set_mtime(0); // + 1 to be compliant with GNU tar header.set_size(size + 1); - header.set_entry_type(EntryType::new(entry_type)); + header.set_entry_type(entry_type); header.set_cksum(); header } @@ -527,7 +531,7 @@ async fn prepare_header_path( if data.len() < max { return Err(e); } - let header2 = prepare_header(data.len() as u64, b'L'); + let header2 = prepare_header(data.len() as u64, EntryType::GNULongName); // null-terminated string let mut data2 = data.chain(io::repeat(0).take(1)); append(dst, &header2, &mut data2).await?; @@ -550,7 +554,7 @@ async fn prepare_header_link( if data.len() < header.as_old().linkname.len() { return Err(e); } - let header2 = prepare_header(data.len() as u64, b'K'); + let header2 = prepare_header(data.len() as u64, EntryType::GNULongLink); let mut data2 = data.chain(io::repeat(0).take(1)); append(dst, &header2, &mut data2).await?; } diff --git a/src/entry.rs b/src/entry.rs index 5b94621..c2e7eb3 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -1,22 +1,23 @@ -use std::borrow::Cow; -use std::pin::Pin; -use std::task::{Context, Poll}; -use std::{cmp, fmt, marker}; - -use async_std::fs; -use async_std::fs::OpenOptions; -use async_std::io::prelude::*; -use async_std::io::{self, Error, ErrorKind, SeekFrom}; -use async_std::path::{Component, Path, PathBuf}; +use std::{ + borrow::Cow, + cmp, fmt, marker, + pin::Pin, + task::{Context, Poll}, +}; + +use async_std::{ + fs, + fs::OpenOptions, + io::{self, prelude::*, Error, ErrorKind, SeekFrom}, + path::{Component, Path, PathBuf}, +}; use pin_project::{pin_project, project}; use filetime::{self, FileTime}; -use crate::error::TarError; -use crate::header::bytes2path; -use crate::other; -use crate::pax::pax_extensions; -use crate::{Archive, Header, PaxExtensions}; +use crate::{ + error::TarError, header::bytes2path, other, pax::pax_extensions, Archive, Header, PaxExtensions, +}; /// A read-only view into an entry of an archive. /// @@ -96,12 +97,12 @@ impl fmt::Debug for EntryIo { /// additional handling by users. Today the File is returned, in future /// the enum may be extended with kinds for links, directories etc. #[derive(Debug)] +#[non_exhaustive] pub enum Unpacked { /// A file was unpacked. File(fs::File), /// A directory, hardlink, symlink, or other node was unpacked. - #[doc(hidden)] - __Nonexhaustive, + Other, } impl Entry { @@ -516,7 +517,7 @@ impl EntryFields { if let Ok(mode) = self.header.mode() { set_perms(dst, None, mode, self.preserve_permissions).await?; } - return Ok(Unpacked::__Nonexhaustive); + return Ok(Unpacked::Other); } else if kind.is_hard_link() || kind.is_symlink() { let src = match self.link_name()? { Some(name) => name, @@ -579,7 +580,7 @@ impl EntryFields { ) })?; }; - return Ok(Unpacked::__Nonexhaustive); + return Ok(Unpacked::Other); #[cfg(target_arch = "wasm32")] #[allow(unused_variables)] @@ -601,7 +602,7 @@ impl EntryFields { || kind.is_gnu_longname() || kind.is_gnu_longlink() { - return Ok(Unpacked::__Nonexhaustive); + return Ok(Unpacked::Other); }; // Old BSD-tar compatibility. @@ -612,7 +613,7 @@ impl EntryFields { if let Ok(mode) = self.header.mode() { set_perms(dst, None, mode, self.preserve_permissions).await?; } - return Ok(Unpacked::__Nonexhaustive); + return Ok(Unpacked::Other); } // Note the lack of `else` clause above. According to the FreeBSD @@ -666,18 +667,18 @@ impl EntryFields { } Ok::(f) } - .await - .map_err(|e| { - let header = self.header.path_bytes(); - TarError::new( - &format!( - "failed to unpack `{}` into `{}`", - String::from_utf8_lossy(&header), - dst.display() - ), - e, - ) - })?; + .await + .map_err(|e| { + let header = self.header.path_bytes(); + TarError::new( + &format!( + "failed to unpack `{}` into `{}`", + String::from_utf8_lossy(&header), + dst.display() + ), + e, + ) + })?; if self.preserve_mtime { if let Ok(mtime) = self.header.mtime() { @@ -771,8 +772,7 @@ impl EntryFields { me: &mut EntryFields, dst: &Path, ) -> io::Result<()> { - use std::ffi::OsStr; - use std::os::unix::prelude::*; + use std::{ffi::OsStr, os::unix::prelude::*}; let exts = match me.pax_extensions().await { Ok(Some(e)) => e, diff --git a/src/entry_type.rs b/src/entry_type.rs index 951388d..8c1106a 100644 --- a/src/entry_type.rs +++ b/src/entry_type.rs @@ -6,6 +6,7 @@ /// A non-exhaustive enum representing the possible entry types #[derive(Clone, Copy, PartialEq, Eq, Debug)] +#[non_exhaustive] pub enum EntryType { /// Regular file Regular, @@ -33,13 +34,8 @@ pub enum EntryType { XGlobalHeader, /// Extended Header XHeader, - /// Hints that destructuring should not be exhaustive. - /// - /// This enum may grow additional variants, so this makes sure clients - /// don't count on exhaustive matching. (Otherwise, adding a new variant - /// could break existing code.) - #[doc(hidden)] - __Nonexhaustive(u8), + /// Unknown header, + Other(u8), } impl EntryType { @@ -62,13 +58,13 @@ impl EntryType { b'L' => EntryType::GNULongName, b'K' => EntryType::GNULongLink, b'S' => EntryType::GNUSparse, - b => EntryType::__Nonexhaustive(b), + other => EntryType::Other(other), } } /// Returns the raw underlying byte that this entry type represents. - pub fn as_byte(&self) -> u8 { - match *self { + pub fn as_byte(self) -> u8 { + match self { EntryType::Regular => b'0', EntryType::Link => b'1', EntryType::Symlink => b'2', @@ -82,7 +78,7 @@ impl EntryType { EntryType::GNULongName => b'L', EntryType::GNULongLink => b'K', EntryType::GNUSparse => b'S', - EntryType::__Nonexhaustive(b) => b, + EntryType::Other(other) => other, } } @@ -127,67 +123,67 @@ impl EntryType { } /// Returns whether this type represents a regular file. - pub fn is_file(&self) -> bool { - self == &EntryType::Regular + pub fn is_file(self) -> bool { + self == EntryType::Regular } /// Returns whether this type represents a hard link. - pub fn is_hard_link(&self) -> bool { - self == &EntryType::Link + pub fn is_hard_link(self) -> bool { + self == EntryType::Link } /// Returns whether this type represents a symlink. - pub fn is_symlink(&self) -> bool { - self == &EntryType::Symlink + pub fn is_symlink(self) -> bool { + self == EntryType::Symlink } /// Returns whether this type represents a character special device. - pub fn is_character_special(&self) -> bool { - self == &EntryType::Char + pub fn is_character_special(self) -> bool { + self == EntryType::Char } /// Returns whether this type represents a block special device. - pub fn is_block_special(&self) -> bool { - self == &EntryType::Block + pub fn is_block_special(self) -> bool { + self == EntryType::Block } /// Returns whether this type represents a directory. - pub fn is_dir(&self) -> bool { - self == &EntryType::Directory + pub fn is_dir(self) -> bool { + self == EntryType::Directory } /// Returns whether this type represents a FIFO. - pub fn is_fifo(&self) -> bool { - self == &EntryType::Fifo + pub fn is_fifo(self) -> bool { + self == EntryType::Fifo } /// Returns whether this type represents a contiguous file. - pub fn is_contiguous(&self) -> bool { - self == &EntryType::Continuous + pub fn is_contiguous(self) -> bool { + self == EntryType::Continuous } /// Returns whether this type represents a GNU long name header. - pub fn is_gnu_longname(&self) -> bool { - self == &EntryType::GNULongName + pub fn is_gnu_longname(self) -> bool { + self == EntryType::GNULongName } /// Returns whether this type represents a GNU sparse header. - pub fn is_gnu_sparse(&self) -> bool { - self == &EntryType::GNUSparse + pub fn is_gnu_sparse(self) -> bool { + self == EntryType::GNUSparse } /// Returns whether this type represents a GNU long link header. - pub fn is_gnu_longlink(&self) -> bool { - self == &EntryType::GNULongLink + pub fn is_gnu_longlink(self) -> bool { + self == EntryType::GNULongLink } /// Returns whether this type represents a GNU long name header. - pub fn is_pax_global_extensions(&self) -> bool { - self == &EntryType::XGlobalHeader + pub fn is_pax_global_extensions(self) -> bool { + self == EntryType::XGlobalHeader } /// Returns whether this type represents a GNU long link header. - pub fn is_pax_local_extensions(&self) -> bool { - self == &EntryType::XHeader + pub fn is_pax_local_extensions(self) -> bool { + self == EntryType::XHeader } } diff --git a/src/error.rs b/src/error.rs index e9b22ed..829c727 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,4 @@ -use std::error; -use std::fmt; +use std::{error, fmt}; use async_std::io::{self, Error}; diff --git a/src/header.rs b/src/header.rs index b7dac77..6ae7213 100644 --- a/src/header.rs +++ b/src/header.rs @@ -3,19 +3,14 @@ use std::os::unix::prelude::*; #[cfg(windows)] use std::os::windows::prelude::*; -use std::borrow::Cow; -use std::fmt; -use std::iter; -use std::iter::repeat; -use std::mem; -use std::str; +use std::{borrow::Cow, fmt, iter, iter::repeat, mem, str}; -use async_std::fs; -use async_std::io; -use async_std::path::{Component, Path, PathBuf}; +use async_std::{ + fs, io, + path::{Component, Path, PathBuf}, +}; -use crate::other; -use crate::EntryType; +use crate::{other, EntryType}; /// Representation of the header of an entry in an archive #[repr(C)] @@ -27,6 +22,7 @@ pub struct Header { /// Declares the information that should be included when filling a Header /// from filesystem metadata. #[derive(Clone, Copy, PartialEq, Eq, Debug)] +#[non_exhaustive] pub enum HeaderMode { /// All supported metadata, including mod/access times and ownership will /// be included. @@ -35,9 +31,6 @@ pub enum HeaderMode { /// Only metadata that is directly relevant to the identity of a file will /// be included. In particular, ownership and mod/access times are excluded. Deterministic, - - #[doc(hidden)] - __Nonexhaustive, } /// Representation of the header of an entry in an archive @@ -609,10 +602,11 @@ impl Header { /// major device number. pub fn set_device_major(&mut self, major: u32) -> io::Result<()> { if let Some(ustar) = self.as_ustar_mut() { - return Ok(ustar.set_device_major(major)); - } - if let Some(gnu) = self.as_gnu_mut() { - Ok(gnu.set_device_major(major)) + ustar.set_device_major(major); + Ok(()) + } else if let Some(gnu) = self.as_gnu_mut() { + gnu.set_device_major(major); + Ok(()) } else { Err(other("not a ustar or gnu archive, cannot set dev_major")) } @@ -641,10 +635,11 @@ impl Header { /// minor device number. pub fn set_device_minor(&mut self, minor: u32) -> io::Result<()> { if let Some(ustar) = self.as_ustar_mut() { - return Ok(ustar.set_device_minor(minor)); - } - if let Some(gnu) = self.as_gnu_mut() { - Ok(gnu.set_device_minor(minor)) + ustar.set_device_minor(minor); + Ok(()) + } else if let Some(gnu) = self.as_gnu_mut() { + gnu.set_device_minor(minor); + Ok(()) } else { Err(other("not a ustar or gnu archive, cannot set dev_minor")) } @@ -740,7 +735,6 @@ impl Header { }; self.set_mode(fs_mode); } - HeaderMode::__Nonexhaustive => panic!(), } // Note that if we are a GNU header we *could* set atime/ctime, except @@ -812,7 +806,6 @@ impl Header { let fs_mode = if meta.is_dir() { 0o755 } else { 0o644 }; self.set_mode(fs_mode); } - HeaderMode::__Nonexhaustive => panic!(), } let ft = meta.file_type(); @@ -937,7 +930,7 @@ impl UstarHeader { } else { let mut bytes = Vec::new(); let prefix = truncate(&self.prefix); - if prefix.len() > 0 { + if !prefix.is_empty() { bytes.extend_from_slice(prefix); bytes.push(b'/'); } @@ -1346,13 +1339,13 @@ impl GnuExtSparseHeader { /// Returns a view into this header as a byte array. pub fn as_bytes(&self) -> &[u8; 512] { debug_assert_eq!(mem::size_of_val(self), 512); - unsafe { mem::transmute(self) } + unsafe { &*(self as *const GnuExtSparseHeader as *const [u8; 512]) } } /// Returns a view into this header as a byte array. pub fn as_mut_bytes(&mut self) -> &mut [u8; 512] { debug_assert_eq!(mem::size_of_val(self), 512); - unsafe { mem::transmute(self) } + unsafe { &mut *(self as *mut GnuExtSparseHeader as *mut [u8; 512]) } } /// Returns a slice of the underlying sparse headers. @@ -1403,7 +1396,7 @@ fn octal_into(dst: &mut [u8], val: T) { // Wrapper to figure out if we should fill the header field using tar's numeric // extension (binary) or not (octal). fn num_field_wrapper_into(dst: &mut [u8], src: u64) { - if src >= 8589934592 || (src >= 2097152 && dst.len() == 8) { + if src >= 8_589_934_592 || (src >= 2_097_152 && dst.len() == 8) { numeric_extended_into(dst, src); } else { octal_into(dst, src); diff --git a/src/lib.rs b/src/lib.rs index 08266ad..caa78ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,13 +21,16 @@ use std::io::{Error, ErrorKind}; -pub use crate::archive::{Archive, ArchiveBuilder, Entries}; -pub use crate::builder::Builder; -pub use crate::entry::{Entry, Unpacked}; -pub use crate::entry_type::EntryType; -pub use crate::header::GnuExtSparseHeader; -pub use crate::header::{GnuHeader, GnuSparseHeader, Header, HeaderMode, OldHeader, UstarHeader}; -pub use crate::pax::{PaxExtension, PaxExtensions}; +pub use crate::{ + archive::{Archive, ArchiveBuilder, Entries}, + builder::Builder, + entry::{Entry, Unpacked}, + entry_type::EntryType, + header::{ + GnuExtSparseHeader, GnuHeader, GnuSparseHeader, Header, HeaderMode, OldHeader, UstarHeader, + }, + pax::{PaxExtension, PaxExtensions}, +}; mod archive; mod builder; diff --git a/src/pax.rs b/src/pax.rs index fffd49d..7c131b9 100644 --- a/src/pax.rs +++ b/src/pax.rs @@ -1,5 +1,4 @@ -use std::slice; -use std::str; +use std::{slice, str}; use async_std::io; @@ -20,11 +19,8 @@ pub struct PaxExtension<'entry> { } pub fn pax_extensions(a: &[u8]) -> PaxExtensions { - fn is_newline(a: &u8) -> bool { - *a == b'\n' - } PaxExtensions { - data: a.split(is_newline), + data: a.split(|a| *a == b'\n'), } } diff --git a/tests/all.rs b/tests/all.rs index ba2cede..5de2f40 100644 --- a/tests/all.rs +++ b/tests/all.rs @@ -4,10 +4,12 @@ extern crate tempfile; #[cfg(all(unix, feature = "xattr"))] extern crate xattr; -use async_std::fs::{self, File}; -use async_std::io::{self, Cursor, Read, Write}; -use async_std::path::{Path, PathBuf}; -use async_std::prelude::*; +use async_std::{ + fs::{self, File}, + io::{self, Cursor, Read, Write}, + path::{Path, PathBuf}, + prelude::*, +}; use std::iter::repeat; use async_tar::{Archive, ArchiveBuilder, Builder, EntryType, Header}; @@ -275,7 +277,7 @@ async fn xattrs() { t!(ar.unpack(td.path()).await); let val = xattr::get(td.path().join("a/b"), "user.pax.flags").unwrap(); - assert_eq!(val.unwrap(), "epm".as_bytes()); + assert_eq!(val.unwrap(), b"epm"); } #[async_std::test] @@ -591,7 +593,7 @@ async fn octal_spaces() { assert_eq!(entry.header().uid().unwrap(), 0); assert_eq!(entry.header().gid().unwrap(), 0); assert_eq!(entry.header().size().unwrap(), 2); - assert_eq!(entry.header().mtime().unwrap(), 0o12440016664); + assert_eq!(entry.header().mtime().unwrap(), 0o12_440_016_664); assert_eq!(entry.header().cksum().unwrap(), 0o4253); } @@ -640,9 +642,9 @@ async fn file_times() { let meta = fs::metadata(td.path().join("a")).await.unwrap(); let mtime = FileTime::from_last_modification_time(&meta); let atime = FileTime::from_last_access_time(&meta); - assert_eq!(mtime.unix_seconds(), 1000000000); + assert_eq!(mtime.unix_seconds(), 1_000_000_000); assert_eq!(mtime.nanoseconds(), 0); - assert_eq!(atime.unix_seconds(), 1000000000); + assert_eq!(atime.unix_seconds(), 1_000_000_000); assert_eq!(atime.nanoseconds(), 0); } @@ -683,8 +685,7 @@ async fn backslash_treated_well() { #[cfg(unix)] #[async_std::test] async fn nul_bytes_in_path() { - use std::ffi::OsStr; - use std::os::unix::prelude::*; + use std::{ffi::OsStr, os::unix::prelude::*}; let nul_path = OsStr::from_bytes(b"foo\0"); let td = t!(TempBuilder::new().prefix("async-tar").tempdir()); @@ -767,7 +768,7 @@ async fn long_name_trailing_nul() { h.set_size(6); h.set_entry_type(EntryType::file()); h.set_cksum(); - t!(b.append(&h, "foobar".as_bytes()).await); + t!(b.append(&h, b"foobar" as &[u8]).await); let contents = t!(b.into_inner().await); let mut a = Archive::new(&contents[..]); @@ -792,7 +793,7 @@ async fn long_linkname_trailing_nul() { h.set_size(6); h.set_entry_type(EntryType::file()); h.set_cksum(); - t!(b.append(&h, "foobar".as_bytes()).await); + t!(b.append(&h, b"foobar" as &[u8]).await); let contents = t!(b.into_inner().await); let mut a = Archive::new(&contents[..]); @@ -972,9 +973,7 @@ async fn path_separators() { #[async_std::test] #[cfg(unix)] async fn append_path_symlink() { - use std::borrow::Cow; - use std::env; - use std::os::unix::fs::symlink; + use std::{borrow::Cow, env, os::unix::fs::symlink}; let mut ar = Builder::new(Vec::new()); ar.follow_symlinks(false); diff --git a/tests/entry.rs b/tests/entry.rs index 8c1f700..44420a5 100644 --- a/tests/entry.rs +++ b/tests/entry.rs @@ -1,8 +1,7 @@ extern crate async_tar; extern crate tempfile; -use async_std::fs::File; -use async_std::prelude::*; +use async_std::{fs::File, prelude::*}; use tempfile::Builder; diff --git a/tests/header/mod.rs b/tests/header/mod.rs index 98ac99c..74cc8ca 100644 --- a/tests/header/mod.rs +++ b/tests/header/mod.rs @@ -1,7 +1,12 @@ -use std::fs::{self, File}; -use std::io::{self, Write}; -use std::path::Path; -use std::{iter, mem, thread, time}; +#![allow(clippy::cognitive_complexity)] + +use std::{ + fs::{self, File}, + io::{self, Write}, + iter, mem, + path::Path, + thread, time, +}; use tempfile::Builder; @@ -207,26 +212,26 @@ fn extended_numeric_format() { let mut h: GnuHeader = unsafe { mem::zeroed() }; h.as_header_mut().set_size(42); assert_eq!(h.size, [48, 48, 48, 48, 48, 48, 48, 48, 48, 53, 50, 0]); - h.as_header_mut().set_size(8589934593); + h.as_header_mut().set_size(8_589_934_593); assert_eq!(h.size, [0x80, 0, 0, 0, 0, 0, 0, 0x02, 0, 0, 0, 1]); h.size = [0x80, 0, 0, 0, 0, 0, 0, 0x02, 0, 0, 0, 0]; - assert_eq!(h.as_header().entry_size().unwrap(), 0x0200000000); + assert_eq!(h.as_header().entry_size().unwrap(), 0x0002_0000_0000); h.size = [48, 48, 48, 48, 48, 48, 48, 48, 48, 53, 51, 0]; assert_eq!(h.as_header().entry_size().unwrap(), 43); h.as_header_mut().set_gid(42); assert_eq!(h.gid, [48, 48, 48, 48, 48, 53, 50, 0]); assert_eq!(h.as_header().gid().unwrap(), 42); - h.as_header_mut().set_gid(0x7fffffffffffffff); + h.as_header_mut().set_gid(0x7fff_ffff_ffff_ffff); assert_eq!(h.gid, [0xff; 8]); - assert_eq!(h.as_header().gid().unwrap(), 0x7fffffffffffffff); + assert_eq!(h.as_header().gid().unwrap(), 0x7fff_ffff_ffff_ffff); h.uid = [0x80, 0x00, 0x00, 0x00, 0x12, 0x34, 0x56, 0x78]; - assert_eq!(h.as_header().uid().unwrap(), 0x12345678); + assert_eq!(h.as_header().uid().unwrap(), 0x1234_5678); h.mtime = [ 0x80, 0, 0, 0, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, ]; - assert_eq!(h.as_header().mtime().unwrap(), 0x0123456789abcdef); + assert_eq!(h.as_header().mtime().unwrap(), 0x0123_4567_89ab_cdef); } #[test]