mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-01 01:10:46 +08:00
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 <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<P: AsRef<Path>>(path: P) -> Result<Self, error::Init> {
|
||||
crate::init();
|
||||
|
||||
|
||||
@@ -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<P: AsRef<Path>>(path: P, info: UserInfo) -> Result<Self, error::Init> {
|
||||
crate::init();
|
||||
|
||||
|
||||
@@ -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};
|
||||
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
// Copyright © 2019-2020 The Radicle Foundation <hello@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<S> = deadpool::managed::Pool<S, InitError>;
|
||||
pub type PoolError = managed::PoolError<InitError>;
|
||||
|
||||
#[async_trait]
|
||||
pub trait Pooled<S: Send> {
|
||||
async fn get(&self) -> Result<PooledRef<S>, PoolError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S: Send> Pooled<S> for Pool<S> {
|
||||
async fn get(&self) -> Result<PooledRef<S>, 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<S>(Object<S, InitError>);
|
||||
|
||||
impl<S> Deref for PooledRef<S> {
|
||||
type Target = S;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.0.deref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> DerefMut for PooledRef<S> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.0.deref_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> AsRef<S> for PooledRef<S> {
|
||||
fn as_ref(&self) -> &S {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> AsMut<S> for PooledRef<S> {
|
||||
fn as_mut(&mut self) -> &mut S {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Read> for PooledRef<Write> {
|
||||
fn as_ref(&self) -> &Read {
|
||||
self.0.read_only()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> From<Object<S, InitError>> for PooledRef<S> {
|
||||
fn from(obj: Object<S, InitError>) -> Self {
|
||||
Self(obj)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Initialised(Arc<RwLock<bool>>);
|
||||
|
||||
impl Initialised {
|
||||
pub fn no() -> Self {
|
||||
Self(Arc::new(RwLock::new(false)))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Writer {
|
||||
init: Initialised,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Config<W> {
|
||||
root: PathBuf,
|
||||
info: UserInfo,
|
||||
write: W,
|
||||
}
|
||||
|
||||
pub type ReadConfig = Config<PhantomData<Void>>;
|
||||
pub type WriteConfig = Config<Writer>;
|
||||
|
||||
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<Read, InitError> for ReadConfig {
|
||||
async fn create(&self) -> Result<Read, InitError> {
|
||||
Read::open(&self.root).map_err(InitError::from)
|
||||
}
|
||||
|
||||
async fn recycle(&self, _: &mut Read) -> RecycleResult<InitError> {
|
||||
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, InitError> {
|
||||
Write::open(&self.root, self.info.clone()).map_err(InitError::from)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Manager<Write, InitError> for WriteConfig {
|
||||
async fn create(&self) -> Result<Write, InitError> {
|
||||
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<InitError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user