From b29cbc414d9583cc421f8f6a32381df1636ec9f8 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 18 Jun 2020 18:38:56 +0200 Subject: [PATCH] parse_zpool_status_vdev: consider tabs as 8 spaces --- src/tools/disks/zpool_status.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/tools/disks/zpool_status.rs b/src/tools/disks/zpool_status.rs index b3b0f450..c56882de 100644 --- a/src/tools/disks/zpool_status.rs +++ b/src/tools/disks/zpool_status.rs @@ -31,20 +31,29 @@ pub struct ZFSPoolVDevState { pub msg: Option, } +fn expand_tab_length(input: &str) -> usize { + input.chars().map(|c| if c == '\t' { 8 } else { 1 }).sum() +} + fn parse_zpool_status_vdev(i: &str) -> IResult<&str, ZFSPoolVDevState> { let (n, indent) = multispace0(i)?; - if (indent.len() & 1) != 0 { + + let indent_len = expand_tab_length(indent); + + if (indent_len & 1) != 0 { return Err(parse_failure(n, "wrong indent length")); } let i = n; + let indent_level = (indent_len as u64)/2; + let (i, vdev_name) = notspace1(i)?; if let Ok((n, _)) = preceded(multispace0, line_ending)(i) { // sepecial device let vdev = ZFSPoolVDevState { name: vdev_name.to_string(), - lvl: (indent.len() as u64)/2, + lvl: indent_level, state: None, read: None, write: None, @@ -63,7 +72,7 @@ fn parse_zpool_status_vdev(i: &str) -> IResult<&str, ZFSPoolVDevState> { let vdev = ZFSPoolVDevState { name: vdev_name.to_string(), - lvl: (indent.len() as u64)/2, + lvl: indent_level, state: Some(state.to_string()), read: Some(read), write: Some(write),