Skip to content

Commit

Permalink
unlink is only able to delete a file
Browse files Browse the repository at this point in the history
- add check if the directory entry is a file
  • Loading branch information
stlankes committed Feb 4, 2024
1 parent 4936809 commit 0ed88e0
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/fs/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down

0 comments on commit 0ed88e0

Please sign in to comment.