refactor(tvix/castore/directorysvc): AsRef traverse_to
Change-Id: I641bd4ab3de591a013f03137f1e16295946315f3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10579 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
b1c556b7e1
commit
0009383c07
2 changed files with 13 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
|||
use super::DirectoryService;
|
||||
use crate::{proto::NamedNode, B3Digest, Error};
|
||||
use std::{ops::Deref, os::unix::ffi::OsStrExt};
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use tracing::{instrument, warn};
|
||||
|
||||
/// This descends from a (root) node to the given (sub)path, returning the Node
|
||||
|
@ -12,7 +12,7 @@ pub async fn descend_to<DS>(
|
|||
path: &std::path::Path,
|
||||
) -> Result<Option<crate::proto::node::Node>, Error>
|
||||
where
|
||||
DS: Deref<Target = dyn DirectoryService>,
|
||||
DS: AsRef<dyn DirectoryService>,
|
||||
{
|
||||
// strip a possible `/` prefix from the path.
|
||||
let path = {
|
||||
|
@ -45,7 +45,7 @@ where
|
|||
})?;
|
||||
|
||||
// fetch the linked node from the directory_service
|
||||
match directory_service.get(&digest).await? {
|
||||
match directory_service.as_ref().get(&digest).await? {
|
||||
// If we didn't get the directory node that's linked, that's a store inconsistency, bail out!
|
||||
None => {
|
||||
warn!("directory {} does not exist", digest);
|
||||
|
@ -86,9 +86,7 @@ where
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::directoryservice::DirectoryService;
|
||||
use crate::fixtures::{DIRECTORY_COMPLICATED, DIRECTORY_WITH_KEEP};
|
||||
use crate::utils::gen_directory_service;
|
||||
|
||||
|
@ -96,7 +94,7 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
async fn test_descend_to() {
|
||||
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||
let directory_service = gen_directory_service();
|
||||
|
||||
let mut handle = directory_service.put_multiple_start();
|
||||
handle
|
||||
|
@ -128,7 +126,7 @@ mod tests {
|
|||
// traversal to an empty subpath should return the root node.
|
||||
{
|
||||
let resp = descend_to(
|
||||
directory_service.clone(),
|
||||
&directory_service,
|
||||
node_directory_complicated.clone(),
|
||||
&PathBuf::from(""),
|
||||
)
|
||||
|
@ -141,7 +139,7 @@ mod tests {
|
|||
// traversal to `keep` should return the node for DIRECTORY_WITH_KEEP
|
||||
{
|
||||
let resp = descend_to(
|
||||
directory_service.clone(),
|
||||
&directory_service,
|
||||
node_directory_complicated.clone(),
|
||||
&PathBuf::from("keep"),
|
||||
)
|
||||
|
@ -154,7 +152,7 @@ mod tests {
|
|||
// traversal to `keep/.keep` should return the node for the .keep file
|
||||
{
|
||||
let resp = descend_to(
|
||||
directory_service.clone(),
|
||||
&directory_service,
|
||||
node_directory_complicated.clone(),
|
||||
&PathBuf::from("keep/.keep"),
|
||||
)
|
||||
|
@ -167,7 +165,7 @@ mod tests {
|
|||
// traversal to `keep/.keep` should return the node for the .keep file
|
||||
{
|
||||
let resp = descend_to(
|
||||
directory_service.clone(),
|
||||
&directory_service,
|
||||
node_directory_complicated.clone(),
|
||||
&PathBuf::from("/keep/.keep"),
|
||||
)
|
||||
|
@ -180,7 +178,7 @@ mod tests {
|
|||
// traversal to `void` should return None (doesn't exist)
|
||||
{
|
||||
let resp = descend_to(
|
||||
directory_service.clone(),
|
||||
&directory_service,
|
||||
node_directory_complicated.clone(),
|
||||
&PathBuf::from("void"),
|
||||
)
|
||||
|
@ -193,7 +191,7 @@ mod tests {
|
|||
// traversal to `void` should return None (doesn't exist)
|
||||
{
|
||||
let resp = descend_to(
|
||||
directory_service.clone(),
|
||||
&directory_service,
|
||||
node_directory_complicated.clone(),
|
||||
&PathBuf::from("//v/oid"),
|
||||
)
|
||||
|
@ -207,7 +205,7 @@ mod tests {
|
|||
// reached, as keep/.keep already is a file)
|
||||
{
|
||||
let resp = descend_to(
|
||||
directory_service.clone(),
|
||||
&directory_service,
|
||||
node_directory_complicated.clone(),
|
||||
&PathBuf::from("keep/.keep/foo"),
|
||||
)
|
||||
|
@ -220,7 +218,7 @@ mod tests {
|
|||
// traversal to a subpath of '/' should return the root node.
|
||||
{
|
||||
let resp = descend_to(
|
||||
directory_service.clone(),
|
||||
&directory_service,
|
||||
node_directory_complicated.clone(),
|
||||
&PathBuf::from("/"),
|
||||
)
|
||||
|
|
|
@ -92,8 +92,7 @@ where
|
|||
// with the root_node and sub_path, descend to the node requested.
|
||||
Ok(self.tokio_handle.block_on({
|
||||
async {
|
||||
directoryservice::descend_to(self.directory_service.as_ref(), root_node, sub_path)
|
||||
.await
|
||||
directoryservice::descend_to(&self.directory_service, root_node, sub_path).await
|
||||
}
|
||||
})?)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue