From df5eb296ccac1e5a52fdd7f4b874e249f9fbabd9 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 17 Jan 2020 13:30:28 +0100 Subject: [PATCH] sys: mountinfo parsing fixups * include the failing line on errors * don't fail on the final empty line... Signed-off-by: Wolfgang Bumiller --- proxmox-sys/src/linux/procfs/mountinfo.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/proxmox-sys/src/linux/procfs/mountinfo.rs b/proxmox-sys/src/linux/procfs/mountinfo.rs index 8bca8457..9d395614 100644 --- a/proxmox-sys/src/linux/procfs/mountinfo.rs +++ b/proxmox-sys/src/linux/procfs/mountinfo.rs @@ -188,13 +188,23 @@ impl MountInfo { /// Parse a `mountinfo` file. pub fn parse(statstr: &[u8]) -> Result { - let entries = statstr.split(|b| *b == b'\n').try_fold( - Vec::new(), - |mut acc, line| -> Result<_, Error> { + let entries = statstr + .split(|b| *b == b'\n') + .filter(|line| !line.is_empty()) + .try_fold(Vec::new(), |mut acc, line| -> Result<_, Error> { + let entry = match Entry::parse(line) { + Ok(entry) => entry, + Err(err) => { + bail!( + "failed to parse mount info line: {:?}\n error: {}", + line, + err, + ); + } + }; acc.push(Entry::parse(line)?); Ok(acc) - }, - )?; + })?; let entries = BTreeMap::from_iter(entries.into_iter().map(|entry| (entry.id, entry)));