diff options
author | Ashley Mannix <ashleymannix@live.com.au> | 2017-05-28 19:20:10 +1000 |
---|---|---|
committer | Paul Masurel <paul.masurel@gmail.com> | 2017-05-29 18:29:39 +0900 |
commit | 1bcebdd29e7366e3b9d3179e2b08775ea4edc880 (patch) | |
tree | c39a04082b205d5714889eb289d71ce1f59be9f1 /src/directory/ram_directory.rs | |
parent | ed0333a404ba300b80d95594ec4132aedfa31116 (diff) |
initial error-chain
Diffstat (limited to 'src/directory/ram_directory.rs')
-rw-r--r-- | src/directory/ram_directory.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/directory/ram_directory.rs b/src/directory/ram_directory.rs index 656eb73..1deb758 100644 --- a/src/directory/ram_directory.rs +++ b/src/directory/ram_directory.rs @@ -6,7 +6,7 @@ use std::result; use std::sync::{Arc, RwLock}; use common::make_io_err; use directory::{Directory, ReadOnlySource}; -use directory::error::{OpenWriteError, OpenReadError, DeleteError}; +use directory::error::{IOError, OpenWriteError, OpenReadError, DeleteError}; use directory::WritePtr; use super::shared_vec_slice::SharedVecSlice; @@ -97,7 +97,7 @@ impl InnerDirectory { directory when trying to read {:?}", path); let io_err = make_io_err(msg); - OpenReadError::IOError(io_err) + OpenReadError::IOError(IOError::with_path(path.to_owned(), io_err)) }) .and_then(|readable_map| { readable_map @@ -115,7 +115,7 @@ impl InnerDirectory { directory when trying to delete {:?}", path); let io_err = make_io_err(msg); - DeleteError::IOError(io_err) + DeleteError::IOError(IOError::with_path(path.to_owned(), io_err)) }) .and_then(|mut writable_map| match writable_map.remove(path) { Some(_) => Ok(()), @@ -163,8 +163,11 @@ impl Directory for RAMDirectory { fn open_write(&mut self, path: &Path) -> Result<WritePtr, OpenWriteError> { let path_buf = PathBuf::from(path); let vec_writer = VecWriter::new(path_buf.clone(), self.fs.clone()); + + let exists = self.fs.write(path_buf.clone(), &Vec::new()).map_err(|err| IOError::with_path(path.to_owned(), err))?; + // force the creation of the file to mimic the MMap directory. - if try!(self.fs.write(path_buf.clone(), &Vec::new())) { + if exists { Err(OpenWriteError::FileAlreadyExists(path_buf)) } else { Ok(BufWriter::new(Box::new(vec_writer))) |