pub struct FileResolver { /* private fields */ }Expand description
Resolve references against a filesystem.
By default that is the real filesystem, with references resolved to
absolute paths. Give it a crate::MapFs and it touches no disk at all;
give it a root and no reference can name anything outside that
directory, however many .. segments it carries.
Implementations§
Source§impl FileResolver
impl FileResolver
Sourcepub fn with_pathfinder(
self,
pathfinder: impl Fn(&str) -> String + Send + Sync + 'static,
) -> Self
pub fn with_pathfinder( self, pathfinder: impl Fn(&str) -> String + Send + Sync + 'static, ) -> Self
Transform each raw reference before resolving it.
Sourcepub fn with_preload(self, preload: BTreeMap<String, String>) -> Self
pub fn with_preload(self, preload: BTreeMap<String, String>) -> Self
Serve these paths from memory before touching the filesystem.
The map crate::preload_files returns goes here.
Sourcepub fn with_fs(self, filesystem: impl SourceFs + 'static) -> Self
pub fn with_fs(self, filesystem: impl SourceFs + 'static) -> Self
Read from filesystem instead of the one the plugin options name.
Read from an already shared filesystem handle.
Sourcepub fn with_root(self, root: impl Into<String>) -> Self
pub fn with_root(self, root: impl Into<String>) -> Self
Confine every candidate path to root.
The root and every candidate are resolved through the filesystem
first (SourceFs::real_path), then compared by whole segment.
So neither ../../etc/passwd nor a sibling directory whose name
merely starts with the root’s can be reached, a relative root
names the same directory a relative candidate does, and a
symbolic link inside the root is judged by where it POINTS
rather than by where it sits. A link that resolves to nothing at
all is refused outright, since its target could be created
before a read reaches it.
What this cannot do is stop a link created in the instant between the check and the read: the check answers for the filesystem as it was. A root whose contents another process can write needs a filesystem that enforces the boundary, not a resolver.
Neither the canonical TypeScript nor the Go port has this: they resolve wherever the reference points. It is additive, so a resolver without a root behaves exactly as they do.
Trait Implementations§
Source§impl Clone for FileResolver
impl Clone for FileResolver
Source§impl Debug for FileResolver
impl Debug for FileResolver
Source§impl Default for FileResolver
impl Default for FileResolver
Source§impl Resolver for FileResolver
impl Resolver for FileResolver
Source§fn resolve(
&self,
reference: Option<&str>,
input: &ResolverInput<'_>,
) -> Resolution
fn resolve( &self, reference: Option<&str>, input: &ResolverInput<'_>, ) -> Resolution
reference to a Resolution. A reference that names
nothing returns Resolution::not_found; raising the error is
the plugin’s job, not the resolver’s.