Commit 924adef1 authored by Deepak Sirone's avatar Deepak Sirone

Update path after frename

parent 602a63ac
......@@ -13,6 +13,7 @@ use filesystem::FileSystem;
pub trait Resource<D: Disk> {
fn block(&self) -> u64;
fn dup(&self) -> Result<Box<Resource<D>>>;
fn set_path(&mut self, path: &str);
fn read(&mut self, buf: &mut [u8], fs: &mut FileSystem<D>) -> Result<usize>;
fn write(&mut self, buf: &[u8], fs: &mut FileSystem<D>) -> Result<usize>;
fn seek(&mut self, offset: usize, whence: usize, fs: &mut FileSystem<D>) -> Result<usize>;
......@@ -63,6 +64,10 @@ impl<D: Disk> Resource<D> for DirResource {
}))
}
fn set_path(&mut self, path: &str) {
self.path = path.to_string();
}
fn read(&mut self, buf: &mut [u8], _fs: &mut FileSystem<D>) -> Result<usize> {
let data = self.data.as_ref().ok_or(Error::new(EISDIR))?;
let mut i = 0;
......@@ -284,6 +289,10 @@ impl<D: Disk> Resource<D> for FileResource {
}))
}
fn set_path(&mut self, path: &str) {
self.path = path.to_string();
}
fn read(&mut self, buf: &mut [u8], fs: &mut FileSystem<D>) -> Result<usize> {
if self.flags & O_ACCMODE == O_RDWR || self.flags & O_ACCMODE == O_RDONLY {
let count = fs.read_node(self.block, self.seek, buf)?;
......
......@@ -522,8 +522,8 @@ impl<D: Disk> Scheme for FileScheme<D> {
// println!("Frename {}, {} from {}, {}", id, path, uid, gid);
let files = self.files.borrow_mut();
if let Some(file) = files.get(&id) {
let mut files = self.files.borrow_mut();
if let Some(file) = files.get_mut(&id) {
//TODO: Check for EINVAL
// The new pathname contained a path prefix of the old, or, more generally,
// an attempt was made to make a directory a subdirectory of itself.
......@@ -607,6 +607,7 @@ impl<D: Disk> Scheme for FileScheme<D> {
fs.insert_blocks(orig.0, BLOCK_SIZE, parent.0)?;
}
file.set_path(path);
Ok(0)
} else {
Err(Error::new(EPERM))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment