Skip to main content

pacenotes_shared/
conflict_report.rs

1/// The body of `POST /report/conflict`: packages the user selected wrote the
2/// same file, and the later one won.
3///
4/// Carries nothing identifying, only the game, the installer's version and
5/// catalogue data the server already has; the server stamps the time itself.
6#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
7pub struct ConflictReport {
8    /// A `GAME_*` id, which the packages below belong to.
9    pub game: String,
10    /// E.g. `"0.2.0"`.
11    pub installer: String,
12    pub conflicts: Vec<Conflict>,
13}
14
15/// One file several packages wrote.
16#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
17pub struct Conflict {
18    /// Relative to the install root and `/`-separated, as the ledger records it.
19    pub file: String,
20    /// `directory/name` refs within the report's game, in install order: the
21    /// last one's bytes are on disk.
22    pub packages: Vec<String>,
23}
24
25#[cfg(test)]
26mod tests {
27    #[test]
28    fn conflict_reports_round_trip_in_the_documented_shape() {
29        let wire = r#"{"game":"rbr","installer":"0.2.0","conflicts":[
30            {"file":"Plugins/Pacenote/PaceNote.ini",
31             "packages":["public/language/polish","public/codriver/polish/male/Kamil"]}]}"#;
32        let report: super::ConflictReport = serde_json::from_str(wire).unwrap();
33        assert_eq!(report.game, crate::GAME_RBR);
34        for reference in &report.conflicts[0].packages {
35            assert!(crate::PackageRef::parse(reference).is_some(), "{reference}");
36        }
37        let back: super::ConflictReport =
38            serde_json::from_str(&serde_json::to_string(&report).unwrap()).unwrap();
39        assert_eq!(back, report);
40    }
41}