Skip to content

Commit

Permalink
Merge pull request #1049 from stlankes/file
Browse files Browse the repository at this point in the history
unlink is only able to delete a file
  • Loading branch information
stlankes authored Feb 4, 2024
2 parents 4936809 + 0ed88e0 commit 5f94a89
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 5f94a89

Please sign in to comment.