diff options
author | Florian Klink <flokli@flokli.de> | 2023-05-18T16·49+0300 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2023-05-18T19·29+0000 |
commit | 2e09e94aadddb6e5e4c3e746a2f4759ede736973 (patch) | |
tree | 350f1738f903d957a7e71b58004ad2df62a52cfd /tvix | |
parent | dcbcac89559e128c70edbd39a6a5566386aee286 (diff) |
refactor(tvix/store/directorysvc/traverse): clippy, use NamedNode r/6162
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 <tazjin@tvl.su>
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/store/src/directoryservice/traverse.rs | 23 |
1 files 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<DS: DirectoryService>( 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<DS: DirectoryService>( 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 { |