mirror of
https://codeberg.org/icewind/palantir.git
synced 2026-06-03 18:24:08 +02:00
zfs warning
This commit is contained in:
parent
eaeabfa712
commit
35ded75b60
1 changed files with 16 additions and 0 deletions
16
src/zfs.rs
16
src/zfs.rs
|
|
@ -4,8 +4,16 @@ use std::fmt::Write;
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
use tracing::warn;
|
||||||
|
|
||||||
|
static CAN_READ: AtomicBool = AtomicBool::new(true);
|
||||||
|
|
||||||
pub fn pools() -> impl Iterator<Item = DiskUsage> {
|
pub fn pools() -> impl Iterator<Item = DiskUsage> {
|
||||||
|
if !CAN_READ.load(Ordering::Relaxed) {
|
||||||
|
return ZPoolOutputParser::default();
|
||||||
|
}
|
||||||
|
|
||||||
ZPoolOutputParser {
|
ZPoolOutputParser {
|
||||||
str: zpool_command().unwrap_or_default(),
|
str: zpool_command().unwrap_or_default(),
|
||||||
pos: 0,
|
pos: 0,
|
||||||
|
|
@ -19,6 +27,13 @@ fn zpool_command() -> Result<String> {
|
||||||
if out.status.success() {
|
if out.status.success() {
|
||||||
Ok(String::from_utf8(out.stdout)?)
|
Ok(String::from_utf8(out.stdout)?)
|
||||||
} else {
|
} else {
|
||||||
|
CAN_READ.store(false, Ordering::Relaxed);
|
||||||
|
warn!(
|
||||||
|
status = out.status.code().unwrap_or(-1),
|
||||||
|
stdout = String::from_utf8(out.stdout).unwrap_or_else(|_| String::from("non utf8")),
|
||||||
|
stderr = String::from_utf8(out.stderr).unwrap_or_else(|_| String::from("non utf8")),
|
||||||
|
"Failed to list zpool status"
|
||||||
|
);
|
||||||
Ok(String::new())
|
Ok(String::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -31,6 +46,7 @@ fn parse_line(line: &str) -> Option<DiskUsage> {
|
||||||
Some(DiskUsage { name, size, free })
|
Some(DiskUsage { name, size, free })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
struct ZPoolOutputParser {
|
struct ZPoolOutputParser {
|
||||||
str: String,
|
str: String,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue