radicle: check if ref exists when removing a cob
If the reference did not exist it is not necessary to create a new `sigrefs` entry. Check that the reference exists before removing from the cob store and only sign if it did. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
0e6fae5a03
commit
44a3a09e5c
|
|
@ -105,6 +105,12 @@ pub enum Error {
|
||||||
NotFound(TypeName, ObjectId),
|
NotFound(TypeName, ObjectId),
|
||||||
#[error("signed refs: {0}")]
|
#[error("signed refs: {0}")]
|
||||||
SignRefs(#[from] storage::Error),
|
SignRefs(#[from] storage::Error),
|
||||||
|
#[error("failed to find reference '{name}': {err}")]
|
||||||
|
RefLookup {
|
||||||
|
name: git::RefString,
|
||||||
|
#[source]
|
||||||
|
err: git::Error,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Storage for collaborative objects of a specific type `T` in a single repository.
|
/// Storage for collaborative objects of a specific type `T` in a single repository.
|
||||||
|
|
@ -237,10 +243,23 @@ where
|
||||||
|
|
||||||
/// Remove an object.
|
/// Remove an object.
|
||||||
pub fn remove<G: Signer>(&self, id: &ObjectId, signer: &G) -> Result<(), Error> {
|
pub fn remove<G: Signer>(&self, id: &ObjectId, signer: &G) -> Result<(), Error> {
|
||||||
cob::remove(self.repo, signer.public_key(), T::type_name(), id)?;
|
let name = git::refs::storage::cob(signer.public_key(), T::type_name(), id);
|
||||||
self.repo.sign_refs(signer).map_err(Error::SignRefs)?;
|
match self
|
||||||
|
.repo
|
||||||
Ok(())
|
.reference_oid(signer.public_key(), &name.strip_namespace())
|
||||||
|
{
|
||||||
|
Ok(_) => {
|
||||||
|
cob::remove(self.repo, signer.public_key(), T::type_name(), id)?;
|
||||||
|
self.repo.sign_refs(signer).map_err(Error::SignRefs)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Err(git::Error::NotFound(_)) => Ok(()),
|
||||||
|
Err(git::Error::Git(err)) if err.code() == git::raw::ErrorCode::NotFound => Ok(()),
|
||||||
|
Err(err) => Err(Error::RefLookup {
|
||||||
|
name: name.to_ref_string(),
|
||||||
|
err,
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue