optimize conditions

This commit is contained in:
postscriptum 2025-07-03 19:42:07 +03:00
parent b8c5e2de86
commit db09d3ba04

View file

@ -85,22 +85,22 @@ impl Nex {
let root = PathBuf::from(self.users.get(name).unwrap()); let root = PathBuf::from(self.users.get(name).unwrap());
let mut p = PathBuf::from(&root); let mut p = PathBuf::from(&root);
if let Some(ref mut i) = index { if let Some(ref mut i) = index {
i.push(root); i.push(root)
} }
p.push(published.format("%Y").to_string()); p.push(published.format("%Y").to_string());
if let Some(ref mut i) = index { if let Some(ref mut i) = index {
i.push(p.clone()); i.push(p.clone())
} }
p.push(published.format("%m").to_string()); p.push(published.format("%m").to_string());
if let Some(ref mut i) = index { if let Some(ref mut i) = index {
i.push(p.clone()); i.push(p.clone())
} }
p.push(published.format("%d").to_string()); p.push(published.format("%d").to_string());
if let Some(ref mut i) = index { if let Some(ref mut i) = index {
i.push(p.clone()); i.push(p.clone())
} }
fs::create_dir_all(&p)?; fs::create_dir_all(&p)?;
@ -123,11 +123,11 @@ impl Nex {
// if this meta file exists and has timestamp changed, also cleanup attachment files to update // if this meta file exists and has timestamp changed, also cleanup attachment files to update
let mut s = PathBuf::from(&d); let mut s = PathBuf::from(&d);
s.push(".state"); s.push(".state");
if !s.exists() || updated.is_some_and(|u| u.to_string() != fs::read_to_string(&s).unwrap()) let state = updated.unwrap_or(published).to_string();
{ if !fs::read_to_string(&s).is_ok_and(|this| this == state) {
fs::remove_dir_all(&d)?; fs::remove_dir_all(&d)?;
fs::create_dir_all(&d)?; fs::create_dir_all(&d)?;
fs::write(&s, updated.unwrap_or(published).to_string())? fs::write(&s, state)?
} else { } else {
if let Some(ref mut i) = index { if let Some(ref mut i) = index {
if let Some(ref a) = attachments { if let Some(ref a) = attachments {
@ -138,7 +138,7 @@ impl Nex {
} }
} }
} }
i.extend([d, f, p, s]); i.extend([d, f, p, s])
} }
return Ok(Sync { return Ok(Sync {
change: Change::Ignored, change: Change::Ignored,
@ -176,9 +176,7 @@ impl Nex {
d.file_name().unwrap().to_string_lossy(), d.file_name().unwrap().to_string_lossy(),
to.file_name().unwrap().to_string_lossy() to.file_name().unwrap().to_string_lossy()
); );
if !to.exists() { self.attachment.sync(&from, &to).unwrap();
self.attachment.sync(&from, &to).unwrap()
}
if let Some(ref mut i) = index { if let Some(ref mut i) = index {
i.push(to); i.push(to);
} }