about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-12-11T20·11+0200
committerclbot <clbot@tvl.fyi>2023-12-11T22·46+0000
commitccaf10b4a6f7768294e41fcb6fbcd768a1e1c143 (patch)
tree64e7ee1f57474e04d8854ed85f5255a6f8af99ea
parent9748543f1c3edd88e8b05f6a772d6e9be18a7be9 (diff)
refactor(tvix/*store/sled): make ::new() more generic r/7159
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
-rw-r--r--tvix/castore/src/blobservice/from_addr.rs3
-rw-r--r--tvix/castore/src/blobservice/sled.rs4
-rw-r--r--tvix/castore/src/directoryservice/from_addr.rs2
-rw-r--r--tvix/castore/src/directoryservice/sled.rs4
-rw-r--r--tvix/store/src/pathinfoservice/from_addr.rs2
-rw-r--r--tvix/store/src/pathinfoservice/sled.rs6
6 files changed, 10 insertions, 11 deletions
diff --git a/tvix/castore/src/blobservice/from_addr.rs b/tvix/castore/src/blobservice/from_addr.rs
index 106edce04d..97e185464d 100644
--- a/tvix/castore/src/blobservice/from_addr.rs
+++ b/tvix/castore/src/blobservice/from_addr.rs
@@ -44,8 +44,7 @@ pub async fn from_addr(uri: &str) -> Result<Arc<dyn BlobService>, crate::Error>
             ));
         }
         return Ok(Arc::new(
-            SledBlobService::new(url.path().into())
-                .map_err(|e| Error::StorageError(e.to_string()))?,
+            SledBlobService::new(url.path()).map_err(|e| Error::StorageError(e.to_string()))?,
         ));
     } else if url.scheme().starts_with("grpc+") {
         // schemes starting with grpc+ go to the GRPCPathInfoService.
diff --git a/tvix/castore/src/blobservice/sled.rs b/tvix/castore/src/blobservice/sled.rs
index a6fdbac499..f7bf33e8c5 100644
--- a/tvix/castore/src/blobservice/sled.rs
+++ b/tvix/castore/src/blobservice/sled.rs
@@ -2,7 +2,7 @@ use super::{BlobReader, BlobService, BlobWriter};
 use crate::{B3Digest, Error};
 use std::{
     io::{self, Cursor, Write},
-    path::PathBuf,
+    path::Path,
     task::Poll,
 };
 use tonic::async_trait;
@@ -14,7 +14,7 @@ pub struct 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()
             .use_compression(false) // is a required parameter
             .path(p);
diff --git a/tvix/castore/src/directoryservice/from_addr.rs b/tvix/castore/src/directoryservice/from_addr.rs
index 8f79fa6158..bd1bf584cf 100644
--- a/tvix/castore/src/directoryservice/from_addr.rs
+++ b/tvix/castore/src/directoryservice/from_addr.rs
@@ -51,7 +51,7 @@ pub async fn from_addr(uri: &str) -> Result<Arc<dyn DirectoryService>, crate::Er
             ));
         }
         return Ok(Arc::new(
-            SledDirectoryService::new(url.path().into())
+            SledDirectoryService::new(url.path())
                 .map_err(|e| Error::StorageError(e.to_string()))?,
         ));
     } else if url.scheme().starts_with("grpc+") {
diff --git a/tvix/castore/src/directoryservice/sled.rs b/tvix/castore/src/directoryservice/sled.rs
index 50e58e7e76..9e6749a753 100644
--- a/tvix/castore/src/directoryservice/sled.rs
+++ b/tvix/castore/src/directoryservice/sled.rs
@@ -3,7 +3,7 @@ use crate::proto::Directory;
 use crate::{proto, B3Digest, Error};
 use futures::Stream;
 use prost::Message;
-use std::path::PathBuf;
+use std::path::Path;
 use std::pin::Pin;
 use tonic::async_trait;
 use tracing::{instrument, warn};
@@ -17,7 +17,7 @@ pub struct 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()
             .use_compression(false) // is a required parameter
             .path(p);
diff --git a/tvix/store/src/pathinfoservice/from_addr.rs b/tvix/store/src/pathinfoservice/from_addr.rs
index 1505b3e427..35f2bd3730 100644
--- a/tvix/store/src/pathinfoservice/from_addr.rs
+++ b/tvix/store/src/pathinfoservice/from_addr.rs
@@ -63,7 +63,7 @@ pub async fn from_addr(
             ));
         }
         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()))?,
         ));
     } else if url.scheme() == "nix+http" || url.scheme() == "nix+https" {
diff --git a/tvix/store/src/pathinfoservice/sled.rs b/tvix/store/src/pathinfoservice/sled.rs
index 1382c3c29b..ff5ebee476 100644
--- a/tvix/store/src/pathinfoservice/sled.rs
+++ b/tvix/store/src/pathinfoservice/sled.rs
@@ -3,7 +3,7 @@ use crate::nar::calculate_size_and_sha256;
 use crate::proto::PathInfo;
 use futures::{stream::iter, Stream};
 use prost::Message;
-use std::{path::PathBuf, pin::Pin, sync::Arc};
+use std::{path::Path, pin::Pin, sync::Arc};
 use tonic::async_trait;
 use tracing::warn;
 use tvix_castore::proto as castorepb;
@@ -21,8 +21,8 @@ pub struct SledPathInfoService {
 }
 
 impl SledPathInfoService {
-    pub fn new(
-        p: PathBuf,
+    pub fn new<P: AsRef<Path>>(
+        p: P,
         blob_service: Arc<dyn BlobService>,
         directory_service: Arc<dyn DirectoryService>,
     ) -> Result<Self, sled::Error> {