chiark / gitweb /
path resolution: Rename types and variables to mention Path
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 11:54:22 +0000 (12:54 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 11:54:22 +0000 (12:54 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/apitest.rs
apitest/at-otter.rs
daemon/main.rs
src/config.rs

index fac1f0273e22e3d6765a61dc76c3081c5cb19b62..187a87e47911e9ecc72c33ff77213f71fa11a8f5 100644 (file)
@@ -641,19 +641,19 @@ impl DirSubst {
   pub fn otter<'s,S>(&self, xargs: &'s [S])
   where &'s S: Into<String>
   {
-    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<String>
   {
     let ds = self;
     let exe = ds.subst("@target@/debug/otter")?;
     let specs = self.subst("@src@/specs")?;
     let mut args: Vec<String> = 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              \
index f1966f14bddef87ead37bf64c0109008e2154864..7cc94032176bdaa30984383410aadcf8f680e40c 100644 (file)
@@ -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");
 }
index 33251b0a5a492d5ab31cf322263e012491642ef1..f0df055c9f367fed7603c22c735533d093612abc 100644 (file)
@@ -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");
 
index 5daaa1045117e3abb33a49da1a7dae9bf16088ec..f4fae7b471ee4b85c48fb3503385442d268e7422 100644 (file)
@@ -65,37 +65,37 @@ pub struct ServerConfig {
   pub debug_js_inject: Arc<String>,
   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<WholeServerConfig,AE> {
+  pub fn resolve(self, prmeth: PathResolveMethod)
+                 -> Result<WholeServerConfig,AE> {
     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<String>, 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);
   }