Skip to content

Make stream_len more atomic #108352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,11 @@ impl Seek for File {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
self.inner.seek(pos)
}

fn stream_len(&mut self) -> io::Result<u64> {
let file_attr = self.inner.file_attr()?;
Ok(file_attr.size())
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl Read for &File {
Expand Down Expand Up @@ -851,6 +856,10 @@ impl Seek for &File {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
self.inner.seek(pos)
}
fn stream_len(&mut self) -> io::Result<u64> {
let file_attr = self.inner.file_attr()?;
Ok(file_attr.size())
}
}

impl OpenOptions {
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/io/buffered/bufreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ impl<R: Seek> Seek for BufReader<R> {
)
})
}

fn stream_len(&mut self) -> io::Result<u64> {
self.inner.stream_len()
}
}

impl<T> SizeHint for BufReader<T> {
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/io/buffered/bufwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@ impl<W: Write + Seek> Seek for BufWriter<W> {
self.flush_buf()?;
self.get_mut().seek(pos)
}

fn stream_len(&mut self) -> io::Result<u64> {
self.inner.stream_len()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
10 changes: 10 additions & 0 deletions library/std/src/io/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ impl<S: Seek + ?Sized> Seek for &mut S {
fn stream_position(&mut self) -> io::Result<u64> {
(**self).stream_position()
}

#[inline]
fn stream_len(&mut self) -> io::Result<u64> {
(**self).stream_len()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<B: BufRead + ?Sized> BufRead for &mut B {
Expand Down Expand Up @@ -197,6 +202,11 @@ impl<S: Seek + ?Sized> Seek for Box<S> {
fn stream_position(&mut self) -> io::Result<u64> {
(**self).stream_position()
}

#[inline]
fn stream_len(&mut self) -> io::Result<u64> {
(**self).stream_len()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<B: BufRead + ?Sized> BufRead for Box<B> {
Expand Down