##// END OF EJS Templates
rust-chg: abort if server doesn't have required capabilities...
Yuya Nishihara -
r45162:7bf45ed9 default
parent child Browse files
Show More
@@ -20,8 +20,11 b' use tokio_hglib::UnixClient;'
20 20 use tokio_process::{Child, CommandExt};
21 21 use tokio_timer;
22 22
23 use super::message::ServerSpec;
23 24 use super::procutil;
24 25
26 const REQUIRED_SERVER_CAPABILITIES: &[&str] = &["attachio", "chdir", "runcommand"];
27
25 28 /// Helper to connect to and spawn a server process.
26 29 #[derive(Clone, Debug)]
27 30 pub struct Locator {
@@ -68,10 +71,15 b' impl Locator {'
68 71 /// Tries to connect to the existing server, or spawns new if not running.
69 72 fn try_connect(self) -> impl Future<Item = (Self, UnixClient), Error = io::Error> {
70 73 debug!("try connect to {}", self.base_sock_path.display());
71 UnixClient::connect(self.base_sock_path.clone()).then(|res| match res {
72 Ok(client) => Either::A(future::ok((self, client))),
73 Err(_) => Either::B(self.spawn_connect()),
74 })
74 UnixClient::connect(self.base_sock_path.clone())
75 .then(|res| match res {
76 Ok(client) => Either::A(future::ok((self, client))),
77 Err(_) => Either::B(self.spawn_connect()),
78 })
79 .and_then(|(loc, client)| {
80 check_server_capabilities(client.server_spec())?;
81 Ok((loc, client))
82 })
75 83 }
76 84
77 85 /// Spawns new server process and connects to it.
@@ -239,3 +247,20 b' where'
239 247 Err(io::Error::new(io::ErrorKind::Other, "insecure directory"))
240 248 }
241 249 }
250
251 fn check_server_capabilities(spec: &ServerSpec) -> io::Result<()> {
252 let unsupported: Vec<_> = REQUIRED_SERVER_CAPABILITIES
253 .iter()
254 .cloned()
255 .filter(|&s| !spec.capabilities.contains(s))
256 .collect();
257 if unsupported.is_empty() {
258 Ok(())
259 } else {
260 let msg = format!(
261 "insufficient server capabilities: {}",
262 unsupported.join(", ")
263 );
264 Err(io::Error::new(io::ErrorKind::Other, msg))
265 }
266 }
General Comments 0
You need to be logged in to leave comments. Login now