Add filestat_get for stdout, stdin and stderr

This makes fstat work for stdout, stdin and stderr as expected.
This seemed like the only reasonable functions to implement from the
filestat_* set, for stdout, stdin and stderr.

Fixes #2515
This commit is contained in:
Sakarias Johansson
2020-12-16 14:30:08 +01:00
parent 245abc2bb2
commit 22ad43b430

View File

@@ -17,7 +17,7 @@
// TODO it might worth re-investigating the suitability of this type on Windows. // TODO it might worth re-investigating the suitability of this type on Windows.
use super::{fd, AsFile}; use super::{fd, AsFile};
use crate::handle::{Fdflags, Filetype, Handle, HandleRights, Rights, RightsExt, Size}; use crate::handle::{Fdflags, Filestat, Filetype, Handle, HandleRights, Rights, RightsExt, Size};
use crate::sandboxed_tty_writer::SandboxedTTYWriter; use crate::sandboxed_tty_writer::SandboxedTTYWriter;
use crate::{Error, Result}; use crate::{Error, Result};
use std::any::Any; use std::any::Any;
@@ -65,6 +65,9 @@ impl Handle for Stdin {
} }
Ok(()) Ok(())
} }
fn filestat_get(&self) -> Result<Filestat> {
fd::filestat_get(&*self.as_file()?)
}
fn read_vectored(&self, iovs: &mut [io::IoSliceMut]) -> Result<usize> { fn read_vectored(&self, iovs: &mut [io::IoSliceMut]) -> Result<usize> {
let nread = io::stdin().read_vectored(iovs)?; let nread = io::stdin().read_vectored(iovs)?;
Ok(nread) Ok(nread)
@@ -111,6 +114,9 @@ impl Handle for Stdout {
} }
Ok(()) Ok(())
} }
fn filestat_get(&self) -> Result<Filestat> {
fd::filestat_get(&*self.as_file()?)
}
fn write_vectored(&self, iovs: &[io::IoSlice]) -> Result<usize> { fn write_vectored(&self, iovs: &[io::IoSlice]) -> Result<usize> {
// lock for the duration of the scope // lock for the duration of the scope
let stdout = io::stdout(); let stdout = io::stdout();
@@ -165,6 +171,9 @@ impl Handle for Stderr {
} }
Ok(()) Ok(())
} }
fn filestat_get(&self) -> Result<Filestat> {
fd::filestat_get(&*self.as_file()?)
}
fn write_vectored(&self, iovs: &[io::IoSlice]) -> Result<usize> { fn write_vectored(&self, iovs: &[io::IoSlice]) -> Result<usize> {
// Always sanitize stderr, even if it's not directly connected to a tty, // Always sanitize stderr, even if it's not directly connected to a tty,
// because stderr is meant for diagnostics rather than binary output, // because stderr is meant for diagnostics rather than binary output,