diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-01-10 13:36:13 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-01-10 13:36:13 +0000 |
commit | 27b6f70a2e7556fc3012b173602d258f33cf0a7e (patch) | |
tree | 3864c5c51c9fadd6b25922d8d0aaf55bb10d29a6 /src/resource.rs | |
parent | 437a2c87e85de43911eb04f721e0af9f3c67f4cf (diff) | |
download | subplot-27b6f70a2e7556fc3012b173602d258f33cf0a7e.tar.gz |
resource: Use a fallback path if needed
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src/resource.rs')
-rw-r--r-- | src/resource.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/resource.rs b/src/resource.rs index d8fab16..6f2b33b 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -88,12 +88,20 @@ pub fn open<P: AsRef<Path>>(subpath: P) -> io::Result<Box<dyn Read>> { } } +fn internal_fallback_path() -> Option<&'static Path> { + match env!("FALLBACK_PATH") { + "" => None, + s => Some(Path::new(s)), + } +} + fn internal_open(subpath: &Path) -> io::Result<Box<dyn Read>> { let search_paths = SEARCH_PATHS.lock().expect("Unable to lock SEARCH_PATHS"); let search_paths = search_paths.iter().map(|p| p.as_path()); let search_paths = std::iter::empty() .chain(Some(Path::new("."))) - .chain(search_paths); + .chain(search_paths) + .chain(internal_fallback_path()); let mut ret = Err(io::Error::new( io::ErrorKind::NotFound, format!("Unable to find {} in resource paths", subpath.display()), |