@@ -7,12 +7,6 @@ use std::{
77
88use anyhow:: { bail, Context } ;
99use 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 ) ]
1812pub 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" ) ) ) ]
7879fn 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