implement argument option to Keep Nex entry on Snac post was removed (disables cleanup action)

This commit is contained in:
postscriptum 2025-07-03 12:30:51 +03:00
parent 499a78004a
commit d8dac50cb6
5 changed files with 66 additions and 24 deletions

View file

@ -19,6 +19,7 @@ fn main() -> Result<()> {
c.format_updated,
c.format_content,
c.attachment,
!c.keep,
&c.user,
)?;
let s = Snac::init(c.source, c.user)?;
@ -48,7 +49,11 @@ fn sync(snac: &Snac, nex: &Nex) -> Result<Response> {
let mut r = Response::default();
for user in &snac.users {
println!("\tsync profile for `{}`...", user.name);
let mut keep = HashSet::with_capacity(100); // @TODO estimated
let mut keep = if nex.is_cleanup() {
Some(HashSet::with_capacity(100)) // @TODO estimated
} else {
None
};
for post in user.public()? {
r.total += 1;
// make sure post entry has expected content type
@ -106,15 +111,21 @@ fn sync(snac: &Snac, nex: &Nex) -> Result<Response> {
println!("\t\t\tpost file `{f}` update with new content.")
}
}
for i in response.keep {
keep.insert(i);
if let Some(ref mut k) = keep
&& let Some(r) = response.keep
{
for i in r {
k.insert(i);
}
}
}
}
// cleanup removed post entries
let d = nex.clean(&user.name, keep)?;
r.deleted.directories += d.directories;
r.deleted.files += d.files;
if let Some(k) = keep {
let d = nex.clean(&user.name, k)?;
r.deleted.directories += d.directories;
r.deleted.files += d.files;
}
}
Ok(r)
}