refactor(tvix/castore): make directorysvc more generic

This works on Box<dyn DirectoryService> too.

Change-Id: Ib869f0f4d963ef4dbaeab22db03ff6afb71ede04
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10513
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2023-12-31 23:30:27 +02:00 committed by clbot
parent 2c2fdfedc6
commit 54fe97e725

View file

@ -1,16 +1,19 @@
use super::DirectoryService;
use crate::{proto::NamedNode, B3Digest, Error};
use std::{os::unix::ffi::OsStrExt, sync::Arc};
use std::{ops::Deref, os::unix::ffi::OsStrExt};
use tracing::{instrument, warn};
/// This descends from a (root) node to the given (sub)path, returning the Node
/// at that path, or none, if there's nothing at that path.
#[instrument(skip(directory_service))]
pub async fn descend_to(
directory_service: Arc<dyn DirectoryService>,
pub async fn descend_to<DS>(
directory_service: DS,
root_node: crate::proto::node::Node,
path: &std::path::Path,
) -> Result<Option<crate::proto::node::Node>, Error> {
) -> Result<Option<crate::proto::node::Node>, Error>
where
DS: Deref<Target = dyn DirectoryService>,
{
// strip a possible `/` prefix from the path.
let path = {
if path.starts_with("/") {