Skip to content

Commit 6d1312c

Browse files
committed
fix: read non existant directory
1 parent c1d3291 commit 6d1312c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/core/src/services/computer/engine.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ impl ComputerStorageEngine {
2525

2626
pub fn tasks(&self, list_id: &str) -> anyhow::Result<Vec<Task>> {
2727
let mut tasks = vec![];
28-
for entry in self.tasks_path().join(list_id).read_dir()? {
28+
let path = self.tasks_path().join(list_id);
29+
if !path.exists() {
30+
return Ok(tasks);
31+
}
32+
for entry in path.read_dir()? {
2933
let entry = entry?;
3034
let path = entry.path();
3135
let content = std::fs::read_to_string(&path)?;
@@ -37,6 +41,10 @@ impl ComputerStorageEngine {
3741

3842
pub fn lists(&self) -> anyhow::Result<Vec<List>> {
3943
let mut tasks = vec![];
44+
let path = self.lists_path();
45+
if !path.exists() {
46+
return Ok(tasks);
47+
}
4048
for entry in self.lists_path().read_dir()? {
4149
let entry = entry?;
4250
let path = entry.path();
@@ -142,8 +150,10 @@ impl ComputerStorageEngine {
142150

143151
pub fn delete_list(&self, list_id: &str) -> anyhow::Result<()> {
144152
let path = self.lists_path().join(list_id).with_extension("ron");
153+
let tasks = self.tasks_path().join(list_id);
145154
if path.exists() {
146155
std::fs::remove_file(path)?;
156+
std::fs::remove_dir_all(tasks)?;
147157
Ok(())
148158
} else {
149159
Err(anyhow::anyhow!("List does not exist"))

0 commit comments

Comments
 (0)