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); } }