Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: add remove to WriteStorage
Fintan Halpenny committed 2 years ago
commit 87187d47e5dbc0da7f574a0b8b36386cefaada5c
parent f1f32d8574583e70f4d3f397af7685f3fd44984e
3 files changed +23 -0
modified radicle/src/storage.rs
@@ -342,6 +342,8 @@ pub trait WriteStorage: ReadStorage {
    fn repository_mut(&self, rid: Id) -> Result<Self::RepositoryMut, Error>;
    /// Create a read-write repository.
    fn create(&self, rid: Id) -> Result<Self::RepositoryMut, Error>;
+
    /// Delete a repository.
+
    fn remove(&self, rid: Id) -> Result<(), Error>;
}

/// Allows read-only access to a repository.
@@ -575,6 +577,10 @@ where
    fn create(&self, rid: Id) -> Result<Self::RepositoryMut, Error> {
        self.deref().create(rid)
    }
+

+
    fn remove(&self, rid: Id) -> Result<(), Error> {
+
        self.deref().remove(rid)
+
    }
}

#[cfg(test)]
modified radicle/src/storage/git.rs
@@ -127,6 +127,10 @@ impl WriteStorage for Storage {
    fn create(&self, rid: Id) -> Result<Self::RepositoryMut, Error> {
        Repository::create(paths::repository(self, &rid), rid)
    }
+

+
    fn remove(&self, rid: Id) -> Result<(), Error> {
+
        self.repository(rid)?.remove()
+
    }
}

impl Storage {
@@ -299,6 +303,15 @@ impl Repository {
        Ok(Self { id, backend })
    }

+
    /// Remove an existing repository
+
    pub fn remove(&self) -> Result<(), Error> {
+
        let path = self.backend.path();
+
        if path.exists() {
+
            fs::remove_dir_all(path)?;
+
        }
+
        Ok(())
+
    }
+

    /// Create the repository's identity branch.
    pub fn init<G: Signer, S: WriteStorage>(
        doc: &Doc<Verified>,
modified radicle/src/test/storage.rs
@@ -99,6 +99,10 @@ impl WriteStorage for MockStorage {
    fn create(&self, _rid: Id) -> Result<Self::RepositoryMut, Error> {
        todo!()
    }
+

+
    fn remove(&self, _rid: Id) -> Result<(), Error> {
+
        todo!()
+
    }
}

#[derive(Clone, Debug)]