Skip to content

Commit 7715412

Browse files
committed
hide unused stuff depending on features
1 parent 585589f commit 7715412

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub mod rpc;
4646
pub mod store;
4747
pub mod util;
4848

49+
#[cfg(feature = "rpc")]
50+
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "rpc")))]
4951
pub mod node;
5052

5153
use bao_tree::BlockSize;

src/util/fs.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ use std::{
77

88
use anyhow::{bail, Context};
99
use bytes::Bytes;
10-
use iroh_net::key::SecretKey;
11-
use tokio::io::AsyncWriteExt;
12-
use walkdir::WalkDir;
13-
14-
use crate::rpc::client::blobs::WrapOption;
15-
1610
/// A data source
1711
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
1812
pub struct DataSource {
@@ -62,7 +56,12 @@ impl From<&std::path::Path> for DataSource {
6256
}
6357

6458
/// Create data sources from a path.
65-
pub fn scan_path(path: PathBuf, wrap: WrapOption) -> anyhow::Result<Vec<DataSource>> {
59+
#[cfg(feature = "rpc")]
60+
pub fn scan_path(
61+
path: PathBuf,
62+
wrap: crate::rpc::client::blobs::WrapOption,
63+
) -> anyhow::Result<Vec<DataSource>> {
64+
use crate::rpc::client::blobs::WrapOption;
6665
if path.is_dir() {
6766
scan_dir(path, wrap)
6867
} else {
@@ -75,12 +74,20 @@ pub fn scan_path(path: PathBuf, wrap: WrapOption) -> anyhow::Result<Vec<DataSour
7574
}
7675
}
7776

77+
#[cfg(feature = "rpc")]
78+
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "rpc")))]
7879
fn file_name(path: &Path) -> anyhow::Result<String> {
7980
relative_canonicalized_path_to_string(path.file_name().context("path is invalid")?)
8081
}
8182

8283
/// Create data sources from a directory.
83-
pub fn scan_dir(root: PathBuf, wrap: WrapOption) -> anyhow::Result<Vec<DataSource>> {
84+
#[cfg(feature = "rpc")]
85+
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "rpc")))]
86+
pub fn scan_dir(
87+
root: PathBuf,
88+
wrap: crate::rpc::client::blobs::WrapOption,
89+
) -> anyhow::Result<Vec<DataSource>> {
90+
use crate::rpc::client::blobs::WrapOption;
8491
if !root.is_dir() {
8592
bail!("Expected {} to be a file", root.to_string_lossy());
8693
}
@@ -89,7 +96,7 @@ pub fn scan_dir(root: PathBuf, wrap: WrapOption) -> anyhow::Result<Vec<DataSourc
8996
WrapOption::Wrap { name: None } => Some(file_name(&root)?),
9097
WrapOption::Wrap { name: Some(name) } => Some(name),
9198
};
92-
let files = WalkDir::new(&root).into_iter();
99+
let files = walkdir::WalkDir::new(&root).into_iter();
93100
let data_sources = files
94101
.map(|entry| {
95102
let entry = entry?;
@@ -121,13 +128,18 @@ pub fn relative_canonicalized_path_to_string(path: impl AsRef<Path>) -> anyhow::
121128

122129
/// Loads a [`SecretKey`] from the provided file, or stores a newly generated one
123130
/// at the given location.
124-
pub async fn load_secret_key(key_path: PathBuf) -> anyhow::Result<SecretKey> {
131+
#[cfg(feature = "rpc")]
132+
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "rpc")))]
133+
pub async fn load_secret_key(key_path: PathBuf) -> anyhow::Result<iroh_net::key::SecretKey> {
134+
use tokio::io::AsyncWriteExt;
135+
125136
if key_path.exists() {
126137
let keystr = tokio::fs::read(key_path).await?;
127-
let secret_key = SecretKey::try_from_openssh(keystr).context("invalid keyfile")?;
138+
let secret_key =
139+
iroh_net::key::SecretKey::try_from_openssh(keystr).context("invalid keyfile")?;
128140
Ok(secret_key)
129141
} else {
130-
let secret_key = SecretKey::generate();
142+
let secret_key = iroh_net::key::SecretKey::generate();
131143
let ser_key = secret_key.to_openssh()?;
132144

133145
// Try to canonicalize if possible

0 commit comments

Comments
 (0)