Skip to content

Commit

Permalink
Merge pull request #50 from dignifiedquire/cleanups
Browse files Browse the repository at this point in the history
Cleanups and fixes
  • Loading branch information
dignifiedquire authored Sep 2, 2024
2 parents 748fee5 + 611d903 commit 2e2b52d
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 72 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/coverage.yml

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
include:
- build: msrv
os: ubuntu-latest
rust: 1.51
rust: 1.63
- build: stable
os: ubuntu-latest
rust: stable
Expand All @@ -41,7 +41,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test

fmt:
name: Check formatting
runs-on: ubuntu-latest
Expand All @@ -50,7 +50,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
components: rustfmt
override: true
- uses: actions-rs/cargo@v1
Expand All @@ -66,7 +66,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
components: clippy
override: true
- uses: actions-rs/cargo@v1
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ contents are never required to be entirely resident in memory all at once.
"""

[dependencies]
async-std = "1.6.0"
async-std = { version = "1.12.0", features = ["unstable"] }
filetime = "0.2.8"
pin-project = "1.0.8"

[dev-dependencies]
async-std = { version = "1.6.0", features = ["unstable", "attributes"] }
async-std = { version = "1.12.0", features = ["unstable", "attributes"] }
static_assertions = "1.1.0"
tempfile = "3"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn main() {

# MSRV

Minimal stable rust version: 1.51
Minimal stable rust version: 1.63

*An increase to the MSRV is accompanied by a minor version bump*

Expand Down
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
29 changes: 22 additions & 7 deletions tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,31 +552,46 @@ async fn extracting_malicious_tarball() {
// The `tmp` subdirectory should be created and within this
// subdirectory, there should be files named `abs_evil.txt` through
// `abs_evil6.txt`.
assert!(fs::metadata(td.path().join("tmp"))
let tmp_root = td.path().join("tmp");

assert!(fs::metadata(&tmp_root)
.await
.map(|m| m.is_dir())
.unwrap_or(false));
assert!(fs::metadata(td.path().join("tmp/abs_evil.txt"))

let mut entries = fs::read_dir(&tmp_root).await.unwrap();
while let Some(entry) = entries.next().await {
let entry = entry.unwrap();
println!("- {:?}", entry.file_name());
}

assert!(fs::metadata(tmp_root.join("abs_evil.txt"))
.await
.map(|m| m.is_file())
.unwrap_or(false));
assert!(fs::metadata(td.path().join("tmp/abs_evil2.txt"))

// not present due to // being interpreted differently on windows
#[cfg(not(target_os = "windows"))]
assert!(fs::metadata(tmp_root.join("abs_evil2.txt"))
.await
.map(|m| m.is_file())
.unwrap_or(false));
assert!(fs::metadata(td.path().join("tmp/abs_evil3.txt"))
assert!(fs::metadata(tmp_root.join("abs_evil3.txt"))
.await
.map(|m| m.is_file())
.unwrap_or(false));
assert!(fs::metadata(td.path().join("tmp/abs_evil4.txt"))
assert!(fs::metadata(tmp_root.join("abs_evil4.txt"))
.await
.map(|m| m.is_file())
.unwrap_or(false));
assert!(fs::metadata(td.path().join("tmp/abs_evil5.txt"))

// not present due to // being interpreted differently on windows
#[cfg(not(target_os = "windows"))]
assert!(fs::metadata(tmp_root.join("abs_evil5.txt"))
.await
.map(|m| m.is_file())
.unwrap_or(false));
assert!(fs::metadata(td.path().join("tmp/abs_evil6.txt"))
assert!(fs::metadata(tmp_root.join("abs_evil6.txt"))
.await
.map(|m| m.is_file())
.unwrap_or(false));
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 2e2b52d

Please sign in to comment.