Add Store::save_to() to create a copy of an entry

This commit is contained in:
Matthias Beyer 2016-04-14 17:15:19 +02:00
parent 2ce84a3dbf
commit 3c40df1ae7

View file

@ -607,6 +607,27 @@ impl Store {
.map_err(|e| SEK::DeleteCallError.into_error_with_cause(e))
}
/// Save a copy of the Entry in another place
/// Executes the post_move_aspects for the new id
pub fn save_to(&self, entry: &FileLockEntry, new_id: StoreId) -> Result<()> {
use std::fs::copy;
let new_id = self.storify_id(new_id);
let hsmap = self.entries.write();
if hsmap.is_err() {
return Err(StoreError::new(StoreErrorKind::LockPoisoned, None))
}
if hsmap.unwrap().contains_key(&new_id) {
return Err(StoreError::new(StoreErrorKind::EntryAlreadyExists, None))
}
let old_id = entry.get_location().clone();
copy(old_id.clone(), new_id.clone())
.map_err(|e| StoreError::new(StoreErrorKind::FileError, Some(Box::new(e))))
.and_then(|_| self.execute_hooks_for_id(self.post_move_aspects.clone(), &new_id))
}
/// Save an Entry in another place
/// Removes the original entry
/// Executes the post_move_aspects for the new id