diff --git a/src/context.rs b/src/context.rs index 1fdffb10e..14ee9c471 100644 --- a/src/context.rs +++ b/src/context.rs @@ -12,6 +12,7 @@ use anyhow::Context as _; use once_cell::unsync::OnceCell; +use std::cell::Ref; use std::cell::RefCell; use std::cell::RefMut; use std::io::Read; @@ -163,6 +164,17 @@ impl Ini { }) } + fn update( + &mut self, + file_system: &Rc, + config_path: &str, + ) -> anyhow::Result<()> { + let data = file_system.read_to_string(config_path)?; + self.config = toml::from_str(&data)?; + + Ok(()) + } + /// Gets the directory which is writable. pub fn get_workdir(&self) -> String { format!("{}/workdir", self.root) @@ -229,7 +241,7 @@ impl Ini { /// Context owns global state which is set up once and then read everywhere. pub struct Context { root: String, - ini: Ini, + ini: Rc>, network: Rc, time: Rc, subprocess: Rc, @@ -252,7 +264,11 @@ impl Context { let unit = Rc::new(StdUnit {}); let file_system: Rc = Rc::new(StdFileSystem {}); let database: Rc = Rc::new(StdDatabase {}); - let ini = Ini::new(&file_system, &format!("{root}/workdir/wsgi.ini"), &root)?; + let ini = Rc::new(RefCell::new(Ini::new( + &file_system, + &format!("{root}/workdir/wsgi.ini"), + &root, + )?)); let connection = OnceCell::new(); let shutdown = Rc::new(RefCell::new(false)); Ok(Context { @@ -275,8 +291,16 @@ impl Context { } /// Gets the ini file. - pub fn get_ini(&self) -> &Ini { - &self.ini + pub fn get_ini(&self) -> Ref<'_, Ini> { + self.ini.borrow() + } + + /// Re-reads the ini file. + pub fn update_ini(&self) -> anyhow::Result<()> { + self.ini.borrow_mut().update( + &self.file_system, + &format!("{}/workdir/wsgi.ini", self.root), + ) } /// Gets the network implementation. diff --git a/src/sync_ref.rs b/src/sync_ref.rs index 3d55e0a14..5c293821c 100644 --- a/src/sync_ref.rs +++ b/src/sync_ref.rs @@ -71,6 +71,7 @@ pub fn download( ctx.get_file_system() .write_from_string(&config_data, &ctx.get_abspath("workdir/wsgi.ini"))?; + ctx.update_ini()?; } stream.write_all("sync-ref: removing old index...\n".as_bytes())?;