From: Ian Jackson Date: Mon, 3 May 2021 11:54:22 +0000 (+0100) Subject: path resolution: Rename types and variables to mention Path X-Git-Tag: otter-0.6.0~454 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=1317e8ee8e2a735e2d9ebfab3f4b53efa68cdaf5;p=otter.git path resolution: Rename types and variables to mention Path Signed-off-by: Ian Jackson --- diff --git a/apitest/apitest.rs b/apitest/apitest.rs index fac1f027..187a87e4 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -641,19 +641,19 @@ impl DirSubst { pub fn otter<'s,S>(&self, xargs: &'s [S]) where &'s S: Into { - self.otter_rctx(&default(), xargs)? + self.otter_prctx(&default(), xargs)? } #[throws(AE)] - pub fn otter_rctx<'s,S>(&self, rctx: &ResolveContext, xargs: &'s [S]) + pub fn otter_prctx<'s,S>(&self, prctx: &PathResolveContext, xargs: &'s [S]) where &'s S: Into { let ds = self; let exe = ds.subst("@target@/debug/otter")?; let specs = self.subst("@src@/specs")?; let mut args: Vec = vec![]; - args.push("--config" .to_owned()); args.push(rctx.resolve(&CONFIG)); - args.push("--spec-dir".to_owned()); args.push(rctx.resolve(&specs) ); + args.push("--config" .to_owned()); args.push(prctx.resolve(&CONFIG)); + args.push("--spec-dir".to_owned()); args.push(prctx.resolve(&specs) ); args.extend(xargs.iter().map(|s| s.into())); let dbg = format!("running {} {:?}", &exe, &args); debug!("{}", &dbg); @@ -694,14 +694,14 @@ impl DirSubst { } #[throws(AE)] -pub fn prepare_game(ds: &DirSubst, rctx: &ResolveContext, table: &str) +pub fn prepare_game(ds: &DirSubst, prctx: &PathResolveContext, table: &str) -> InstanceName { let game_spec = ds.game_spec_path()?; let subst = ds.also(&[ ("table", table.to_owned()), - ("game_spec", rctx.resolve(&game_spec)), + ("game_spec", prctx.resolve(&game_spec)), ]); - ds.otter_rctx(rctx, &subst.ss( + ds.otter_prctx(prctx, &subst.ss( "--account server: \ reset \ --reset-table @specs@/test.table.toml \ diff --git a/apitest/at-otter.rs b/apitest/at-otter.rs index f1966f14..7cc94032 100644 --- a/apitest/at-otter.rs +++ b/apitest/at-otter.rs @@ -18,7 +18,7 @@ struct Ctx { spec: GameSpec, alice: Player, bob: Player, - rctx: ResolveContext, + prctx: PathResolveContext, } impl Ctx { @@ -205,10 +205,10 @@ impl Ctx { { let tmp = &(*self.su_rc).borrow().ds.abstmp.clone(); env::set_current_dir("/").expect("cd /"); - self.rctx = ResolveContext::RelativeTo(tmp.clone()); + self.prctx = PathResolveContext::RelativeTo(tmp.clone()); f(self).expect("run test"); env::set_current_dir(&tmp).expect("cd back"); - self.rctx = default(); + self.prctx = default(); } } @@ -489,12 +489,12 @@ impl Ctx { ["--account", "server:"].iter().cloned().map(Into::into) .chain(args.iter().map(|s| s.as_ref().to_owned())) .collect(); - self.su().ds.otter_rctx(&self.rctx, &args)?; + self.su().ds.otter_prctx(&self.prctx, &args)?; } #[throws(AE)] fn library_load(&mut self) { - prepare_game(&self.su().ds, &self.rctx, TABLE)?; + prepare_game(&self.su().ds, &self.prctx, TABLE)?; let command = self.su().ds.ss( "library-add @table@ wikimedia chess-blue-?" @@ -715,7 +715,7 @@ fn main() { drop(mc); let su_rc = Rc::new(RefCell::new(su)); - tests(Ctx { opts, spec, su_rc, alice, bob, rctx: default() })?; + tests(Ctx { opts, spec, su_rc, alice, bob, prctx: default() })?; } info!("ok"); } diff --git a/daemon/main.rs b/daemon/main.rs index 33251b0a..f0df055c 100644 --- a/daemon/main.rs +++ b/daemon/main.rs @@ -263,7 +263,7 @@ fn main() { let opts = Opts::from_args(); ServerConfig::read(opts.config_filename.as_ref().map(String::as_str), - ResolveMethod::ForServerReal)?; + PathResolveMethod::Chdir)?; std::env::set_var("ROCKET_CLI_COLORS", "off"); diff --git a/src/config.rs b/src/config.rs index 5daaa104..f4fae7b4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -65,37 +65,37 @@ pub struct ServerConfig { pub debug_js_inject: Arc, pub check_bundled_sources: bool, pub game_rng: RngWrap, - pub rctx: ResolveContext, + pub prctx: PathResolveContext, } #[derive(Debug,Copy,Clone)] -pub enum ResolveMethod { - ForServerReal, - Other, +pub enum PathResolveMethod { + Chdir, + Prefix, } -impl Default for ResolveMethod { fn default() -> Self { Self::Other } } +impl Default for PathResolveMethod { fn default() -> Self { Self::Prefix } } #[derive(Debug,Clone)] -pub enum ResolveContext { +pub enum PathResolveContext { RelativeTo(String), Noop, } -impl Default for ResolveContext { fn default() -> Self { Self::Noop } } +impl Default for PathResolveContext { fn default() -> Self { Self::Noop } } -impl ResolveMethod { +impl PathResolveMethod { #[throws(io::Error)] - fn chdir(self, cd: &str) -> ResolveContext { - use ResolveMethod::*; - use ResolveContext::*; + fn chdir(self, cd: &str) -> PathResolveContext { + use PathResolveMethod::*; + use PathResolveContext::*; match self { - ForServerReal => { env::set_current_dir(cd)?; Noop }, - Other if cd == "." => Noop, - Other => RelativeTo(cd.to_string()), + Chdir => { env::set_current_dir(cd)?; Noop }, + Prefix if cd == "." => Noop, + Prefix => RelativeTo(cd.to_string()), } } } -impl ResolveContext { +impl PathResolveContext { pub fn resolve(&self, input: &str) -> String { - use ResolveContext::*; + use PathResolveContext::*; match (self, input.as_bytes()) { (Noop , _ ) | (RelativeTo(_ ), &[b'/',..]) => input.to_owned(), @@ -106,7 +106,8 @@ impl ResolveContext { impl ServerConfigSpec { //#[throws(AE)] - pub fn resolve(self, rmeth: ResolveMethod) -> Result { + pub fn resolve(self, prmeth: PathResolveMethod) + -> Result { let ServerConfigSpec { change_directory, base_dir, save_dir, command_socket, debug, http_port, public_url, sse_wildcard_url, rocket_workers, @@ -117,17 +118,17 @@ impl ServerConfigSpec { let game_rng = fake_rng.make_game_rng(); - let rctx; + let prctx; if let Some(ref cd) = change_directory { - rctx = rmeth.chdir(cd) + prctx = prmeth.chdir(cd) .with_context(|| cd.clone()) .context("config change_directory")?; } else { - rctx = ResolveContext::Noop; + prctx = PathResolveContext::Noop; }; let defpath = |specd: Option, leaf: &str| -> String { - rctx.resolve(&specd.unwrap_or_else(|| match &base_dir { + prctx.resolve(&specd.unwrap_or_else(|| match &base_dir { Some(base) => format!("{}/{}", &base, &leaf), None => leaf.to_owned(), })) @@ -146,7 +147,7 @@ impl ServerConfigSpec { vec![ shapelib::Config1::PathGlob(glob) ] }); - let sendmail = rctx.resolve(&sendmail.unwrap_or_else( + let sendmail = prctx.resolve(&sendmail.unwrap_or_else( || DEFAULT_SENDMAIL_PROGRAM.into() )); @@ -221,7 +222,7 @@ impl ServerConfigSpec { http_port, public_url, sse_wildcard_url, rocket_workers, template_dir, nwtemplate_dir, wasm_dir, bundled_sources, shapelibs, sendmail, - debug_js_inject, check_bundled_sources, game_rng, rctx, + debug_js_inject, check_bundled_sources, game_rng, prctx, }; trace_dbg!("config resolved", &server); Ok(WholeServerConfig { @@ -244,7 +245,7 @@ fn set_config(whole: WholeServerConfig) { impl ServerConfig { #[throws(StartupError)] - pub fn read(config_filename: Option<&str>, rmeth: ResolveMethod) { + pub fn read(config_filename: Option<&str>, prmeth: PathResolveMethod) { let config_filename = config_filename.map(|s| s.to_string()) .unwrap_or_else( || format!("{}/{}", DEFAULT_CONFIG_DIR, DEFAULT_CONFIG_LEAFNAME) @@ -253,7 +254,7 @@ impl ServerConfig { File::open(&config_filename).with_context(||config_filename.to_string())? .read_to_string(&mut buf)?; let spec: ServerConfigSpec = toml_de::from_str(&buf)?; - let whole = spec.resolve(rmeth)?; + let whole = spec.resolve(prmeth)?; set_config(whole); }