Warn before watch history is left behind, and re-apply it later (#2)
CI / test (push) Successful in 1m16s

This commit is contained in:
IxianPixel committed 2026-11-06 17:34:22 +00:00
1 parent 2bd4489b1a
commit 8cfa0f05eb
15 files changed
+611 -73

No files matched your search

+6
View File
@@ -206,6 +206,11 @@ pub struct Job {
/// into a show the destination already has.
#[serde(default)]
pub skip_files: Vec<usize>,
/// Users with watch state on the source who have no account here, so
/// their watch state wasn't (or won't be) applied. Their records stay in
/// `export.user_data` and can be re-applied once the account exists.
#[serde(default)]
pub missing_users: Vec<String>,
pub progress: Progress,
/// Human-readable log of what happened, newest last.
pub log: Vec<String>,
@@ -238,6 +243,7 @@ impl Job {
target_item_id: None,
target_location: None,
skip_files: Vec::new(),
missing_users: Vec::new(),
progress: Progress::default(),
log: Vec::new(),
}
+29
View File
@@ -51,10 +51,39 @@ pub fn same_user(a: &str, b: &str) -> bool {
a.trim().eq_ignore_ascii_case(b.trim())
}
/// Users with watch state in `records` who have no account among `users`,
/// each named once, in the order they first appear.
pub fn missing_users<'a>(
records: &'a [UserDataRecord],
users: impl IntoIterator<Item = &'a str> + Clone,
) -> Vec<String> {
let mut out: Vec<String> = Vec::new();
for r in records {
let known = users.clone().into_iter().any(|u| same_user(u, &r.user_name));
if !known && !out.iter().any(|m| same_user(m, &r.user_name)) {
out.push(r.user_name.clone());
}
}
out
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn finds_users_with_no_account() {
let rec = |name: &str| UserDataRecord {
user_name: name.into(),
key: ItemKey::Root,
data: UserData::default(),
};
let records = [rec("Alice"), rec("Bob"), rec("bob "), rec("Carol")];
let here = ["alice", "Carol"];
assert_eq!(missing_users(&records, here.iter().copied()), ["Bob"]);
assert!(missing_users(&records[..1], here.iter().copied()).is_empty());
}
#[test]
fn empty_detection() {
assert!(UserData::default().is_empty());