summaryrefslogtreecommitdiff
path: root/src/loading/fs.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-05-31 12:00:13 +0200
committerLaurenz <laurmaedje@gmail.com>2021-05-31 22:33:40 +0200
commit00ac68b8451179468aa39cba0d7fbea1ee20e0a1 (patch)
tree8271cf0189dc2a99109af72ce54867fb0cf90802 /src/loading/fs.rs
parente023bf2ac9f5796355d9485afc16781196bf212b (diff)
Fix and improve
- Set context location to resolved path during module evaluation. - Dump module diagnostics on import - Use same-file for more robustness than fs::canonicalize
Diffstat (limited to 'src/loading/fs.rs')
-rw-r--r--src/loading/fs.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/loading/fs.rs b/src/loading/fs.rs
index bf768bd5..e2654a2e 100644
--- a/src/loading/fs.rs
+++ b/src/loading/fs.rs
@@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
use std::rc::Rc;
use memmap2::Mmap;
+use same_file::Handle;
use serde::{Deserialize, Serialize};
use ttf_parser::{name_id, Face};
use walkdir::WalkDir;
@@ -167,10 +168,6 @@ impl Loader for FsLoader {
&self.faces
}
- fn resolve(&self, path: &Path) -> Option<FileHash> {
- hash(path)
- }
-
fn load_face(&mut self, idx: usize) -> Option<Buffer> {
load(&mut self.cache, &self.files[idx])
}
@@ -178,6 +175,10 @@ impl Loader for FsLoader {
fn load_file(&mut self, path: &Path) -> Option<Buffer> {
load(&mut self.cache, path)
}
+
+ fn resolve(&self, path: &Path) -> Option<FileHash> {
+ hash(path)
+ }
}
/// Load from the file system using a cache.
@@ -191,8 +192,11 @@ fn load(cache: &mut FileCache, path: &Path) -> Option<Buffer> {
})
}
+/// Create a hash that is the same for all paths pointing to the same file.
fn hash(path: &Path) -> Option<FileHash> {
- path.canonicalize().ok().map(|p| FileHash(fxhash::hash64(&p)))
+ Handle::from_path(path)
+ .map(|handle| FileHash(fxhash::hash64(&handle)))
+ .ok()
}
#[cfg(test)]