From 502053d972ff8ae7ccdf5a230597f019ff5c3645 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 11 Jan 2023 10:41:06 +0000 Subject: [PATCH] git-storage: remove pool There is an advisory error[0] relating to tokio which is transitively brought in via deadpool. Since git-storage is not currently used and heartwood is avoiding any async runtimes, the pool module is removed. [0]: https://rustsec.org/advisories/RUSTSEC-2023-0001.html Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- git-storage/Cargo.toml | 6 -- git-storage/src/backend/read.rs | 2 - git-storage/src/backend/write.rs | 2 - git-storage/src/lib.rs | 8 -- git-storage/src/pool.rs | 176 ------------------------------- 5 files changed, 194 deletions(-) delete mode 100644 git-storage/src/pool.rs diff --git a/git-storage/Cargo.toml b/git-storage/Cargo.toml index 1eef56b..c01b080 100644 --- a/git-storage/Cargo.toml +++ b/git-storage/Cargo.toml @@ -6,18 +6,12 @@ edition = "2021" license = "GPL-3.0-or-later" [dependencies] -async-trait = "0.1" globset = "0.4" libc = "0.2" parking_lot = "0.12" thiserror = "1" either = "1.8.0" -[dependencies.deadpool] -version = "0.7" -default-features = false -features = ["managed"] - [dependencies.git2] version = "0.15.0" default-features = false diff --git a/git-storage/src/backend/read.rs b/git-storage/src/backend/read.rs index 45f611b..d1257ed 100644 --- a/git-storage/src/backend/read.rs +++ b/git-storage/src/backend/read.rs @@ -35,8 +35,6 @@ impl Read { /// [`Read`] can be sent between threads, but it can't be shared between /// threads. _Some_ operations are safe to perform concurrently in much /// the same way two `git` processes can access the same repository. - /// However, if you need multiple [`Read`]s to be shared between - /// threads, use a [`crate::Pool`] instead. pub fn open>(path: P) -> Result { crate::init(); diff --git a/git-storage/src/backend/write.rs b/git-storage/src/backend/write.rs index a15ae6d..b2d7354 100644 --- a/git-storage/src/backend/write.rs +++ b/git-storage/src/backend/write.rs @@ -50,8 +50,6 @@ impl Write { /// [`Write`] can be sent between threads, but it can't be shared between /// threads. _Some_ operations are safe to perform concurrently in much /// the same way two `git` processes can access the same repository. - /// However, if you need multiple [`Write`]s to be shared between - /// threads, use a [`crate::Pool`] instead. pub fn open>(path: P, info: UserInfo) -> Result { crate::init(); diff --git a/git-storage/src/lib.rs b/git-storage/src/lib.rs index e062d50..5703292 100644 --- a/git-storage/src/lib.rs +++ b/git-storage/src/lib.rs @@ -29,23 +29,15 @@ //! [`Read`] and [`Write`] can be sent between threads, but it can't be shared //! between threads. _Some_ operations are safe to perform concurrently in much //! the same way two `git` processes can access the same repository. -//! However, if you need multiple [`Read`]/[`Write`]s to be shared between -//! threads, use a [`Pool`] instead. //! //! [refs]: https://git-scm.com/book/en/v2/Git-Internals-Git-References //! [objs]: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects -#[macro_use] -extern crate async_trait; - extern crate radicle_git_ext as git_ext; extern crate radicle_std_ext as std_ext; pub mod glob; -pub mod pool; -pub use pool::Pool; - pub mod refdb; pub use refdb::{Applied, Reference, SymrefTarget, Target, Update, Updated}; diff --git a/git-storage/src/pool.rs b/git-storage/src/pool.rs deleted file mode 100644 index da6faa2..0000000 --- a/git-storage/src/pool.rs +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright © 2019-2020 The Radicle Foundation -// -// This file is part of radicle-link, distributed under the GPLv3 with Radicle -// Linking Exception. For full terms see the included LICENSE file. - -use std::{ - marker::PhantomData, - ops::{Deref, DerefMut}, - path::PathBuf, - sync::Arc, -}; - -use deadpool::managed::{self, Manager, Object, RecycleResult}; -use parking_lot::RwLock; -use std_ext::Void; -use thiserror::Error; - -use crate::{read, signature::UserInfo, write, Read, Write}; - -#[derive(Debug, Error)] -#[non_exhaustive] -pub enum InitError { - #[error(transparent)] - Read(#[from] read::error::Init), - - #[error(transparent)] - Write(#[from] write::error::Init), -} - -pub type Pool = deadpool::managed::Pool; -pub type PoolError = managed::PoolError; - -#[async_trait] -pub trait Pooled { - async fn get(&self) -> Result, PoolError>; -} - -#[async_trait] -impl Pooled for Pool { - async fn get(&self) -> Result, PoolError> { - self.get().await.map(PooledRef::from) - } -} - -/// A reference to a pooled storage. -/// -/// The `S` parameter can be filled by [`Write`] for read-write access or -/// [`Read`] for read-only access. -pub struct PooledRef(Object); - -impl Deref for PooledRef { - type Target = S; - - fn deref(&self) -> &Self::Target { - self.0.deref() - } -} - -impl DerefMut for PooledRef { - fn deref_mut(&mut self) -> &mut Self::Target { - self.0.deref_mut() - } -} - -impl AsRef for PooledRef { - fn as_ref(&self) -> &S { - self - } -} - -impl AsMut for PooledRef { - fn as_mut(&mut self) -> &mut S { - self - } -} - -impl AsRef for PooledRef { - fn as_ref(&self) -> &Read { - self.0.read_only() - } -} - -impl From> for PooledRef { - fn from(obj: Object) -> Self { - Self(obj) - } -} - -#[derive(Clone)] -pub struct Initialised(Arc>); - -impl Initialised { - pub fn no() -> Self { - Self(Arc::new(RwLock::new(false))) - } -} - -pub struct Writer { - init: Initialised, -} - -#[derive(Clone)] -pub struct Config { - root: PathBuf, - info: UserInfo, - write: W, -} - -pub type ReadConfig = Config>; -pub type WriteConfig = Config; - -impl ReadConfig { - pub fn new(root: PathBuf, info: UserInfo) -> Self { - Config { - root, - info, - write: PhantomData, - } - } - - pub fn write(self, init: Initialised) -> WriteConfig { - Config { - root: self.root, - info: self.info, - write: Writer { init }, - } - } -} - -#[async_trait] -impl Manager for ReadConfig { - async fn create(&self) -> Result { - Read::open(&self.root).map_err(InitError::from) - } - - async fn recycle(&self, _: &mut Read) -> RecycleResult { - Ok(()) - } -} - -impl WriteConfig { - pub fn new(root: PathBuf, info: UserInfo, init: Initialised) -> Self { - Self { - root, - info, - write: Writer { init }, - } - } - - fn mk_storage(&self) -> Result { - Write::open(&self.root, self.info.clone()).map_err(InitError::from) - } -} - -#[async_trait] -impl Manager for WriteConfig { - async fn create(&self) -> Result { - let initialised = self.write.init.0.read(); - if *initialised { - self.mk_storage() - } else { - drop(initialised); - let mut initialised = self.write.init.0.write(); - self.mk_storage() - .map(|storage| { - *initialised = true; - storage - }) - .map_err(InitError::from) - } - } - - async fn recycle(&self, _: &mut Write) -> RecycleResult { - Ok(()) - } -}