From 6e03dd77e61d7a479e653dc5e5031372f05fe0c8 Mon Sep 17 00:00:00 2001 From: bootandy Date: Mon, 1 Jul 2019 22:09:39 +0100 Subject: [PATCH] Fix obscure display bug When one directory was a substring of another with files in the files could appear as children of the wrong directory Fix: https://github.com/bootandy/dust/issues/25 --- src/display.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/display.rs b/src/display.rs index 0571d5d..fede948 100644 --- a/src/display.rs +++ b/src/display.rs @@ -75,7 +75,8 @@ fn display_node>( let mut is_biggest = true; for &(ref k, _) in to_display.iter() { - if k.starts_with(ntp) && k.matches('/').count() == num_slashes + 1 { + let ntp_with_slash= String::from(ntp.to_owned() + "/"); + if k.starts_with(ntp_with_slash.as_str()) && k.matches('/').count() == num_slashes + 1 { num_siblings -= 1; let has_children = has_children(to_display, new_depth, k, num_slashes + 1); display_node( @@ -122,7 +123,8 @@ fn has_children( ) -> bool { if new_depth.is_none() || new_depth.unwrap() != 1 { for &(ref k2, _) in to_display.iter() { - if k2.starts_with(ntp) && k2.matches('/').count() == num_slashes + 1 { + let ntp_with_slash= String::from(ntp.to_owned() + "/"); + if k2.starts_with(ntp_with_slash.as_str()) && k2.matches('/').count() == num_slashes + 1 { return true; } }