From 2e09e94aadddb6e5e4c3e746a2f4759ede736973 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 18 May 2023 19:49:40 +0300 Subject: refactor(tvix/store/directorysvc/traverse): clippy, use NamedNode Also, get rid of the explicit byte comparison here, but unwrap like in the rest of the codebase. We'll deal with this in a generic manner in b/267 and b/189. Change-Id: Ie5f3d27ab35b7e88d67a2796c29cdd7bc7df71f3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8589 Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/store/src/directoryservice/traverse.rs | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/tvix/store/src/directoryservice/traverse.rs b/tvix/store/src/directoryservice/traverse.rs index c407c62c305e..46bf0c4b6329 100644 --- a/tvix/store/src/directoryservice/traverse.rs +++ b/tvix/store/src/directoryservice/traverse.rs @@ -1,6 +1,5 @@ use super::DirectoryService; -use crate::Error; -use std::os::unix::prelude::OsStrExt; +use crate::{proto::NamedNode, Error}; use tracing::{instrument, warn}; /// This traverses from a (root) node to the given (sub)path, returning the Node @@ -33,9 +32,6 @@ pub fn traverse_to( Ok(Some(node)) } Some(first_component) => { - // convert first_component to bytes, which are later used for comparison. - let first_component_bytes: &[u8] = first_component.as_os_str().as_bytes(); - match node { crate::proto::node::Node::File(_) | crate::proto::node::Node::Symlink(_) => { // There's still some path left, but the current node is no directory. @@ -54,25 +50,18 @@ pub fn traverse_to( None => { let digest_b64 = data_encoding::BASE64.encode(&digest); warn!("directory {} does not exist", digest_b64); - return Err(Error::StorageError(format!( + + Err(Error::StorageError(format!( "directory {} does not exist", digest_b64 - ))); + ))) } Some(directory) => { // look for first_component in the [Directory]. // FUTUREWORK: as the nodes() iterator returns in a sorted fashion, we // could stop as soon as e.name is larger than the search string. - let child_node = directory.nodes().find(|n| match n { - crate::proto::node::Node::Directory(e) => { - &e.name.to_string().into_bytes() == first_component_bytes - } - crate::proto::node::Node::File(e) => { - &e.name.to_string().into_bytes() == first_component_bytes - } - crate::proto::node::Node::Symlink(e) => { - &e.name.to_string().into_bytes() == first_component_bytes - } + let child_node = directory.nodes().find(|n| { + n.get_name() == first_component.as_os_str().to_str().unwrap() }); match child_node { -- cgit 1.4.1