Skip to content

fix: Fix hazmat panic #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 15 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -98,6 +99,7 @@ pub enum Commands {
Send(SendArgs),

/// Receive a file or directory.
#[clap(visible_alias = "recv")]
Receive(ReceiveArgs),
}

Expand Down Expand Up @@ -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?;

Expand Down
52 changes: 52 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Loading