|
1 | 1 | use std::any::Any;
|
2 | 2 | use std::collections::BTreeMap;
|
3 |
| -use std::io; |
4 | 3 | use std::io::{IsTerminal, Read, SeekFrom, Write};
|
5 | 4 | use std::ops::Deref;
|
6 | 5 | use std::rc::{Rc, Weak};
|
| 6 | +use std::{fs, io}; |
7 | 7 |
|
8 | 8 | use rustc_abi::Size;
|
9 | 9 |
|
@@ -62,6 +62,10 @@ pub trait FileDescription: std::fmt::Debug + Any {
|
62 | 62 | throw_unsup_format!("cannot close {}", self.name());
|
63 | 63 | }
|
64 | 64 |
|
| 65 | + fn metadata<'tcx>(&self) -> InterpResult<'tcx, io::Result<fs::Metadata>> { |
| 66 | + throw_unsup_format!("obtaining metadata is only supported on file-backed file descriptors"); |
| 67 | + } |
| 68 | + |
65 | 69 | fn is_tty(&self, _communicate_allowed: bool) -> bool {
|
66 | 70 | // Most FDs are not tty's and the consequence of a wrong `false` are minor,
|
67 | 71 | // so we use a default impl here.
|
@@ -216,7 +220,7 @@ impl Deref for FileDescriptionRef {
|
216 | 220 | }
|
217 | 221 |
|
218 | 222 | impl FileDescriptionRef {
|
219 |
| - fn new(fd: impl FileDescription, id: FdId) -> Self { |
| 223 | + pub fn new(fd: impl FileDescription, id: FdId) -> Self { |
220 | 224 | FileDescriptionRef(Rc::new(FileDescWithId { id, file_description: Box::new(fd) }))
|
221 | 225 | }
|
222 | 226 |
|
@@ -273,8 +277,8 @@ impl VisitProvenance for WeakFileDescriptionRef {
|
273 | 277 |
|
274 | 278 | /// A unique id for file descriptions. While we could use the address, considering that
|
275 | 279 | /// is definitely unique, the address would expose interpreter internal state when used
|
276 |
| -/// for sorting things. So instead we generate a unique id per file description that stays |
277 |
| -/// the same even if a file descriptor is duplicated and gets a new integer file descriptor. |
| 280 | +/// for sorting things. So instead we generate a unique id per file description is the name |
| 281 | +/// for all `dup`licates and is never reused. |
278 | 282 | #[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd)]
|
279 | 283 | pub struct FdId(usize);
|
280 | 284 |
|
|
0 commit comments