Fix: Store::create() should fail if the entry exists
This commit is contained in:
parent
e4fc2e8010
commit
41f7bab1c5
1 changed files with 13 additions and 1 deletions
|
@ -317,6 +317,7 @@ impl Store {
|
||||||
///
|
///
|
||||||
/// On error:
|
/// On error:
|
||||||
/// - Errors StoreId::into_storeid() might return
|
/// - Errors StoreId::into_storeid() might return
|
||||||
|
/// - EntryAlreadyExists(id) if the entry exists
|
||||||
/// - CreateCallError(LockPoisoned()) if the internal lock is poisened.
|
/// - CreateCallError(LockPoisoned()) if the internal lock is poisened.
|
||||||
/// - CreateCallError(EntryAlreadyExists()) if the entry exists already.
|
/// - CreateCallError(EntryAlreadyExists()) if the entry exists already.
|
||||||
///
|
///
|
||||||
|
@ -325,6 +326,17 @@ impl Store {
|
||||||
|
|
||||||
debug!("Creating id: '{}'", id);
|
debug!("Creating id: '{}'", id);
|
||||||
|
|
||||||
|
let exists = id.exists()? || self.entries
|
||||||
|
.read()
|
||||||
|
.map(|map| map.contains_key(&id))
|
||||||
|
.map_err(|_| SE::from_kind(SEK::LockPoisoned))
|
||||||
|
.chain_err(|| SEK::CreateCallError)?;
|
||||||
|
|
||||||
|
if exists {
|
||||||
|
debug!("Entry exists: {:?}", id);
|
||||||
|
return Err(SEK::EntryAlreadyExists(id).into());
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut hsmap = self
|
let mut hsmap = self
|
||||||
.entries
|
.entries
|
||||||
|
@ -1420,7 +1432,7 @@ mod store_tests {
|
||||||
for n in 1..100 {
|
for n in 1..100 {
|
||||||
let s = format!("test-{}", n % 50);
|
let s = format!("test-{}", n % 50);
|
||||||
store.create(PathBuf::from(s.clone()))
|
store.create(PathBuf::from(s.clone()))
|
||||||
.map_err(|e| assert!(is_match!(e.kind(), &SEK::CreateCallError) && n >= 50))
|
.map_err(|e| assert!(is_match!(e.kind(), &SEK::EntryAlreadyExists(_)) && n >= 50))
|
||||||
.ok()
|
.ok()
|
||||||
.map(|entry| {
|
.map(|entry| {
|
||||||
assert!(entry.verify().is_ok());
|
assert!(entry.verify().is_ok());
|
||||||
|
|
Loading…
Reference in a new issue