diff --git a/libimagstore/src/error.rs b/libimagstore/src/error.rs index 6432e0f3..3b3fa39b 100644 --- a/libimagstore/src/error.rs +++ b/libimagstore/src/error.rs @@ -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, diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index ba254ac7..1c4b9aa7 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -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