mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 08:16:32 +03:00
apply CR
This commit is contained in:
3372
Cargo.lock
generated
3372
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@ license = "MPL-2.0"
|
|||||||
rust-version = "1.57"
|
rust-version = "1.57"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
#debug = 0
|
debug = 0
|
||||||
panic = 'abort'
|
panic = 'abort'
|
||||||
opt-level = 1
|
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-share = { git = "https://github.com/n0-computer/iroh", branch = "main" }
|
||||||
iroh-resolver = { git = "https://github.com/n0-computer/iroh", branch = "main", default-features = false }
|
iroh-resolver = { git = "https://github.com/n0-computer/iroh", branch = "main", default-features = false }
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
multibase = "0.9.1"
|
multibase = "0.9"
|
||||||
|
port_check = "0.1.5"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
ansi_term = "0.12.0"
|
ansi_term = "0.12.0"
|
||||||
|
|||||||
@@ -477,10 +477,12 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
Some(arg2.to_string()),
|
Some(arg2.to_string()),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
println!("Exported to {}.", dir.to_string_lossy());
|
println!("Exported to {}.", dir.display());
|
||||||
}
|
}
|
||||||
"send-backup" => {
|
"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 transfer = send_backup(&context, dir.as_ref(), Some(arg1.to_string())).await?;
|
||||||
let ticket = transfer.ticket();
|
let ticket = transfer.ticket();
|
||||||
let ticket_bytes = ticket.as_bytes();
|
let ticket_bytes = ticket.as_bytes();
|
||||||
|
|||||||
25
src/imex.rs
25
src/imex.rs
@@ -5,8 +5,8 @@ use std::ffi::OsStr;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use ::pgp::types::KeyTrait;
|
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;
|
use futures::{StreamExt, TryStreamExt};
|
||||||
use futures_lite::FutureExt;
|
use futures_lite::FutureExt;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use tokio::fs::{self, File};
|
use tokio::fs::{self, File};
|
||||||
@@ -107,6 +107,10 @@ pub async fn imex(
|
|||||||
res
|
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(
|
pub async fn receive_backup(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
ticket_bytes: Vec<u8>,
|
ticket_bytes: Vec<u8>,
|
||||||
@@ -135,7 +139,7 @@ pub async fn receive_backup(
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn receive_backup_inner(
|
async fn receive_backup_inner(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
ticket_bytes: Vec<u8>,
|
ticket_bytes: Vec<u8>,
|
||||||
passphrase: String,
|
passphrase: String,
|
||||||
@@ -153,11 +157,12 @@ pub async fn receive_backup_inner(
|
|||||||
|
|
||||||
let recv_dir = tempfile::tempdir().unwrap();
|
let recv_dir = tempfile::tempdir().unwrap();
|
||||||
let recv_db = recv_dir.path().join("db");
|
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)
|
let receiver = Receiver::new(port, &recv_db)
|
||||||
.await
|
.await
|
||||||
.context("failed to create sender")?;
|
.context("failed to create receiver")?;
|
||||||
let mut receiver_transfer = receiver
|
let mut receiver_transfer = receiver
|
||||||
.transfer_from_ticket(&ticket)
|
.transfer_from_ticket(&ticket)
|
||||||
.await
|
.await
|
||||||
@@ -200,9 +205,10 @@ pub async fn receive_backup_inner(
|
|||||||
let name = link.name.unwrap_or_default();
|
let name = link.name.unwrap_or_default();
|
||||||
let path = out.join(&name);
|
let path = out.join(&name);
|
||||||
|
|
||||||
let mut file = tokio::fs::File::create(&path)
|
let file = tokio::fs::File::create(&path)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("create file: {}", path.display()))?;
|
.with_context(|| format!("create file: {}", path.display()))?;
|
||||||
|
let mut file = tokio::io::BufWriter::new(file);
|
||||||
let mut content = file_content.pretty()?;
|
let mut content = file_content.pretty()?;
|
||||||
tokio::io::copy(&mut content, &mut file)
|
tokio::io::copy(&mut content, &mut file)
|
||||||
.await
|
.await
|
||||||
@@ -232,6 +238,10 @@ pub async fn receive_backup_inner(
|
|||||||
Ok(())
|
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(
|
pub async fn send_backup(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
@@ -829,7 +839,8 @@ async fn export_backup_iroh(
|
|||||||
|
|
||||||
match res {
|
match res {
|
||||||
Ok(dir_builder) => {
|
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 sender = iroh_share::Sender::new(port, &sender_db_path).await?;
|
||||||
let transfer = sender.transfer_from_dir_builder(dir_builder).await?;
|
let transfer = sender.transfer_from_dir_builder(dir_builder).await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user