Skip to content

Commit aff8152

Browse files
authored
fix(iroh-net): unexpected cfg condition values / possible fix on netbsd (#2476)
## Description We had some CLI tests that had `#[cfg(feature = "fs-store")]`, but that feature doesn't exist in `iroh-cli`... so they were never compiled (and some related code needed for these tests was deleted. I reintroduced it). This also fixes what is likely a bug, where `#[cfg(target_arch = "netbsd")]` was used, but there is no "architecture" netbsd. Only an *OS* netbsd. ## Breaking Changes None ## Notes & open questions -- ## Change checklist - [X] Self-review. - ~~[ ] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant.~~ - ~~[ ] Tests if relevant.~~ - [X] All breaking changes documented.
1 parent b88dfa5 commit aff8152

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

iroh-cli/tests/cli.rs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,10 @@ fn cli_provide_tree() -> Result<()> {
108108
test_provide_get_loop(Input::Path(path), Output::Path)
109109
}
110110

111-
#[cfg(feature = "fs-store")]
112111
#[test]
113112
#[ignore = "flaky"]
114113
fn cli_provide_tree_resume() -> Result<()> {
115-
use iroh_blobs::store::file::test_support::{make_partial, MakePartialResult};
114+
use iroh::blobs::store::fs::test_support::{make_partial, MakePartialResult};
116115

117116
/// Get all matches for match group 1 (an explicitly defined match group)
118117
fn explicit_matches(matches: Vec<(usize, Vec<String>)>) -> Vec<String> {
@@ -214,11 +213,10 @@ fn cli_provide_tree_resume() -> Result<()> {
214213
Ok(())
215214
}
216215

217-
#[cfg(feature = "fs-store")]
218216
#[test]
219217
#[ignore = "flaky"]
220218
fn cli_provide_file_resume() -> Result<()> {
221-
use iroh_blobs::store::file::test_support::{make_partial, MakePartialResult};
219+
use iroh::blobs::store::fs::test_support::{make_partial, MakePartialResult};
222220

223221
/// Get all matches for match group 1 (an explicitly defined match group)
224222
fn explicit_matches(matches: Vec<(usize, Vec<String>)>) -> Vec<String> {
@@ -1034,3 +1032,51 @@ where
10341032

10351033
caps
10361034
}
1035+
1036+
fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> anyhow::Result<usize> {
1037+
let src = src.as_ref();
1038+
let dst = dst.as_ref();
1039+
std::fs::create_dir_all(dst)?;
1040+
let mut len = 0;
1041+
for entry in std::fs::read_dir(src)? {
1042+
let entry = entry.with_context(|| {
1043+
format!(
1044+
"failed to read directory entry in `{}`",
1045+
src.to_string_lossy()
1046+
)
1047+
})?;
1048+
let ty = entry.file_type().with_context(|| {
1049+
format!(
1050+
"failed to get file type for file `{}`",
1051+
entry.path().to_string_lossy()
1052+
)
1053+
})?;
1054+
let src = entry.path();
1055+
let dst = dst.join(entry.file_name());
1056+
if ty.is_dir() {
1057+
len += copy_dir_all(&src, &dst).with_context(|| {
1058+
format!(
1059+
"failed to copy directory `{}` to `{}`",
1060+
src.to_string_lossy(),
1061+
dst.to_string_lossy()
1062+
)
1063+
})?;
1064+
} else {
1065+
std::fs::copy(&src, &dst).with_context(|| {
1066+
format!(
1067+
"failed to copy file `{}` to `{}`",
1068+
src.to_string_lossy(),
1069+
dst.to_string_lossy()
1070+
)
1071+
})?;
1072+
len += 1;
1073+
}
1074+
}
1075+
Ok(len)
1076+
}
1077+
1078+
fn copy_blob_dirs(src: &Path, tgt: &Path) -> Result<()> {
1079+
let dir = &IrohPaths::BaoStoreDir;
1080+
copy_dir_all(dir.with_root(src), dir.with_root(tgt))?;
1081+
Ok(())
1082+
}

iroh-net/src/net/interfaces/bsd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ impl WireFormat {
374374
return Err(RouteError::InvalidMessage);
375375
}
376376

377-
#[cfg(target_arch = "netbsd")]
377+
#[cfg(target_os = "netbsd")]
378378
let index = u16_from_ne_range(data, 16..18)?;
379-
#[cfg(not(target_arch = "netbsd"))]
379+
#[cfg(not(target_os = "netbsd"))]
380380
let index = u16_from_ne_range(data, 12..14)?;
381381

382382
let addrs = parse_addrs(

0 commit comments

Comments
 (0)