]> git.proxmox.com Git - proxmox-backup.git/blob - src/tools/format.rs
a5bd0c83d6c0b9981aa5e1bb89515500a621ecbe
[proxmox-backup.git] / src / tools / format.rs
1 use failure::*;
2 use serde_json::Value;
3 use chrono::{Local, TimeZone};
4
5 pub fn strip_server_file_expenstion(name: &str) -> String {
6
7 if name.ends_with(".didx") || name.ends_with(".fidx") || name.ends_with(".blob") {
8 name[..name.len()-5].to_owned()
9 } else {
10 name.to_owned() // should not happen
11 }
12 }
13
14 pub fn render_backup_file_list(files: &[String]) -> String {
15 let mut files: Vec<String> = files.iter()
16 .map(|v| strip_server_file_expenstion(&v))
17 .collect();
18
19 files.sort();
20
21 super::join(&files, ' ')
22 }
23
24 pub fn render_epoch(value: &Value, _record: &Value) -> Result<String, Error> {
25 if value.is_null() { return Ok(String::new()); }
26 let text = match value.as_i64() {
27 Some(epoch) => {
28 Local.timestamp(epoch, 0).format("%c").to_string()
29 }
30 None => {
31 value.to_string()
32 }
33 };
34 Ok(text)
35 }
36
37 pub fn render_task_status(value: &Value, record: &Value) -> Result<String, Error> {
38 if record["endtime"].is_null() {
39 Ok(value.as_str().unwrap_or("running").to_string())
40 } else {
41 Ok(value.as_str().unwrap_or("unknown").to_string())
42 }
43 }