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 <tazjin@tvl.su>
This commit is contained in:
parent
dcbcac8955
commit
2e09e94aad
1 changed files with 6 additions and 17 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue