Fixing newline issues in the protocol over OpenSSH

pmeunier
Jul 21, 2021, 11:54 AM
LJFJEX43HDS33O5HCRXH7AR3GTQZDHNWHEQBOERDNPNXR3B3XZ3QC

Dependencies

  • [2] A3RM526Y Integrating identity malleability
  • [3] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [4] UDHP4ZVB Fixing SSH asynchronicity issues
  • [5] JL4WKA5P Implement the Sanakirja concurrency model in a cross-process way

Change contents

  • replacement in pijul/src/remote/ssh.rs at line 638
    [2.2958][2.2958:3012]()
    let buf = if buf.is_empty() {
    [2.2958]
    [2.3012]
    let buf_ = if buf.is_empty() {
  • replacement in pijul/src/remote/ssh.rs at line 644
    [2.3186][2.3186:3323]()
    for data in data.split(|c| *c == 10) {
    if let Ok(p) = serde_json::from_slice(&buf) {
    [2.3186]
    [2.3323]
    for data in buf_.split(|c| *c == 10) {
    if let Ok(p) = serde_json::from_slice(data) {
  • edit in pijul/src/remote/ssh.rs at line 656
    [2.3814]
    [2.3814]
    buf.clear()
  • replacement in pijul/src/main.rs at line 200
    [3.88636][3.4706:4758]()
    SubCommand::Diff(diff) => diff.run().await,
    [3.88636]
    [3.88682]
    SubCommand::Diff(diff) => diff.run(),
  • replacement in pijul/src/commands/protocol.rs at line 258
    [2.16713][2.16713:19678]()
    let id = id?;
    let m = id.metadata()?;
    let p = id.path();
    debug!("{:?}", p);
    let mod_ts = m
    .modified()?
    .duration_since(std::time::SystemTime::UNIX_EPOCH)
    .unwrap()
    .as_secs();
    if mod_ts >= last_touched {
    let mut done = HashSet::new();
    if p.file_name() == Some("publickey.json".as_ref()) {
    let public_key: libpijul::key::PublicKey =
    if let Some(mut dir) = crate::config::global_config_dir() {
    dir.push("publickey.json");
    let mut pkf = std::fs::File::open(&dir)?;
    serde_json::from_reader(&mut pkf)?
    } else {
    continue;
    };
    if !done.insert(public_key.key.clone()) {
    continue;
    }
    if let Ok((config, last_modified)) = crate::config::Global::load() {
    serde_json::to_writer(
    &mut o,
    &crate::Identity {
    public_key,
    email: config.author.email,
    name: config.author.full_name,
    login: config.author.name,
    origin: String::new(),
    last_modified,
    },
    )
    .unwrap();
    writeln!(o)?;
    o.flush()?;
    } else {
    debug!("no global config");
    }
    } else {
    let mut idf = if let Ok(f) = std::fs::File::open(&p) {
    f
    } else {
    continue;
    };
    let id: Result<crate::Identity, _> = serde_json::from_reader(&mut idf);
    if let Ok(id) = id {
    if !done.insert(id.public_key.key.clone()) {
    continue;
    }
    serde_json::to_writer(&mut o, &id).unwrap();
    writeln!(o)?;
    o.flush()?;
    }
    }
    }
    [2.16713]
    [2.19678]
    output_id(id, last_touched, &mut o).unwrap_or(());
  • edit in pijul/src/commands/protocol.rs at line 285
    [3.133601]
    [3.133601]
    }
    }
    fn get_public_key() -> Result<libpijul::key::PublicKey, anyhow::Error> {
    if let Some(mut dir) = crate::config::global_config_dir() {
    dir.push("publickey.json");
    if let Ok(mut pkf) = std::fs::File::open(&dir) {
    if let Ok(pkf) = serde_json::from_reader(&mut pkf) {
    return Ok(pkf);
    }
    }
    }
    bail!("No public key found")
    }
    fn output_id<W: Write>(
    id: Result<std::fs::DirEntry, std::io::Error>,
    last_touched: u64,
    mut o: W,
    ) -> Result<(), anyhow::Error> {
    let id = id?;
    let m = id.metadata()?;
    let p = id.path();
    debug!("{:?}", p);
    let mod_ts = m
    .modified()?
    .duration_since(std::time::SystemTime::UNIX_EPOCH)
    .unwrap()
    .as_secs();
    if mod_ts >= last_touched {
    let mut done = HashSet::new();
    if p.file_name() == Some("publickey.json".as_ref()) {
    let public_key: libpijul::key::PublicKey = if let Ok(pk) = get_public_key() {
    pk
    } else {
    return Ok(());
    };
    if !done.insert(public_key.key.clone()) {
    return Ok(());
    }
    if let Ok((config, last_modified)) = crate::config::Global::load() {
    serde_json::to_writer(
    &mut o,
    &crate::Identity {
    public_key,
    email: config.author.email,
    name: config.author.full_name,
    login: config.author.name,
    origin: String::new(),
    last_modified,
    },
    )
    .unwrap();
    writeln!(o)?;
    } else {
    debug!("no global config");
    }
    } else {
    let mut idf = if let Ok(f) = std::fs::File::open(&p) {
    f
    } else {
    return Ok(());
    };
    let id: Result<crate::Identity, _> = serde_json::from_reader(&mut idf);
    if let Ok(id) = id {
    if !done.insert(id.public_key.key.clone()) {
    return Ok(());
    }
    serde_json::to_writer(&mut o, &id).unwrap();
    writeln!(o)?;
    }
    }
  • edit in pijul/src/commands/protocol.rs at line 358
    [3.133607]
    [3.133607]
    Ok(())