assorted_debian_utils/
autoremovals.rsuse std::{collections::HashMap, io};
use chrono::{DateTime, Utc};
use serde::Deserialize;
use crate::{utils::DateTimeVisitor, version::PackageVersion};
fn deserialize_datetime<'de, D>(deserializer: D) -> std::result::Result<DateTime<Utc>, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_str(DateTimeVisitor("%Y-%m-%d %H:%M:%S"))
}
pub type AutoRemovals = HashMap<String, AutoRemoval>;
#[derive(Debug, Deserialize, PartialEq, Eq)]
pub struct AutoRemoval {
pub bugs: Vec<String>,
pub bugs_dependencies: Option<Vec<String>>,
pub buggy_dependencies: Option<Vec<String>>,
pub dependencies_only: bool,
#[serde(deserialize_with = "deserialize_datetime")]
pub last_checked: DateTime<Utc>,
#[serde(deserialize_with = "deserialize_datetime")]
pub removal_date: DateTime<Utc>,
pub source: String,
pub version: PackageVersion,
pub rdeps: Option<Vec<String>>,
}
pub type Result<T> = serde_yaml::Result<T>;
pub fn from_reader(reader: impl io::Read) -> Result<AutoRemovals> {
serde_yaml::from_reader(reader)
}
pub fn from_str(data: &str) -> Result<AutoRemovals> {
serde_yaml::from_str(data)
}
#[cfg(test)]
mod test {
use super::from_str;
#[test]
fn base() {
let data = r"---
mplayer:
bugs:
- '1005899'
dependencies_only: false
last_checked: 2022-04-10 17:55:40
rdeps:
- devede
- diffoscope
- dradio
- mplayer-blue
- ogmrip
- qwinff
- reprotest
- vdr-plugin-mp3
- videotrans
removal_date: 2022-05-01 19:42:01
source: mplayer
version: 2:1.4+ds1-3
mplayer-blue:
buggy_dependencies:
- mplayer
bugs: []
bugs_dependencies:
- '1005899'
dependencies_only: true
last_checked: 2022-04-10 17:55:40
removal_date: 2022-05-01 19:42:01
source: mplayer-blue
version: 1.13-2
";
let autoremovals = from_str(data).unwrap();
assert!(autoremovals.contains_key("mplayer"));
let mplayer = autoremovals.get("mplayer").unwrap();
assert_eq!(mplayer.source, "mplayer");
assert_eq!(mplayer.version.to_string(), "2:1.4+ds1-3");
assert_eq!(mplayer.bugs, vec!["1005899"]);
assert_eq!(
mplayer.rdeps.as_ref().unwrap(),
&vec![
"devede",
"diffoscope",
"dradio",
"mplayer-blue",
"ogmrip",
"qwinff",
"reprotest",
"vdr-plugin-mp3",
"videotrans"
]
);
assert!(!mplayer.dependencies_only);
assert!(autoremovals.contains_key("mplayer-blue"));
let mplayer_blue = autoremovals.get("mplayer-blue").unwrap();
assert_eq!(mplayer_blue.source, "mplayer-blue");
assert_eq!(mplayer_blue.version.to_string(), "1.13-2");
assert_eq!(mplayer_blue.bugs.len(), 0);
assert_eq!(
mplayer_blue.buggy_dependencies.as_ref().unwrap(),
&vec!["mplayer"]
);
assert_eq!(
mplayer_blue.bugs_dependencies.as_ref().unwrap(),
&vec!["1005899"]
);
assert!(mplayer_blue.dependencies_only);
}
}