mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-08-13 14:02:16 +00:00
system report: support outputting all files in a directory
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
eb32373e3c
commit
0b9614d5a4
@ -1,3 +1,4 @@
|
|||||||
|
use std::fmt::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
@ -86,9 +87,48 @@ fn function_calls() -> Vec<FunctionMapping> {
|
|||||||
})]
|
})]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_report() -> String {
|
fn get_file_content(file: impl AsRef<Path>) -> String {
|
||||||
use proxmox_sys::fs::file_read_optional_string;
|
use proxmox_sys::fs::file_read_optional_string;
|
||||||
|
let content = match file_read_optional_string(&file) {
|
||||||
|
Ok(Some(content)) => content,
|
||||||
|
Ok(None) => String::from("# file does not exist"),
|
||||||
|
Err(err) => err.to_string(),
|
||||||
|
};
|
||||||
|
let file_name = file.as_ref().display();
|
||||||
|
format!("`$ cat '{file_name}'`\n```\n{}\n```", content.trim_end())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_directory_content(path: impl AsRef<Path>) -> String {
|
||||||
|
let read_dir_iter = match std::fs::read_dir(&path) {
|
||||||
|
Ok(iter) => iter,
|
||||||
|
Err(err) => {
|
||||||
|
return format!(
|
||||||
|
"`$ cat '{}*'`\n```\n# read dir failed - {}\n```",
|
||||||
|
path.as_ref().display(),
|
||||||
|
err.to_string(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut out = String::new();
|
||||||
|
for entry in read_dir_iter {
|
||||||
|
let entry = match entry {
|
||||||
|
Ok(entry) => entry,
|
||||||
|
Err(err) => {
|
||||||
|
let _ = writeln!(out, "error during read-dir - {}", err.to_string());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let path = entry.path();
|
||||||
|
if path.is_file() {
|
||||||
|
let _ = writeln!(out, "{}", get_file_content(path));
|
||||||
|
} else {
|
||||||
|
let _ = writeln!(out, "skipping sub-directory `{}`", path.display());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_report() -> String {
|
||||||
let file_contents = files()
|
let file_contents = files()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|group| {
|
.map(|group| {
|
||||||
@ -96,12 +136,12 @@ pub fn generate_report() -> String {
|
|||||||
let group_content = files
|
let group_content = files
|
||||||
.iter()
|
.iter()
|
||||||
.map(|file_name| {
|
.map(|file_name| {
|
||||||
let content = match file_read_optional_string(Path::new(file_name)) {
|
let path = Path::new(file_name);
|
||||||
Ok(Some(content)) => content,
|
if path.is_dir() {
|
||||||
Ok(None) => String::from("# file does not exist"),
|
get_directory_content(&path)
|
||||||
Err(err) => err.to_string(),
|
} else {
|
||||||
};
|
get_file_content(file_name)
|
||||||
format!("`$ cat '{file_name}'`\n```\n{}\n```", content.trim_end())
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n\n");
|
.join("\n\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user