Take into account the source directory when parsing org-mode in Organic.

Previously only the emacs code was doing this.
This commit is contained in:
Tom Alexander
2023-09-04 21:46:40 -04:00
parent 275b4b53d1
commit d3c733c5ad
6 changed files with 61 additions and 15 deletions

View File

@@ -1,14 +1,24 @@
use std::fmt::Debug;
use std::path::PathBuf;
pub trait FileAccessInterface: Debug {
fn read_file(&self, path: &str) -> Result<String, std::io::Error>;
}
#[derive(Debug, Clone)]
pub struct LocalFileAccessInterface;
pub struct LocalFileAccessInterface {
pub working_directory: Option<PathBuf>,
}
impl FileAccessInterface for LocalFileAccessInterface {
fn read_file(&self, path: &str) -> Result<String, std::io::Error> {
Ok(std::fs::read_to_string(path)?)
let final_path = self
.working_directory
.as_ref()
.map(PathBuf::as_path)
.map(|pb| pb.join(path))
.unwrap_or_else(|| PathBuf::from(path));
eprintln!("Reading file: {}", final_path.display());
Ok(std::fs::read_to_string(final_path)?)
}
}

View File

@@ -14,7 +14,9 @@ impl<'g, 's> GlobalSettings<'g, 's> {
pub fn new() -> GlobalSettings<'g, 's> {
GlobalSettings {
radio_targets: Vec::new(),
file_access: &LocalFileAccessInterface,
file_access: &LocalFileAccessInterface {
working_directory: None,
},
}
}
}