mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
Improve error handling of default directory
This commit is contained in:
@@ -61,13 +61,24 @@ fn main() {
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let mut default_dir = dirs::home_dir().unwrap_or_else(|| PathBuf::from("."));
|
||||
default_dir.push(DEFAULT_DATA_DIR);
|
||||
|
||||
let data_dir = &matches
|
||||
let data_dir = match matches
|
||||
.value_of("datadir")
|
||||
.and_then(|v| Some(PathBuf::from(v)))
|
||||
.unwrap_or_else(|| PathBuf::from(default_dir));
|
||||
{
|
||||
Some(v) => v,
|
||||
None => {
|
||||
// use the default
|
||||
let mut default_dir = match dirs::home_dir() {
|
||||
Some(v) => v,
|
||||
None => {
|
||||
crit!(log, "Failed to find a home directory");
|
||||
return;
|
||||
}
|
||||
};
|
||||
default_dir.push(DEFAULT_DATA_DIR);
|
||||
PathBuf::from(default_dir)
|
||||
}
|
||||
};
|
||||
|
||||
// create the directory if needed
|
||||
match fs::create_dir_all(&data_dir) {
|
||||
|
||||
Reference in New Issue
Block a user