rmdir, mkdir
This commit is contained in:
+45
-9
@@ -13,7 +13,7 @@ use image::Image;
|
||||
|
||||
use redoxfs::{FileSystem, Node};
|
||||
|
||||
use system::error::{Error, Result, EISDIR, EPERM, ENOENT, EBADF, EINVAL};
|
||||
use system::error::{Error, Result, EEXIST, EISDIR, ENOTDIR, EPERM, ENOENT, EBADF, EINVAL};
|
||||
use system::scheme::{Packet, Scheme};
|
||||
use system::syscall::{Stat, O_CREAT, SEEK_SET, SEEK_CUR, SEEK_END};
|
||||
|
||||
@@ -189,17 +189,53 @@ impl Scheme for FileScheme {
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
fn mkdir(&mut self, path: &str, mode: usize) -> Result<usize> {
|
||||
println!("mkdir {}, {:X}", path, mode);
|
||||
Err(Error::new(ENOENT))
|
||||
fn mkdir(&mut self, url: &str, mode: usize) -> Result<usize> {
|
||||
let path = url.split(':').nth(1).unwrap_or("").trim_matches('/');
|
||||
|
||||
let mut nodes = Vec::new();
|
||||
match self.path_nodes(path, &mut nodes) {
|
||||
Ok(_node) => Err(Error::new(EEXIST)),
|
||||
Err(err) => if err.errno == ENOENT {
|
||||
let mut last_part = String::new();
|
||||
for part in path.split('/') {
|
||||
if ! part.is_empty() {
|
||||
last_part = part.to_string();
|
||||
}
|
||||
}
|
||||
if ! last_part.is_empty() {
|
||||
if let Some(parent) = nodes.last() {
|
||||
self.fs.create_node(Node::MODE_DIR, &last_part, parent.0).and(Ok(0))
|
||||
} else {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
} else {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
} else {
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
fn rmdir(&mut self, path: &str) -> Result<usize> {
|
||||
println!("rmdir {}", path);
|
||||
Err(Error::new(ENOENT))
|
||||
fn rmdir(&mut self, url: &str) -> Result<usize> {
|
||||
let path = url.split(':').nth(1).unwrap_or("").trim_matches('/');
|
||||
|
||||
let mut nodes = Vec::new();
|
||||
let child = try!(self.path_nodes(path, &mut nodes));
|
||||
if let Some(parent) = nodes.last() {
|
||||
if child.1.is_dir() {
|
||||
if let Ok(child_name) = child.1.name() {
|
||||
self.fs.remove_node(Node::MODE_DIR, child_name, parent.0).and(Ok(0))
|
||||
} else {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
} else {
|
||||
Err(Error::new(ENOTDIR))
|
||||
}
|
||||
} else {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
fn unlink(&mut self, url: &str) -> Result<usize> {
|
||||
let path = url.split(':').nth(1).unwrap_or("").trim_matches('/');
|
||||
|
||||
Reference in New Issue
Block a user