Avoid unnecessary panic in todos
This commit is contained in:
parent
149fd2aa1f
commit
21ec79296e
1 changed files with 5 additions and 4 deletions
|
|
@ -508,8 +508,7 @@ impl SavedState {
|
||||||
{
|
{
|
||||||
project_dirs.data_dir().into()
|
project_dirs.data_dir().into()
|
||||||
} else {
|
} else {
|
||||||
std::env::current_dir()
|
std::env::current_dir().unwrap_or(std::path::PathBuf::new())
|
||||||
.expect("The current directory is not accessible")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
path.push("todos.json");
|
path.push("todos.json");
|
||||||
|
|
@ -538,9 +537,11 @@ impl SavedState {
|
||||||
.map_err(|_| SaveError::FormatError)?;
|
.map_err(|_| SaveError::FormatError)?;
|
||||||
|
|
||||||
let path = Self::path();
|
let path = Self::path();
|
||||||
let dir = path.parent().ok_or(SaveError::DirectoryError)?;
|
|
||||||
|
|
||||||
std::fs::create_dir_all(dir).map_err(|_| SaveError::DirectoryError)?;
|
if let Some(dir) = path.parent() {
|
||||||
|
std::fs::create_dir_all(dir)
|
||||||
|
.map_err(|_| SaveError::DirectoryError)?;
|
||||||
|
}
|
||||||
|
|
||||||
let mut file =
|
let mut file =
|
||||||
std::fs::File::create(path).map_err(|_| SaveError::FileError)?;
|
std::fs::File::create(path).map_err(|_| SaveError::FileError)?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue