Add Store::save_to() to create a copy of an entry
This commit is contained in:
parent
2ce84a3dbf
commit
3c40df1ae7
1 changed files with 21 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue