[DEV-7084] TAMER: CanonicalFile

This will be entirely replaced in an upcoming commit.  See that for
details.  I don't feel like dealing with the conflicts for rearranging and
squashing these commits.
master
Mike Gerwitz 2020-04-06 22:07:39 -04:00
parent d97e53a835
commit fbfb3c4ba2
2 changed files with 26 additions and 5 deletions

View File

@ -42,7 +42,7 @@ use std::ffi::OsString;
use std::fs;
use std::hash::BuildHasher;
use std::io::Result;
use std::path::Path;
use std::path::{Path, PathBuf};
/// A file.
pub trait File
@ -58,6 +58,23 @@ impl File for fs::File {
}
}
pub struct CanonicalFile<F: File>(PathBuf, F);
impl<F: File> Into<(PathBuf, F)> for CanonicalFile<F> {
fn into(self) -> (PathBuf, F) {
(self.0, self.1)
}
}
impl<F: File> File for CanonicalFile<F> {
fn open<P: AsRef<Path>>(path: P) -> Result<Self> {
let cpath = fs::canonicalize(path)?;
let file = F::open(&cpath)?;
Ok(Self(cpath, file))
}
}
/// A filesystem.
///
/// Opening a file (using [`open`](Filesystem::open)) proxies to `F::open`.

View File

@ -20,7 +20,9 @@
//! **This is a poorly-written proof of concept; do not use!** It has been
//! banished to its own file to try to make that more clear.
use crate::fs::{Filesystem, VisitOnceFile, VisitOnceFilesystem};
use crate::fs::{
CanonicalFile, Filesystem, VisitOnceFile, VisitOnceFilesystem,
};
use crate::global;
use crate::ir::asg::{
Asg, AsgError, DefaultAsg, IdentKind, IdentObject, IdentObjectData,
@ -34,6 +36,7 @@ use std::convert::TryInto;
use std::error::Error;
use std::fs;
use std::io::BufReader;
use std::path::PathBuf;
type LinkerAsg<'i> = DefaultAsg<'i, IdentObject<'i>, global::ProgIdentSize>;
type LinkerObjectRef = ObjectRef<global::ProgIdentSize>;
@ -126,16 +129,17 @@ fn load_xmlo<'a, 'i, I: Interner<'i>>(
interner: &'i I,
roots: &mut Vec<LinkerObjectRef>,
) -> LoadResult<'i> {
let path = fs::canonicalize(path_str)?;
let first = fs.visit_len() == 0;
let mut found: FxHashSet<&str> = Default::default();
let file: fs::File = match fs.open(&path)? {
let cfile: CanonicalFile<fs::File> = match fs.open(path_str)? {
VisitOnceFile::FirstVisit(file) => file,
VisitOnceFile::Visited => return Ok(None),
};
let (path, file) = cfile.into();
let reader = BufReader::new(file);
let mut xmlo: XmloReader<'_, _, _> = (reader, interner).into();
let mut elig = None;
@ -238,7 +242,7 @@ fn load_xmlo<'a, 'i, I: Interner<'i>>(
));
}
let mut dir = path.clone();
let mut dir: PathBuf = path.clone();
dir.pop();
for relpath in found.iter() {