Implement move_by_id()

This commit is contained in:
Matthias Beyer 2016-03-17 13:39:32 +01:00
parent 5b16771f4f
commit f885e6c80b
2 changed files with 22 additions and 2 deletions

View file

@ -33,6 +33,7 @@ generate_custom_error_types!(StoreError, StoreErrorKind, CustomErrorData,
GlobError => "glob() error",
EncodingError => "Encoding error",
StorePathError => "Store Path error",
EntryRenameError => "Entry rename error",
CreateCallError => "Error when calling create()",
RetrieveCallError => "Error when calling retrieve()",
@ -42,7 +43,6 @@ generate_custom_error_types!(StoreError, StoreErrorKind, CustomErrorData,
UpdateCallError => "Error when calling update()",
RetrieveCopyCallError => "Error when calling retrieve_copy()",
DeleteCallError => "Error when calling delete()"
);
generate_custom_error_types!(ParserError, ParserErrorKind, CustomErrorData,

View file

@ -598,7 +598,27 @@ impl Store {
/// Move an entry without loading
pub fn move_by_id(&self, old_id: StoreId, new_id: StoreId) -> Result<()> {
unimplemented!()
use std::fs::rename;
let new_id = self.storify_id(new_id);
let old_id = self.storify_id(old_id);
let hsmap = self.entries.write();
if hsmap.is_err() {
return Err(SE::new(SEK::LockPoisoned, None))
}
if hsmap.unwrap().contains_key(&old_id) {
return Err(SE::new(SEK::EntryAlreadyBorrowed, None));
} else {
match rename(old_id, new_id.clone()) {
Err(e) => {
let kind = SEK::EntryRenameError;
return Err(SE::new(kind, Some(Box::new(e))));
},
_ => {
debug!("Rename worked");
},
}
}
}
/// Gets the path where this store is on the disk