src/server/worker_task.rs: make log_path a method on UPID

This commit is contained in:
Dietmar Maurer 2019-04-07 13:51:46 +02:00
parent d2a2e02bb7
commit 4494d07819
1 changed files with 13 additions and 9 deletions

View File

@ -55,6 +55,18 @@ pub struct UPID {
pub node: String, pub node: String,
} }
impl UPID {
/// Returns the absolute path to the task log file
pub fn log_path(&self) -> std::path::PathBuf {
let mut path = std::path::PathBuf::from(PROXMOX_BACKUP_TASK_DIR!());
path.push(format!("{:02X}", self.pstart % 256));
path.push(self.to_string());
path
}
}
impl std::str::FromStr for UPID { impl std::str::FromStr for UPID {
type Err = Error; type Err = Error;
@ -134,18 +146,10 @@ pub fn create_task_log_dir() -> Result<(), Error> {
Ok(()) Ok(())
} }
/// Returns the absolute path to the task log file
pub fn upid_log_path(upid: &UPID) -> std::path::PathBuf {
let mut path = std::path::PathBuf::from(PROXMOX_BACKUP_TASK_DIR!());
path.push(format!("{:02X}", upid.pstart % 256));
path.push(upid.to_string());
path
}
fn upid_read_status(upid: &UPID) -> Result<String, Error> { fn upid_read_status(upid: &UPID) -> Result<String, Error> {
let mut status = String::from("unknown"); let mut status = String::from("unknown");
let path = upid_log_path(upid); let path = upid.log_path();
let file = File::open(path)?; let file = File::open(path)?;
let reader = BufReader::new(file); let reader = BufReader::new(file);