Skip to content
Snippets Groups Projects
Commit 7f8776fa authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Do not allow rmdir when node has children

parent 66480133
No related branches found
No related tags found
No related merge requests found
...@@ -259,6 +259,13 @@ impl<E> FileSystem<E> { ...@@ -259,6 +259,13 @@ impl<E> FileSystem<E> {
pub fn remove_node(&mut self, mode: u16, name: &str, parent_block: u64) -> Result<bool, E> { pub fn remove_node(&mut self, mode: u16, name: &str, parent_block: u64) -> Result<bool, E> {
if let Some(mut node) = try!(self.find_node(name, parent_block)) { if let Some(mut node) = try!(self.find_node(name, parent_block)) {
if node.1.mode & Node::MODE_TYPE == mode { if node.1.mode & Node::MODE_TYPE == mode {
if node.1.is_dir() {
let mut children = Vec::new();
try!(self.child_nodes(&mut children, node.0));
if ! children.is_empty() {
return Ok(false);
}
}
if try!(self.remove_block(node.0, parent_block)) { if try!(self.remove_block(node.0, parent_block)) {
node.1 = Node::default(); node.1 = Node::default();
try!(self.disk.write_at(node.0, &node.1)); try!(self.disk.write_at(node.0, &node.1));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment