From 0ed88e0d432f914b49153e20c2b82fe98edeedf7 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 4 Feb 2024 23:17:23 +0100 Subject: [PATCH] unlink is only able to delete a file - add check if the directory entry is a file --- src/fs/mem.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/fs/mem.rs b/src/fs/mem.rs index f482d011b5..6b80376a75 100644 --- a/src/fs/mem.rs +++ b/src/fs/mem.rs @@ -352,10 +352,6 @@ impl VfsNode for MemDirectory { if let Some(component) = components.pop() { let node_name = String::from(component); - if let Some(directory) = self.inner.read().get(&node_name) { - return directory.traverse_rmdir(components); - } - if components.is_empty() { let mut guard = self.inner.write(); @@ -366,6 +362,8 @@ impl VfsNode for MemDirectory { guard.insert(node_name, obj); return Err(IoError::ENOTDIR); } + } else if let Some(directory) = self.inner.read().get(&node_name) { + return directory.traverse_rmdir(components); } } @@ -376,20 +374,18 @@ impl VfsNode for MemDirectory { if let Some(component) = components.pop() { let node_name = String::from(component); - if let Some(directory) = self.inner.read().get(&node_name) { - return directory.traverse_unlink(components); - } - if components.is_empty() { let mut guard = self.inner.write(); let obj = guard.remove(&node_name).ok_or(IoError::ENOENT)?; - if obj.get_kind() == NodeKind::Directory { - guard.insert(node_name, obj); - return Err(IoError::EISDIR); - } else { + if obj.get_kind() == NodeKind::File { return Ok(()); + } else { + guard.insert(node_name, obj); + return Err(IoError::ENOENT); } + } else if let Some(directory) = self.inner.read().get(&node_name) { + return directory.traverse_unlink(components); } }