Introduce error if the store path exists but is a file
This commit is contained in:
parent
4f71563eb4
commit
80b0501d03
2 changed files with 15 additions and 11 deletions
|
@ -15,17 +15,19 @@ pub enum StoreErrorKind {
|
|||
OutOfMemory,
|
||||
FileNotFound,
|
||||
FileNotCreated,
|
||||
StorePathExists,
|
||||
// maybe more
|
||||
}
|
||||
|
||||
fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str {
|
||||
match e {
|
||||
&StoreErrorKind::FileError => "File Error",
|
||||
&StoreErrorKind::IdLocked => "ID locked",
|
||||
&StoreErrorKind::IdNotFound => "ID not found",
|
||||
&StoreErrorKind::OutOfMemory => "Out of Memory",
|
||||
&StoreErrorKind::FileNotFound => "File corresponding to ID not found",
|
||||
&StoreErrorKind::FileNotCreated => "File corresponding to ID could not be created",
|
||||
&StoreErrorKind::FileError => "File Error",
|
||||
&StoreErrorKind::IdLocked => "ID locked",
|
||||
&StoreErrorKind::IdNotFound => "ID not found",
|
||||
&StoreErrorKind::OutOfMemory => "Out of Memory",
|
||||
&StoreErrorKind::FileNotFound => "File corresponding to ID not found",
|
||||
&StoreErrorKind::FileNotCreated => "File corresponding to ID could not be created",
|
||||
&StoreErrorKind::StorePathExists => "Store path exists",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,19 +54,21 @@ pub struct Store {
|
|||
impl Store {
|
||||
|
||||
/// Create a new Store object
|
||||
pub fn new(location: PathBuf) -> Store {
|
||||
pub fn new(location: PathBuf) -> Result<Store> {
|
||||
use std::fs::create_dir_all;
|
||||
|
||||
if !location.exists() {
|
||||
create_dir_all(location.clone()).ok(); // TODO: Error handling?
|
||||
} else {
|
||||
if location.is_file() {
|
||||
return Err(StoreError::new(StoreErrorKind::StorePathExists, None));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Path exists, but is a file? What now?
|
||||
|
||||
Store {
|
||||
Ok(Store {
|
||||
location: location,
|
||||
entries: Arc::new(RwLock::new(HashMap::new())),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates the Entry at the given location (inside the entry)
|
||||
|
|
Loading…
Reference in a new issue