mirror of
https://codeberg.org/postscriptum/snac2nex.git
synced 2026-03-31 13:15:27 +00:00
optimize conditions
This commit is contained in:
parent
b8c5e2de86
commit
db09d3ba04
1 changed files with 9 additions and 11 deletions
20
src/nex.rs
20
src/nex.rs
|
|
@ -85,22 +85,22 @@ impl Nex {
|
|||
let root = PathBuf::from(self.users.get(name).unwrap());
|
||||
let mut p = PathBuf::from(&root);
|
||||
if let Some(ref mut i) = index {
|
||||
i.push(root);
|
||||
i.push(root)
|
||||
}
|
||||
|
||||
p.push(published.format("%Y").to_string());
|
||||
if let Some(ref mut i) = index {
|
||||
i.push(p.clone());
|
||||
i.push(p.clone())
|
||||
}
|
||||
|
||||
p.push(published.format("%m").to_string());
|
||||
if let Some(ref mut i) = index {
|
||||
i.push(p.clone());
|
||||
i.push(p.clone())
|
||||
}
|
||||
|
||||
p.push(published.format("%d").to_string());
|
||||
if let Some(ref mut i) = index {
|
||||
i.push(p.clone());
|
||||
i.push(p.clone())
|
||||
}
|
||||
|
||||
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
|
||||
let mut s = PathBuf::from(&d);
|
||||
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::create_dir_all(&d)?;
|
||||
fs::write(&s, updated.unwrap_or(published).to_string())?
|
||||
fs::write(&s, state)?
|
||||
} else {
|
||||
if let Some(ref mut i) = index {
|
||||
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 {
|
||||
change: Change::Ignored,
|
||||
|
|
@ -176,9 +176,7 @@ impl Nex {
|
|||
d.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 {
|
||||
i.push(to);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue