Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cob: Implement COB removal function
Alexis Sellier committed 3 years ago
commit 3af2c53bb220a312c0869d292fbbbdb2e472ce37
parent dd7052926a1ae263731aa9a3b82ca323f9f49276
6 files changed +84 -0
modified radicle-cob/src/object/collaboration.rs
@@ -23,6 +23,9 @@ pub mod info;
mod list;
pub use list::list;

+
mod remove;
+
pub use remove::remove;
+

mod update;
pub use update::{update, Update};

modified radicle-cob/src/object/collaboration/error.rs
@@ -25,6 +25,13 @@ pub enum Create {
}

#[derive(Debug, Error)]
+
#[error("failed to remove object: {err}")]
+
pub struct Remove {
+
    #[source]
+
    pub(crate) err: Box<dyn std::error::Error + Send + Sync + 'static>,
+
}
+

+
#[derive(Debug, Error)]
pub enum Retrieve {
    #[error(transparent)]
    Git(#[from] git2::Error),
added radicle-cob/src/object/collaboration/remove.rs
@@ -0,0 +1,33 @@
+
// Copyright © 2022 The Radicle Link Contributors
+
//
+
// This file is part of radicle-link, distributed under the GPLv3 with Radicle
+
// Linking Exception. For full terms see the included LICENSE file.
+

+
use crate::{ObjectId, Store, TypeName};
+

+
use super::error;
+

+
/// Remove a [`crate::CollaborativeObject`].
+
///
+
/// The `storage` is the backing storage for storing
+
/// [`crate::Change`]s at content-addressable locations. Please see
+
/// [`Store`] for further information.
+
///
+
/// The `typename` is the type of object to be found, while the
+
/// `object_id` is the identifier for the particular object under that
+
/// type.
+
pub fn remove<S>(
+
    storage: &S,
+
    identifier: &S::Identifier,
+
    typename: &TypeName,
+
    oid: &ObjectId,
+
) -> Result<(), error::Remove>
+
where
+
    S: Store,
+
{
+
    storage
+
        .remove(identifier, typename, oid)
+
        .map_err(|e| error::Remove { err: e.into() })?;
+

+
    Ok(())
+
}
modified radicle-cob/src/object/storage.rs
@@ -61,6 +61,7 @@ pub trait Storage {
    type ObjectsError: Error + Send + Sync + 'static;
    type TypesError: Error + Send + Sync + 'static;
    type UpdateError: Error + Send + Sync + 'static;
+
    type RemoveError: Error + Send + Sync + 'static;

    type Identifier;

@@ -84,6 +85,14 @@ pub trait Storage {
        object_id: &ObjectId,
        change: &Change,
    ) -> Result<(), Self::UpdateError>;
+

+
    /// Remove a ref to a particular collaborative object
+
    fn remove(
+
        &self,
+
        identifier: &Self::Identifier,
+
        typename: &TypeName,
+
        object_id: &ObjectId,
+
    ) -> Result<(), Self::RemoveError>;
}

pub mod convert {
modified radicle-cob/src/test/storage.rs
@@ -96,6 +96,7 @@ impl object::Storage for Storage {
    type ObjectsError = error::Objects;
    type TypesError = error::Objects;
    type UpdateError = git2::Error;
+
    type RemoveError = git2::Error;

    type Identifier = Urn;

@@ -157,4 +158,21 @@ impl object::Storage for Storage {
        self.raw.reference(&name, id.into(), true, "new change")?;
        Ok(())
    }
+

+
    fn remove(
+
        &self,
+
        identifier: &Self::Identifier,
+
        typename: &crate::TypeName,
+
        object_id: &ObjectId,
+
    ) -> Result<(), Self::RemoveError> {
+
        let name = format!(
+
            "refs/rad/{}/cobs/{}/{}",
+
            identifier.to_path(),
+
            typename,
+
            object_id
+
        );
+
        self.raw.find_reference(&name)?.delete()?;
+

+
        Ok(())
+
    }
}
modified radicle/src/storage/git.rs
@@ -705,6 +705,7 @@ impl cob::object::Storage for Repository {
    type ObjectsError = CobObjectsError;
    type TypesError = CobTypesError;
    type UpdateError = git2::Error;
+
    type RemoveError = git2::Error;

    type Identifier = RemoteId;

@@ -780,6 +781,19 @@ impl cob::object::Storage for Repository {

        Ok(())
    }
+

+
    fn remove(
+
        &self,
+
        identifier: &Self::Identifier,
+
        typename: &cob::TypeName,
+
        object_id: &cob::ObjectId,
+
    ) -> Result<(), Self::RemoveError> {
+
        let mut reference = self
+
            .backend
+
            .find_reference(git::refs::storage::cob(identifier, typename, object_id).as_str())?;
+

+
        reference.delete().map_err(Self::RemoveError::from)
+
    }
}

pub mod trailers {