@@ -7,12 +7,6 @@ use std::{
7
7
8
8
use anyhow:: { bail, Context } ;
9
9
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
-
16
10
/// A data source
17
11
#[ derive( Debug , PartialEq , Eq , PartialOrd , Ord , Clone ) ]
18
12
pub struct DataSource {
@@ -62,7 +56,12 @@ impl From<&std::path::Path> for DataSource {
62
56
}
63
57
64
58
/// 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 ;
66
65
if path. is_dir ( ) {
67
66
scan_dir ( path, wrap)
68
67
} else {
@@ -75,12 +74,20 @@ pub fn scan_path(path: PathBuf, wrap: WrapOption) -> anyhow::Result<Vec<DataSour
75
74
}
76
75
}
77
76
77
+ #[ cfg( feature = "rpc" ) ]
78
+ #[ cfg_attr( iroh_docsrs, doc( cfg( feature = "rpc" ) ) ) ]
78
79
fn file_name ( path : & Path ) -> anyhow:: Result < String > {
79
80
relative_canonicalized_path_to_string ( path. file_name ( ) . context ( "path is invalid" ) ?)
80
81
}
81
82
82
83
/// 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 ;
84
91
if !root. is_dir ( ) {
85
92
bail ! ( "Expected {} to be a file" , root. to_string_lossy( ) ) ;
86
93
}
@@ -89,7 +96,7 @@ pub fn scan_dir(root: PathBuf, wrap: WrapOption) -> anyhow::Result<Vec<DataSourc
89
96
WrapOption :: Wrap { name : None } => Some ( file_name ( & root) ?) ,
90
97
WrapOption :: Wrap { name : Some ( name) } => Some ( name) ,
91
98
} ;
92
- let files = WalkDir :: new ( & root) . into_iter ( ) ;
99
+ let files = walkdir :: WalkDir :: new ( & root) . into_iter ( ) ;
93
100
let data_sources = files
94
101
. map ( |entry| {
95
102
let entry = entry?;
@@ -121,13 +128,18 @@ pub fn relative_canonicalized_path_to_string(path: impl AsRef<Path>) -> anyhow::
121
128
122
129
/// Loads a [`SecretKey`] from the provided file, or stores a newly generated one
123
130
/// 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
+
125
136
if key_path. exists ( ) {
126
137
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" ) ?;
128
140
Ok ( secret_key)
129
141
} else {
130
- let secret_key = SecretKey :: generate ( ) ;
142
+ let secret_key = iroh_net :: key :: SecretKey :: generate ( ) ;
131
143
let ser_key = secret_key. to_openssh ( ) ?;
132
144
133
145
// Try to canonicalize if possible
0 commit comments