From e2c5f03d7d7ddb37558176301dd9fad7c8c4cd9e Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Wed, 8 Apr 2020 13:32:48 +0200 Subject: [PATCH] sysinfo: fix installtime offset (dnf returns UTC, not local time) --- Cargo.lock | 8 ++++---- src/input.rs | 6 +++--- src/output.rs | 16 ++++++++++------ src/sysinfo.rs | 10 +++++----- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 925198c..8af3ebb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -956,9 +956,9 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" [[package]] name = "openssl" -version = "0.10.28" +version = "0.10.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "973293749822d7dd6370d6da1e523b0d1db19f06c459134c658b2a4261378b52" +checksum = "cee6d85f4cb4c4f59a6a85d5b68a233d280c82e29e822913b9c8b129fbf20bdd" dependencies = [ "bitflags", "cfg-if", @@ -976,9 +976,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-sys" -version = "0.9.54" +version = "0.9.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1024c0a59774200a555087a6da3f253a9095a5f344e353b212ac4c8b8e450986" +checksum = "7717097d810a0f2e2323f9e5d11e71608355e24828410b55b9d4f18aa5f9a5d8" dependencies = [ "autocfg 1.0.0", "cc", diff --git a/src/input.rs b/src/input.rs index 28b54e0..5a7be93 100644 --- a/src/input.rs +++ b/src/input.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::io::{stdin, stdout, Write}; use bodhi::{Karma, Update}; -use chrono::{DateTime, Local}; +use chrono::{DateTime, Utc}; use super::print_update; @@ -55,11 +55,11 @@ pub fn str_to_karma(string: &str) -> Option { /// automatically; two empty lines or EOF (`Ctrl-D`) ends comment input) /// /// If enabled at compile time, it also asks for bug and testcase feedback. -pub fn ask_feedback<'a>( +pub fn ask_feedback<'a, S: std::hash::BuildHasher>( rl: &mut rustyline::Editor<()>, update: &'a Update, builds: &[&str], - install_times: &HashMap>, + install_times: &HashMap, S>, ) -> Result, String> { print_update(update, builds, install_times); diff --git a/src/output.rs b/src/output.rs index cac50b3..a7dd56d 100644 --- a/src/output.rs +++ b/src/output.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::io::{stdout, Write}; use bodhi::{Comment, Update}; -use chrono::{DateTime, Duration, Local}; +use chrono::{DateTime, Duration, Utc}; /// This function draws a pretty progress bar with this format: /// @@ -33,8 +33,8 @@ pub fn progress_bar(prefix: &str, p: u32, ps: u32) { } /// This helper function returns the duration from a datetime that lies in the past until now. -fn duration_until_now(datetime: &DateTime) -> Duration { - let result = Local::now() - datetime.to_owned(); +fn duration_until_now(datetime: &DateTime) -> Duration { + let result = Utc::now() - datetime.to_owned(); if result <= Duration::seconds(0) { Duration::seconds(0) @@ -68,14 +68,18 @@ fn pretty_duration(duration: Duration) -> String { ) } else if duration >= Duration::minutes(1) { let minutes = duration.num_minutes(); - format!("{}", proper_plural(minutes, "minute")) + proper_plural(minutes, "minute") } else { - format!("less than a minute") + String::from("less than a minute") } } /// This helper function pretty-prints an update. -pub fn print_update(update: &Update, builds: &[&str], install_times: &HashMap>) { +pub fn print_update( + update: &Update, + builds: &[&str], + install_times: &HashMap, S>, +) { let submitted_date = match &update.date_submitted { Some(date) => date.to_string(), None => "(None)".to_string(), diff --git a/src/sysinfo.rs b/src/sysinfo.rs index 961ef54..bb5e7e5 100644 --- a/src/sysinfo.rs +++ b/src/sysinfo.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::process::Command; use bodhi::FedoraRelease; -use chrono::{DateTime, Local, TimeZone}; +use chrono::{DateTime, TimeZone, Utc}; use super::{parse_filename, NVR}; @@ -144,7 +144,7 @@ pub fn get_src_bin_map() -> Result>, String> { } /// This helper function returns a map from binary packages to their installation times. -pub fn get_installation_times() -> Result>, String> { +pub fn get_installation_times() -> Result>, String> { // query dnf for installed binary packages and their corresponding installation dates let output = match Command::new("dnf") .arg("--quiet") @@ -172,7 +172,7 @@ pub fn get_installation_times() -> Result>, Stri let lines: Vec<&str> = results.trim().split('\n').collect(); - let mut pkg_map: HashMap> = HashMap::new(); + let mut pkg_map: HashMap> = HashMap::new(); for line in lines { let parts: Vec<&str> = line.split('\t').collect(); @@ -184,12 +184,12 @@ pub fn get_installation_times() -> Result>, Stri let binary = parts.get(0).unwrap(); let installtime = parts.get(1).unwrap(); - let local_time = match Local.datetime_from_str(installtime, "%Y-%m-%d %H:%M") { + let datetime = match Utc.datetime_from_str(installtime, "%Y-%m-%d %H:%M") { Ok(datetime) => datetime, Err(error) => return Err(format!("Failed to parse dnf output: {}", error)), }; - pkg_map.entry((*binary).to_string()).or_insert(local_time); + pkg_map.entry((*binary).to_string()).or_insert(datetime); } Ok(pkg_map)