diff --git a/radicle/src/storage.rs b/radicle/src/storage.rs index ef32e5d0..ead12d1c 100644 --- a/radicle/src/storage.rs +++ b/radicle/src/storage.rs @@ -342,6 +342,8 @@ pub trait WriteStorage: ReadStorage { fn repository_mut(&self, rid: Id) -> Result; /// Create a read-write repository. fn create(&self, rid: Id) -> Result; + /// 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.deref().create(rid) } + + fn remove(&self, rid: Id) -> Result<(), Error> { + self.deref().remove(rid) + } } #[cfg(test)] diff --git a/radicle/src/storage/git.rs b/radicle/src/storage/git.rs index 1539ad63..2c83c3ab 100644 --- a/radicle/src/storage/git.rs +++ b/radicle/src/storage/git.rs @@ -127,6 +127,10 @@ impl WriteStorage for Storage { fn create(&self, rid: Id) -> Result { 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( doc: &Doc, diff --git a/radicle/src/test/storage.rs b/radicle/src/test/storage.rs index e04a6e15..eb5bd60b 100644 --- a/radicle/src/test/storage.rs +++ b/radicle/src/test/storage.rs @@ -99,6 +99,10 @@ impl WriteStorage for MockStorage { fn create(&self, _rid: Id) -> Result { todo!() } + + fn remove(&self, _rid: Id) -> Result<(), Error> { + todo!() + } } #[derive(Clone, Debug)]