refactor(tvix/*store/sled): make ::new() more generic
We don't really require the Path to be a PathBuf, we don't even require it to be a Path, we only need it to be AsRef<Path>>. This removes some conversion in the from_addr cases, which can just reuse `url.path()` (a `&str`). Change-Id: I38d536dbaf0b44421e41f211a9ad2b13605179e9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10258 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
This commit is contained in:
parent
9748543f1c
commit
ccaf10b4a6
6 changed files with 10 additions and 11 deletions
|
@ -44,8 +44,7 @@ pub async fn from_addr(uri: &str) -> Result<Arc<dyn BlobService>, crate::Error>
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return Ok(Arc::new(
|
return Ok(Arc::new(
|
||||||
SledBlobService::new(url.path().into())
|
SledBlobService::new(url.path()).map_err(|e| Error::StorageError(e.to_string()))?,
|
||||||
.map_err(|e| Error::StorageError(e.to_string()))?,
|
|
||||||
));
|
));
|
||||||
} else if url.scheme().starts_with("grpc+") {
|
} else if url.scheme().starts_with("grpc+") {
|
||||||
// schemes starting with grpc+ go to the GRPCPathInfoService.
|
// schemes starting with grpc+ go to the GRPCPathInfoService.
|
||||||
|
|
|
@ -2,7 +2,7 @@ use super::{BlobReader, BlobService, BlobWriter};
|
||||||
use crate::{B3Digest, Error};
|
use crate::{B3Digest, Error};
|
||||||
use std::{
|
use std::{
|
||||||
io::{self, Cursor, Write},
|
io::{self, Cursor, Write},
|
||||||
path::PathBuf,
|
path::Path,
|
||||||
task::Poll,
|
task::Poll,
|
||||||
};
|
};
|
||||||
use tonic::async_trait;
|
use tonic::async_trait;
|
||||||
|
@ -14,7 +14,7 @@ pub struct SledBlobService {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SledBlobService {
|
impl SledBlobService {
|
||||||
pub fn new(p: PathBuf) -> Result<Self, sled::Error> {
|
pub fn new<P: AsRef<Path>>(p: P) -> Result<Self, sled::Error> {
|
||||||
let config = sled::Config::default()
|
let config = sled::Config::default()
|
||||||
.use_compression(false) // is a required parameter
|
.use_compression(false) // is a required parameter
|
||||||
.path(p);
|
.path(p);
|
||||||
|
|
|
@ -51,7 +51,7 @@ pub async fn from_addr(uri: &str) -> Result<Arc<dyn DirectoryService>, crate::Er
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return Ok(Arc::new(
|
return Ok(Arc::new(
|
||||||
SledDirectoryService::new(url.path().into())
|
SledDirectoryService::new(url.path())
|
||||||
.map_err(|e| Error::StorageError(e.to_string()))?,
|
.map_err(|e| Error::StorageError(e.to_string()))?,
|
||||||
));
|
));
|
||||||
} else if url.scheme().starts_with("grpc+") {
|
} else if url.scheme().starts_with("grpc+") {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::proto::Directory;
|
||||||
use crate::{proto, B3Digest, Error};
|
use crate::{proto, B3Digest, Error};
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
use std::path::PathBuf;
|
use std::path::Path;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use tonic::async_trait;
|
use tonic::async_trait;
|
||||||
use tracing::{instrument, warn};
|
use tracing::{instrument, warn};
|
||||||
|
@ -17,7 +17,7 @@ pub struct SledDirectoryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SledDirectoryService {
|
impl SledDirectoryService {
|
||||||
pub fn new(p: PathBuf) -> Result<Self, sled::Error> {
|
pub fn new<P: AsRef<Path>>(p: P) -> Result<Self, sled::Error> {
|
||||||
let config = sled::Config::default()
|
let config = sled::Config::default()
|
||||||
.use_compression(false) // is a required parameter
|
.use_compression(false) // is a required parameter
|
||||||
.path(p);
|
.path(p);
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub async fn from_addr(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return Ok(Arc::new(
|
return Ok(Arc::new(
|
||||||
SledPathInfoService::new(url.path().into(), blob_service, directory_service)
|
SledPathInfoService::new(url.path(), blob_service, directory_service)
|
||||||
.map_err(|e| Error::StorageError(e.to_string()))?,
|
.map_err(|e| Error::StorageError(e.to_string()))?,
|
||||||
));
|
));
|
||||||
} else if url.scheme() == "nix+http" || url.scheme() == "nix+https" {
|
} else if url.scheme() == "nix+http" || url.scheme() == "nix+https" {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::nar::calculate_size_and_sha256;
|
||||||
use crate::proto::PathInfo;
|
use crate::proto::PathInfo;
|
||||||
use futures::{stream::iter, Stream};
|
use futures::{stream::iter, Stream};
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
use std::{path::PathBuf, pin::Pin, sync::Arc};
|
use std::{path::Path, pin::Pin, sync::Arc};
|
||||||
use tonic::async_trait;
|
use tonic::async_trait;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
use tvix_castore::proto as castorepb;
|
use tvix_castore::proto as castorepb;
|
||||||
|
@ -21,8 +21,8 @@ pub struct SledPathInfoService {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SledPathInfoService {
|
impl SledPathInfoService {
|
||||||
pub fn new(
|
pub fn new<P: AsRef<Path>>(
|
||||||
p: PathBuf,
|
p: P,
|
||||||
blob_service: Arc<dyn BlobService>,
|
blob_service: Arc<dyn BlobService>,
|
||||||
directory_service: Arc<dyn DirectoryService>,
|
directory_service: Arc<dyn DirectoryService>,
|
||||||
) -> Result<Self, sled::Error> {
|
) -> Result<Self, sled::Error> {
|
||||||
|
|
Loading…
Reference in a new issue