This commit is contained in:
dignifiedquire
2022-09-19 11:18:03 +02:00
parent 09d5cbe564
commit 26719ee358
6 changed files with 3149 additions and 259 deletions

3372
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@ license = "MPL-2.0"
rust-version = "1.57"
[profile.dev]
#debug = 0
debug = 0
panic = 'abort'
opt-level = 1
@@ -86,7 +86,8 @@ async_zip = { version = "0.0.9", default-features = false, features = ["deflate"
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"

View File

@@ -477,10 +477,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();

BIN
foo-shm Normal file

Binary file not shown.

BIN
foo-wal Normal file

Binary file not shown.

View File

@@ -5,8 +5,8 @@ use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use ::pgp::types::KeyTrait;
use anyhow::{bail, ensure, format_err, Context as _, Result};
use futures::StreamExt;
use anyhow::{anyhow, bail, ensure, format_err, Context as _, Result};
use futures::{StreamExt, TryStreamExt};
use futures_lite::FutureExt;
use rand::{thread_rng, Rng};
use tokio::fs::{self, File};
@@ -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>,
@@ -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,
@@ -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
@@ -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
@@ -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,
@@ -829,7 +839,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?;