@@ -8,7 +8,7 @@ use std::{
8
8
} ,
9
9
} ;
10
10
11
- use anyhow:: Result ;
11
+ use anyhow:: { anyhow , Result } ;
12
12
use cid:: {
13
13
multihash:: { Code , MultihashDigest } ,
14
14
Cid ,
@@ -53,15 +53,16 @@ pub async fn block_until_sigint() {
53
53
/// | Linux | `$XDG_CONFIG_HOME` or `$HOME`/.config/iroh | /home/alice/.config/iroh |
54
54
/// | macOS | `$HOME`/Library/Application Support/iroh | /Users/Alice/Library/Application Support/iroh |
55
55
/// | Windows | `{FOLDERID_RoamingAppData}`/iroh | C:\Users\Alice\AppData\Roaming\iroh |
56
- pub fn iroh_config_root ( ) -> Option < PathBuf > {
57
- let cfg = dirs_next:: config_dir ( ) ?;
58
- Some ( cfg. join ( & IROH_DIR ) )
56
+ pub fn iroh_config_root ( ) -> Result < PathBuf > {
57
+ let cfg = dirs_next:: config_dir ( )
58
+ . ok_or_else ( || anyhow ! ( "operating environment provides no directory for configuration" ) ) ?;
59
+ Ok ( cfg. join ( & IROH_DIR ) )
59
60
}
60
61
61
62
// Path that leads to a file in the iroh config directory.
62
- pub fn iroh_config_path ( file_name : & str ) -> Option < PathBuf > {
63
+ pub fn iroh_config_path ( file_name : & str ) -> Result < PathBuf > {
63
64
let path = iroh_config_root ( ) ?. join ( file_name) ;
64
- Some ( path)
65
+ Ok ( path)
65
66
}
66
67
67
68
/// Returns the path to the user's iroh data directory.
@@ -73,15 +74,17 @@ pub fn iroh_config_path(file_name: &str) -> Option<PathBuf> {
73
74
/// | Linux | `$XDG_DATA_HOME`/iroh or `$HOME`/.local/share/iroh | /home/alice/.local/share/iroh |
74
75
/// | macOS | `$HOME`/Library/Application Support/iroh | /Users/Alice/Library/Application Support/iroh |
75
76
/// | Windows | `{FOLDERID_RoamingAppData}/iroh` | C:\Users\Alice\AppData\Roaming\iroh |
76
- pub fn iroh_data_root ( ) -> Option < PathBuf > {
77
- let path = dirs_next:: data_dir ( ) ?;
78
- Some ( path. join ( & IROH_DIR ) )
77
+ pub fn iroh_data_root ( ) -> Result < PathBuf > {
78
+ let path = dirs_next:: data_dir ( ) . ok_or_else ( || {
79
+ anyhow ! ( "operating environment provides no directory for application data" )
80
+ } ) ?;
81
+ Ok ( path. join ( & IROH_DIR ) )
79
82
}
80
83
81
- // Path that leads to a file in the iroh data directory.
82
- pub fn iroh_data_path ( file_name : & str ) -> Option < PathBuf > {
84
+ /// Path that leads to a file in the iroh data directory.
85
+ pub fn iroh_data_path ( file_name : & str ) -> Result < PathBuf > {
83
86
let path = iroh_data_root ( ) ?. join ( file_name) ;
84
- Some ( path)
87
+ Ok ( path)
85
88
}
86
89
87
90
/// insert a value into a `config::Map`
0 commit comments