Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/tamer
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@ryansg.com>2020-04-06 22:07:39 -0400
committerMike Gerwitz <mike.gerwitz@ryansg.com>2020-04-28 09:06:25 -0400
commitfbfb3c4ba2a90df028bd02e268ce286f99c3e16d (patch)
tree209a63acbfcc238f4ddc471446c0cf7ed3decaa9 /tamer
parentd97e53a835cec970c103d10eaa9f4d1b93ee8a82 (diff)
downloadtame-fbfb3c4ba2a90df028bd02e268ce286f99c3e16d.tar.gz
tame-fbfb3c4ba2a90df028bd02e268ce286f99c3e16d.tar.bz2
tame-fbfb3c4ba2a90df028bd02e268ce286f99c3e16d.zip
[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.
Diffstat (limited to 'tamer')
-rw-r--r--tamer/src/fs.rs19
-rw-r--r--tamer/src/ld/poc.rs12
2 files changed, 26 insertions, 5 deletions
diff --git a/tamer/src/fs.rs b/tamer/src/fs.rs
index 40b0f31..0471835 100644
--- a/tamer/src/fs.rs
+++ b/tamer/src/fs.rs
@@ -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`.
diff --git a/tamer/src/ld/poc.rs b/tamer/src/ld/poc.rs
index 689aa9d..117aeca 100644
--- a/tamer/src/ld/poc.rs
+++ b/tamer/src/ld/poc.rs
@@ -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() {