From a74384f725181268aee3623fc3d9fde00b802a83 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 16 Oct 2021 12:38:34 +0200 Subject: [PATCH] proxmox-rrd: cleanup - use struct instead of tuple --- proxmox-rrd/src/cache.rs | 8 ++++---- proxmox-rrd/src/cache/journal.rs | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/proxmox-rrd/src/cache.rs b/proxmox-rrd/src/cache.rs index afe7a33c..c3969686 100644 --- a/proxmox-rrd/src/cache.rs +++ b/proxmox-rrd/src/cache.rs @@ -318,14 +318,14 @@ fn apply_journal_impl( // Apply old journals first let journal_list = state.read().unwrap().list_old_journals()?; - for (_time, filename, path) in journal_list { - log::info!("apply old journal log {}", filename); - let file = std::fs::OpenOptions::new().read(true).open(path)?; + for entry in journal_list { + log::info!("apply old journal log {}", entry.name); + let file = std::fs::OpenOptions::new().read(true).open(&entry.path)?; let mut reader = BufReader::new(file); lines += apply_journal_lines( Arc::clone(&state), Arc::clone(&rrd_map), - &filename, + &entry.name, &mut reader, false, )?; diff --git a/proxmox-rrd/src/cache/journal.rs b/proxmox-rrd/src/cache/journal.rs index e0f7a88b..cd84cc7f 100644 --- a/proxmox-rrd/src/cache/journal.rs +++ b/proxmox-rrd/src/cache/journal.rs @@ -31,6 +31,12 @@ pub struct JournalEntry { pub rel_path: String, } +pub struct JournalFileInfo { + pub time: u64, + pub name: String, + pub path: PathBuf, +} + impl JournalState { pub(crate) fn new(config: Arc) -> Result { @@ -104,14 +110,14 @@ impl JournalState { let journal_list = self.list_old_journals()?; - for (_time, _filename, path) in journal_list { - std::fs::remove_file(path)?; + for entry in journal_list { + std::fs::remove_file(entry.path)?; } Ok(()) } - pub fn list_old_journals(&self) -> Result, Error> { + pub fn list_old_journals(&self) -> Result, Error> { let mut list = Vec::new(); for entry in std::fs::read_dir(&self.config.basedir)? { let entry = entry?; @@ -123,7 +129,11 @@ impl JournalState { if let Some(extension) = extension.to_str() { if let Some(rest) = extension.strip_prefix("journal-") { if let Ok(time) = u64::from_str_radix(rest, 16) { - list.push((time, format!("rrd.{}", extension), path.to_owned())); + list.push(JournalFileInfo { + time, + name: format!("rrd.{}", extension), + path: path.to_owned(), + }); } } } @@ -131,7 +141,7 @@ impl JournalState { } } } - list.sort_unstable_by_key(|t| t.0); + list.sort_unstable_by_key(|entry| entry.time); Ok(list) } }