Comments
Patch
@@ -20,8 +20,15 @@ use tokio_hglib::UnixClient;
use tokio_process::{Child, CommandExt};
use tokio_timer;
+use super::message::ServerSpec;
use super::procutil;
+const REQUIRED_SERVER_CAPABILITIES: &[&str] = &[
+ "attachio",
+ "chdir",
+ "runcommand",
+];
+
/// Helper to connect to and spawn a server process.
#[derive(Clone, Debug)]
pub struct Locator {
@@ -75,6 +82,10 @@ impl Locator {
Err(_) => Either::B(self.spawn_connect()),
}
})
+ .and_then(|(loc, client)| {
+ check_server_capabilities(client.server_spec())?;
+ Ok((loc, client))
+ })
}
/// Spawns new server process and connects to it.
@@ -222,3 +233,15 @@ fn check_secure_dir<P>(path: P) -> io::R
Err(io::Error::new(io::ErrorKind::Other, "insecure directory"))
}
}
+
+fn check_server_capabilities(spec: &ServerSpec) -> io::Result<()> {
+ let unsupported: Vec<_> = REQUIRED_SERVER_CAPABILITIES.iter().cloned()
+ .filter(|&s| !spec.capabilities.contains(s))
+ .collect();
+ if unsupported.is_empty() {
+ Ok(())
+ } else {
+ let msg = format!("insufficient server capabilities: {}", unsupported.join(", "));
+ Err(io::Error::new(io::ErrorKind::Other, msg))
+ }
+}