This commit is contained in:
sxyazi 2024-06-02 02:36:47 +08:00
parent 72b483f0c5
commit 897eb54e98
No known key found for this signature in database
4 changed files with 11 additions and 16 deletions

View file

@ -100,14 +100,6 @@ impl<'a> Body<'a> {
}
}
#[inline]
pub fn as_hey(&self) -> Option<&BodyHey> {
match self {
Self::Hey(b) => Some(b),
_ => None,
}
}
#[inline]
pub fn with_receiver(self, receiver: u64) -> Payload<'a> {
Payload::new(self).with_receiver(receiver)

View file

@ -17,9 +17,6 @@ impl BodyHey {
pub fn owned(peers: HashMap<u64, Peer>) -> Body<'static> {
Self { peers, version: BodyHi::version() }.into()
}
#[inline]
pub fn match_version(&self) -> bool { self.version == BodyHi::version() }
}
impl From<BodyHey> for Body<'_> {

View file

@ -22,9 +22,7 @@ impl<'a> BodyHi<'a> {
}
#[inline]
pub(super) fn version() -> String {
format!("{} {}", env!("CARGO_PKG_VERSION"), env!("VERGEN_GIT_SHA"))
}
pub fn version() -> String { format!("{} {}", env!("CARGO_PKG_VERSION"), env!("VERGEN_GIT_SHA")) }
}
impl<'a> From<BodyHi<'a>> for Body<'a> {

View file

@ -77,11 +77,12 @@ impl Client {
writer.flush().await?;
drop(writer);
let mut version = None;
while let Ok(Some(line)) = lines.next_line().await {
match line.split(',').next() {
Some("hey") => {
if !Payload::from_str(&line)?.body.as_hey().is_some_and(|b| b.match_version()) {
bail!("Server version mismatch - `yazi` and `ya` must have the same version")
if let Ok(Body::Hey(hey)) = Payload::from_str(&line).map(|p| p.body) {
version = Some(hey.version);
}
}
Some("bye") => break,
@ -89,6 +90,13 @@ impl Client {
}
}
if version != Some(BodyHi::version()) {
bail!(
"Incompatible version - Yazi {} <==> Ya {}",
version.as_deref().unwrap_or("Unknown"),
BodyHi::version()
);
}
Ok(())
}