Skip to content

Commit

Permalink
apply CR
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Sep 19, 2022
1 parent c3ae7d4 commit edeb36d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MPL-2.0"
rust-version = "1.56"

[profile.dev]
#debug = 0
debug = 0
panic = 'abort'
opt-level = 1

Expand Down Expand Up @@ -83,7 +83,8 @@ async_zip = { git = "https://github.com/dignifiedquire/rs-async-zip", branch = "
iroh-share = { git = "https://github.com/n0-computer/iroh", branch = "main" }
iroh-resolver = { git = "https://github.com/n0-computer/iroh", branch = "main", default-features = false }
tempfile = "3"
multibase = "0.9.1"
multibase = "0.9"
port_check = "0.1.5"

[dev-dependencies]
ansi_term = "0.12.0"
Expand Down
6 changes: 4 additions & 2 deletions examples/repl/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,12 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
Some(arg2.to_string()),
)
.await?;
println!("Exported to {}.", dir.to_string_lossy());
println!("Exported to {}.", dir.display());
}
"send-backup" => {
let dir = dirs::home_dir().unwrap_or_default();
let tdir = tempfile::TempDir::new()?;
let dir = tdir.path();
println!("Storing backup in: {} ", dir.display());
let transfer = send_backup(&context, dir.as_ref(), Some(arg1.to_string())).await?;
let ticket = transfer.ticket();
let ticket_bytes = ticket.as_bytes();
Expand Down
Binary file added foo-shm
Binary file not shown.
Binary file added foo-wal
Binary file not shown.
23 changes: 17 additions & 6 deletions src/imex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ffi::OsStr;
use std::path::{Path, PathBuf};

use ::pgp::types::KeyTrait;
use anyhow::{bail, ensure, format_err, Context as _, Result};
use anyhow::{anyhow, bail, ensure, format_err, Context as _, Result};
use futures::{StreamExt, TryStreamExt};
use futures_lite::FutureExt;
use rand::{thread_rng, Rng};
Expand Down Expand Up @@ -107,6 +107,10 @@ pub async fn imex(
res
}

/// Receives a backup, as sent from `send_backup`.
///
/// Only one receive-progress can run at the same time.
/// To cancel a receive-progress, drop the future returned by this function.
pub async fn receive_backup(
context: &Context,
ticket_bytes: Vec<u8>,
Expand Down Expand Up @@ -135,7 +139,7 @@ pub async fn receive_backup(
res
}

pub async fn receive_backup_inner(
async fn receive_backup_inner(
context: &Context,
ticket_bytes: Vec<u8>,
passphrase: String,
Expand All @@ -153,11 +157,12 @@ pub async fn receive_backup_inner(

let recv_dir = tempfile::tempdir().unwrap();
let recv_db = recv_dir.path().join("db");
let port = 9991;
let port = port_check::free_local_port()
.ok_or_else(|| anyhow!("failed to find free local port to bind to"))?;

let receiver = Receiver::new(port, &recv_db)
.await
.context("failed to create sender")?;
.context("failed to create receiver")?;
let mut receiver_transfer = receiver
.transfer_from_ticket(&ticket)
.await
Expand Down Expand Up @@ -200,9 +205,10 @@ pub async fn receive_backup_inner(
let name = link.name.unwrap_or_default();
let path = out.join(&name);

let mut file = tokio::fs::File::create(&path)
let file = tokio::fs::File::create(&path)
.await
.with_context(|| format!("create file: {}", path.display()))?;
let mut file = tokio::io::BufWriter::new(file);
let mut content = file_content.pretty()?;
tokio::io::copy(&mut content, &mut file)
.await
Expand Down Expand Up @@ -232,6 +238,10 @@ pub async fn receive_backup_inner(
Ok(())
}

/// Send a backup.
///
/// Only one send-progress can run at the same time.
/// To cancel a send-progress, drop the future returned by this function.
pub async fn send_backup(
context: &Context,
path: &Path,
Expand Down Expand Up @@ -832,7 +842,8 @@ async fn export_backup_iroh(

match res {
Ok(dir_builder) => {
let port = 9990;
let port = port_check::free_local_port()
.ok_or_else(|| anyhow!("failed to find free local port to bind to"))?;
let sender = iroh_share::Sender::new(port, &sender_db_path).await?;
let transfer = sender.transfer_from_dir_builder(dir_builder).await?;

Expand Down

0 comments on commit edeb36d

Please sign in to comment.