diff --git a/Cargo.lock b/Cargo.lock index 45c1b0f..51fb5ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -280,14 +280,14 @@ dependencies = [ [[package]] name = "bao-tree" -version = "0.13.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f7a89a8ee5889d2593ae422ce6e1bb03e48a0e8a16e4fa0882dfcbe7e182ef" +checksum = "ff16d65e48353db458be63ee395c03028f24564fd48668389bd65fd945f5ac36" dependencies = [ + "blake3", "bytes", "futures-lite", "genawaiter", - "iroh-blake3", "iroh-io", "positioned-io", "range-collections", @@ -331,6 +331,19 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" +[[package]] +name = "blake3" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389a099b34312839e16420d499a9cad9650541715937ffbdd40d36f49e77eeb3" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -2036,28 +2049,14 @@ dependencies = [ "url", ] -[[package]] -name = "iroh-blake3" -version = "1.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbba31f40a650f58fa28dd585a8ca76d8ae3ba63aacab4c8269004a0c803930" -dependencies = [ - "arrayref", - "arrayvec", - "cc", - "cfg-if", - "constant_time_eq", -] - [[package]] name = "iroh-blobs" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d7a6872c7ec4a2613d0386b4dc19b5f3cf4822d81361c5136a63fd56ba2372" +version = "0.34.1" dependencies = [ "anyhow", "async-channel", "bao-tree", + "blake3", "bytes", "chrono", "data-encoding", @@ -2070,7 +2069,6 @@ dependencies = [ "hex", "iroh", "iroh-base", - "iroh-blake3", "iroh-io", "iroh-metrics", "nested_enum_utils", @@ -2103,9 +2101,9 @@ dependencies = [ [[package]] name = "iroh-io" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17e302c5ad649c6a7aa9ae8468e1c4dc2469321af0c6de7341c1be1bdaab434b" +checksum = "e0a5feb781017b983ff1b155cd1faf8174da2acafd807aa482876da2d7e6577a" dependencies = [ "bytes", "futures-lite", diff --git a/Cargo.toml b/Cargo.toml index d8c647e..a97261a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ derive_more = { version = "1.0.0", features = [ futures-buffered = "0.2.4" futures-lite = "2.3.0" indicatif = "0.17.7" -iroh-blobs = { version = "0.34", features = ["net_protocol"] } +iroh-blobs = { version = "0.34.1", features = ["net_protocol"], path = "../iroh-blobs" } iroh-io = "0.6" iroh = "0.34" num_cpus = "1.16.0" diff --git a/src/main.rs b/src/main.rs index 2ead104..5082777 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,15 @@ //! Command line arguments. +use std::{ + collections::BTreeMap, + fmt::{Display, Formatter}, + net::{SocketAddrV4, SocketAddrV6}, + path::{Component, Path, PathBuf}, + str::FromStr, + sync::Arc, + time::Duration, +}; + use anyhow::Context; use arboard::Clipboard; use clap::{ @@ -32,15 +42,6 @@ use iroh_blobs::{ use n0_future::{future::Boxed, StreamExt}; use rand::Rng; use serde::{Deserialize, Serialize}; -use std::{ - collections::BTreeMap, - fmt::{Display, Formatter}, - net::{SocketAddrV4, SocketAddrV6}, - path::{Component, Path, PathBuf}, - str::FromStr, - sync::Arc, - time::Duration, -}; use walkdir::WalkDir; /// Send a file or directory between two machines, using blake3 verified streaming. @@ -98,6 +99,7 @@ pub enum Commands { Send(SendArgs), /// Receive a file or directory. + #[clap(visible_alias = "recv")] Receive(ReceiveArgs), } @@ -610,6 +612,10 @@ async fn send(args: SendArgs) -> anyhow::Result<()> { ); std::process::exit(1); } + if cwd.join(&args.path) == cwd { + println!("can not share from the current directory"); + std::process::exit(1); + } tokio::fs::create_dir_all(&blobs_data_dir).await?; diff --git a/tests/cli.rs b/tests/cli.rs index 7ef738c..2f37892 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -136,3 +136,55 @@ fn send_recv_dir() { } } } + +#[test] +fn send_send_current() { + let src_dir = tempfile::tempdir().unwrap(); + let output = duct::cmd(sendme_bin(), ["send", "."]) + .dir(src_dir.path()) + .env_remove("RUST_LOG") // disable tracing + .stderr_to_stdout() + .unchecked() + .run() + .unwrap(); + // attempting to send the current directory should fail + assert_eq!(output.status.code(), Some(1)); +} + +#[test] +fn send_recv_modified() { + let name = "somefile.bin"; + let data = vec![0u8; 20000]; + let data2 = vec![1u8; 20000]; + // create src and tgt dir, and src file + let src_dir = tempfile::tempdir().unwrap(); + let tgt_dir = tempfile::tempdir().unwrap(); + let src_file = src_dir.path().join(name); + std::fs::write(&src_file, &data).unwrap(); + let mut send_cmd = duct::cmd( + sendme_bin(), + ["send", src_file.as_os_str().to_str().unwrap()], + ) + .dir(src_dir.path()) + .env_remove("RUST_LOG") // disable tracing + .stderr_to_stdout() + .reader() + .unwrap(); + let output = read_ascii_lines(3, &mut send_cmd).unwrap(); + let output = String::from_utf8(output).unwrap(); + let ticket = output.split_ascii_whitespace().last().unwrap(); + let ticket = BlobTicket::from_str(ticket).unwrap(); + + // modify the file + std::fs::write(&src_file, &data2).unwrap(); + + // check that download fails + let receive_output = duct::cmd(sendme_bin(), ["receive", &ticket.to_string()]) + .dir(tgt_dir.path()) + .env_remove("RUST_LOG") // disable tracing + .stderr_to_stdout() + .unchecked() + .run() + .unwrap(); + assert_eq!(receive_output.status.code(), Some(1)); +}