fix: use documented swapon show columns
This commit is contained in:
@@ -11,17 +11,17 @@ use std::os::unix::fs::PermissionsExt;
|
|||||||
|
|
||||||
use super::model::ActiveSwap;
|
use super::model::ActiveSwap;
|
||||||
|
|
||||||
|
fn swapon_show_args() -> [&'static str; 4] {
|
||||||
|
[
|
||||||
|
"--show=NAME,TYPE,SIZE,PRIO",
|
||||||
|
"--bytes",
|
||||||
|
"--raw",
|
||||||
|
"--noheadings",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn read_active_swaps() -> anyhow::Result<Vec<ActiveSwap>> {
|
pub(super) fn read_active_swaps() -> anyhow::Result<Vec<ActiveSwap>> {
|
||||||
let out = Command::new("swapon")
|
let out = Command::new("swapon").args(swapon_show_args()).output()?;
|
||||||
.args([
|
|
||||||
"--show",
|
|
||||||
"--bytes",
|
|
||||||
"--raw",
|
|
||||||
"--noheadings",
|
|
||||||
"--output",
|
|
||||||
"NAME,TYPE,SIZE,PRIO",
|
|
||||||
])
|
|
||||||
.output()?;
|
|
||||||
if !out.status.success() {
|
if !out.status.success() {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"swapon --show failed: {}",
|
"swapon --show failed: {}",
|
||||||
@@ -111,6 +111,20 @@ pub(super) fn run(program: &str, args: &[&str]) -> anyhow::Result<()> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn swapon_uses_the_documented_show_columns_form() {
|
||||||
|
assert_eq!(
|
||||||
|
swapon_show_args(),
|
||||||
|
[
|
||||||
|
"--show=NAME,TYPE,SIZE,PRIO",
|
||||||
|
"--bytes",
|
||||||
|
"--raw",
|
||||||
|
"--noheadings"
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_swapon_empty() {
|
fn parse_swapon_empty() {
|
||||||
let got = parse_swapon_output("").expect("parse");
|
let got = parse_swapon_output("").expect("parse");
|
||||||
|
|||||||
Reference in New Issue
Block a user