From 15466052f63c47cf47decd4409a9b0e936302773 Mon Sep 17 00:00:00 2001 From: Frazer McLean Date: Tue, 5 Nov 2024 19:35:20 +0100 Subject: [PATCH] Add test to reproduce issue in `impl Stream for Entries` --- tests/all.rs | 62 +++++++++++++++++++++++++++++++++ tests/archives/paxlongname.tar | Bin 0 -> 10240 bytes 2 files changed, 62 insertions(+) create mode 100644 tests/archives/paxlongname.tar diff --git a/tests/all.rs b/tests/all.rs index 722eed8..b112dac 100644 --- a/tests/all.rs +++ b/tests/all.rs @@ -762,6 +762,68 @@ async fn pax_simple() { assert_eq!(third.value(), Ok("1453146164.953123768")); } +#[tokio::test] +async fn pax_pending_interrupted() { + use std::pin::Pin; + + struct SirPendalot { + inner: R, + n: usize, + } + + impl SirPendalot + where + R: AsyncRead + Unpin, + { + fn new(reader: R) -> Self { + Self { + inner: reader, + n: 0, + } + } + + fn project(self: Pin<&mut Self>) -> (Pin<&mut R>, &mut usize) { + let Self { inner, n } = std::pin::Pin::into_inner(self); + (Pin::new(inner), n) + } + } + impl AsyncRead for SirPendalot + where + R: AsyncRead + Unpin, + { + fn poll_read( + self: std::pin::Pin<&mut Self>, + cx: &mut std::task::Context<'_>, + buf: &mut tokio::io::ReadBuf<'_>, + ) -> std::task::Poll> { + use std::task::Poll; + + let (inner, n) = self.project(); + + let pend = *n % 2 == 0; + *n += 1; + + if pend { + cx.waker().wake_by_ref(); + return Poll::Pending; + } + + inner.poll_read(cx, buf) + } + } + + let ar = tar!("paxlongname.tar"); + let ar = SirPendalot::new(ar); + let mut ar = Archive::new(ar); + let mut entries = t!(ar.entries()); + + let entry = t!(entries.next().await.unwrap()); + let path = t!(entry.path()); + let path = path.to_str().unwrap(); + + assert_eq!(path, "this_file_name_will_be_one_hundred_and_one_characters_long_once_i_add_some_more_characters_at_the_end"); +} + #[tokio::test] async fn pax_path() { let mut ar = Archive::new(tar!("pax2.tar")); diff --git a/tests/archives/paxlongname.tar b/tests/archives/paxlongname.tar new file mode 100644 index 0000000000000000000000000000000000000000..8178c4771ea78fba4f66bfeeb5b378ed77c88301 GIT binary patch literal 10240 zcmeIy%}&H15C`y{_bK`WT?XjKW$zw+g9(<=Hfh07HoK2+Ycxg^_hz#u|GAJd5Xf(s zR>wzoeGum*Eyp~J3qOyOaB#EmWt=8{5{^N5I0v7^vkU(HyB}O~eO`C*6vN9p*9(vA zyyqpZd*_&hKNhJq8f%MfT;u1cj4}n;mb5jhZgioHR%DCvTI>+#CA+j