Skip to content

Commit

Permalink
chore: apply clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Sep 2, 2024
1 parent 748fee5 commit 1f4775a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ fn poll_skip<R: Read + Unpin>(
while amt > 0 {
let n = cmp::min(amt, buf.len() as u64);
match async_std::task::ready!(Pin::new(&mut source).poll_read(cx, &mut buf[..n as usize])) {
Ok(n) if n == 0 => {
Ok(0) => {
return Poll::Ready(Err(other("unexpected EOF during skip")));
}
Ok(n) => {
Expand Down
4 changes: 2 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ async fn prepare_header_link(
link_name: &Path,
) -> io::Result<()> {
// Same as previous function but for linkname
if let Err(e) = header.set_link_name(&link_name) {
if let Err(e) = header.set_link_name(link_name) {
let data = path2bytes(link_name)?;
if data.len() < header.as_old().linkname.len() {
return Err(e);
Expand Down Expand Up @@ -591,7 +591,7 @@ async fn append_dir_all(
) -> io::Result<()> {
let mut stack = vec![(src_path.to_path_buf(), true, false)];
while let Some((src, is_dir, is_symlink)) = stack.pop() {
let dest = path.join(src.strip_prefix(&src_path).unwrap());
let dest = path.join(src.strip_prefix(src_path).unwrap());

// In case of a symlink pointing to a directory, is_dir is false, but src.is_dir() will return true
if is_dir || (is_symlink && follow && src.is_dir().await) {
Expand Down
2 changes: 1 addition & 1 deletion src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ impl<R: Read + Unpin> EntryFields<R> {
if self.preserve_mtime {
if let Ok(mtime) = self.header.mtime() {
let mtime = FileTime::from_unix_time(mtime as i64, 0);
filetime::set_file_times(&dst, mtime, mtime).map_err(|e| {
filetime::set_file_times(dst, mtime, mtime).map_err(|e| {
TarError::new(&format!("failed to set mtime for `{}`", dst.display()), e)
})?;
}
Expand Down
36 changes: 16 additions & 20 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,12 @@ impl Header {
///
/// May return an error if the field is corrupted.
pub fn uid(&self) -> io::Result<u64> {
num_field_wrapper_from(&self.as_old().uid)
.map(|u| u as u64)
.map_err(|err| {
io::Error::new(
err.kind(),
format!("{} when getting uid for {}", err, self.path_lossy()),
)
})
num_field_wrapper_from(&self.as_old().uid).map_err(|err| {
io::Error::new(
err.kind(),
format!("{} when getting uid for {}", err, self.path_lossy()),
)
})
}

/// Encodes the `uid` provided into this header.
Expand All @@ -463,14 +461,12 @@ impl Header {

/// Returns the value of the group's user ID field
pub fn gid(&self) -> io::Result<u64> {
num_field_wrapper_from(&self.as_old().gid)
.map(|u| u as u64)
.map_err(|err| {
io::Error::new(
err.kind(),
format!("{} when getting gid for {}", err, self.path_lossy()),
)
})
num_field_wrapper_from(&self.as_old().gid).map_err(|err| {
io::Error::new(
err.kind(),
format!("{} when getting gid for {}", err, self.path_lossy()),
)
})
}

/// Encodes the `gid` provided into this header.
Expand Down Expand Up @@ -721,7 +717,7 @@ impl Header {
self.set_mtime(meta.mtime() as u64);
self.set_uid(meta.uid() as u64);
self.set_gid(meta.gid() as u64);
self.set_mode(meta.mode() as u32);
self.set_mode(meta.mode());
}
HeaderMode::Deterministic => {
self.set_mtime(0);
Expand Down Expand Up @@ -1502,7 +1498,7 @@ fn copy_path_into(mut slot: &mut [u8], path: &Path, is_link_name: bool) -> io::R
return Err(other("path component in archive cannot contain `/`"));
}
}
copy(&mut slot, &*bytes)?;
copy(&mut slot, &bytes)?;
if &*bytes != b"/" {
needs_slash = true;
}
Expand All @@ -1517,7 +1513,7 @@ fn copy_path_into(mut slot: &mut [u8], path: &Path, is_link_name: bool) -> io::R
return Ok(());

fn copy(slot: &mut &mut [u8], bytes: &[u8]) -> io::Result<()> {
copy_into(*slot, bytes)?;
copy_into(slot, bytes)?;
let tmp = std::mem::take(slot);
*slot = &mut tmp[bytes.len()..];
Ok(())
Expand Down Expand Up @@ -1565,7 +1561,7 @@ pub fn path2bytes(p: &Path) -> io::Result<Cow<[u8]>> {
#[cfg(any(unix, target_os = "redox"))]
/// On unix this will never fail
pub fn path2bytes(p: &Path) -> io::Result<Cow<[u8]>> {
Ok(p.as_os_str().as_bytes()).map(Cow::Borrowed)
Ok(Cow::Borrowed(p.as_os_str().as_bytes()))
}

#[cfg(windows)]
Expand Down
9 changes: 7 additions & 2 deletions src/pax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ impl<'entry> Iterator for PaxExtensions<'entry> {

fn next(&mut self) -> Option<io::Result<PaxExtension<'entry>>> {
let line = match self.data.next() {
Some(line) if line.is_empty() => return None,
Some(line) => line,
Some(line) => {
if line.is_empty() {
return None;
} else {
line
}
}
None => return None,
};

Expand Down
2 changes: 1 addition & 1 deletion tests/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fn set_path() {
#[test]
fn set_ustar_path_hard() {
let mut h = Header::new_ustar();
let p = Path::new("a").join(&vec!["a"; 100].join(""));
let p = Path::new("a").join(vec!["a"; 100].join(""));
t!(h.set_path(&p));
let path = t!(h.path());
let actual: &Path = path.as_ref().into();
Expand Down

0 comments on commit 1f4775a

Please sign in to comment.