From d5b41916cbeec36012a1f54491ed7b793a357c51 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Thu, 13 Jul 2023 23:50:52 -0500 Subject: [PATCH] Add extensions to check client/server compatibility --- distant-core/src/client/ext.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/distant-core/src/client/ext.rs b/distant-core/src/client/ext.rs index f65f0f0..bedbc64 100644 --- a/distant-core/src/client/ext.rs +++ b/distant-core/src/client/ext.rs @@ -44,8 +44,12 @@ pub trait DistantChannelExt { /// Creates a remote directory, optionally creating all parent components if specified fn create_dir(&mut self, path: impl Into, all: bool) -> AsyncReturn<'_, ()>; + /// Checks whether the `path` exists on the remote machine fn exists(&mut self, path: impl Into) -> AsyncReturn<'_, bool>; + /// Checks whether this client is compatible with the remote server + fn is_compatible(&mut self) -> AsyncReturn<'_, bool>; + /// Retrieves metadata about a path on a remote machine fn metadata( &mut self, @@ -136,6 +140,9 @@ pub trait DistantChannelExt { /// Retrieves server version information fn version(&mut self) -> AsyncReturn<'_, Version>; + /// Returns version of protocol that the client uses + fn protocol_version(&self) -> protocol::semver::Version; + /// Writes a remote file with the data from a collection of bytes fn write_file( &mut self, @@ -232,6 +239,15 @@ impl DistantChannelExt ) } + fn is_compatible(&mut self) -> AsyncReturn<'_, bool> { + make_body!(self, protocol::Request::Version {}, |data| match data { + protocol::Response::Version(version) => + Ok(protocol::is_compatible_with(&version.protocol_version)), + protocol::Response::Error(x) => Err(io::Error::from(x)), + _ => Err(mismatched_response()), + }) + } + fn metadata( &mut self, path: impl Into, @@ -453,6 +469,10 @@ impl DistantChannelExt }) } + fn protocol_version(&self) -> protocol::semver::Version { + protocol::PROTOCOL_VERSION + } + fn write_file( &mut self, path: impl Into,