Skip to content

Commit

Permalink
Clippy and style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vorot93 committed Dec 27, 2019
1 parent 6e2082a commit c04479b
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 185 deletions.
10 changes: 6 additions & 4 deletions examples/extract_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions examples/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions examples/raw_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
43 changes: 24 additions & 19 deletions src/archive.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down Expand Up @@ -400,11 +405,11 @@ fn poll_next_raw<R: Read + Unpin>(
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,
Expand Down
36 changes: 20 additions & 16 deletions src/builder.rs
Original file line number Diff line number Diff line change
@@ -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
///
Expand Down Expand Up @@ -208,7 +212,7 @@ impl<W: Write + Unpin> Builder<W> {
/// # Ok(()) }) }
/// ```
pub async fn append_path<P: AsRef<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(())
Expand Down Expand Up @@ -248,7 +252,7 @@ impl<W: Write + Unpin> Builder<W> {
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(),
Expand Down Expand Up @@ -296,7 +300,7 @@ impl<W: Write + Unpin> Builder<W> {
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(())
}
Expand Down Expand Up @@ -335,7 +339,7 @@ impl<W: Write + Unpin> Builder<W> {
P: AsRef<Path>,
Q: AsRef<Path>,
{
let mode = self.mode.clone();
let mode = self.mode;
append_dir(self.get_mut(), path.as_ref(), src_path.as_ref(), mode).await?;
Ok(())
}
Expand Down Expand Up @@ -371,7 +375,7 @@ impl<W: Write + Unpin> Builder<W> {
P: AsRef<Path>,
Q: AsRef<Path>,
{
let mode = self.mode.clone();
let mode = self.mode;
let follow = self.follow;
append_dir_all(
self.get_mut(),
Expand Down Expand Up @@ -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[..]);
Expand All @@ -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
}
Expand All @@ -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?;
Expand All @@ -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?;
}
Expand Down
70 changes: 35 additions & 35 deletions src/entry.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down Expand Up @@ -96,12 +97,12 @@ impl<R: Read + Unpin> fmt::Debug for EntryIo<R> {
/// 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<R: Read + Unpin> Entry<R> {
Expand Down Expand Up @@ -516,7 +517,7 @@ impl<R: Read + Unpin> EntryFields<R> {
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,
Expand Down Expand Up @@ -579,7 +580,7 @@ impl<R: Read + Unpin> EntryFields<R> {
)
})?;
};
return Ok(Unpacked::__Nonexhaustive);
return Ok(Unpacked::Other);

#[cfg(target_arch = "wasm32")]
#[allow(unused_variables)]
Expand All @@ -601,7 +602,7 @@ impl<R: Read + Unpin> EntryFields<R> {
|| kind.is_gnu_longname()
|| kind.is_gnu_longlink()
{
return Ok(Unpacked::__Nonexhaustive);
return Ok(Unpacked::Other);
};

// Old BSD-tar compatibility.
Expand All @@ -612,7 +613,7 @@ impl<R: Read + Unpin> EntryFields<R> {
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
Expand Down Expand Up @@ -666,18 +667,18 @@ impl<R: Read + Unpin> EntryFields<R> {
}
Ok::<fs::File, io::Error>(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() {
Expand Down Expand Up @@ -771,8 +772,7 @@ impl<R: Read + Unpin> EntryFields<R> {
me: &mut EntryFields<R>,
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,
Expand Down
Loading

0 comments on commit c04479b

Please sign in to comment.