catch attempts to overwrite notetype with older version

This commit is contained in:
Damien Elmes 2020-05-04 21:28:55 +10:00
parent 36c1d1cf8c
commit 5ff83fad08

View file

@ -322,12 +322,11 @@ impl Collection {
pub fn update_notetype(&mut self, nt: &mut NoteType, preserve_usn: bool) -> Result<()> {
let existing = self.get_notetype(nt.id)?;
nt.prepare_for_update(existing.as_ref().map(AsRef::as_ref))?;
if !preserve_usn {
nt.mtime_secs = TimestampSecs::now();
nt.usn = self.usn()?;
}
self.transact(None, |col| {
if let Some(existing_notetype) = existing {
if existing_notetype.mtime_secs > nt.mtime_secs {
return Err(AnkiError::invalid_input("attempt to save stale notetype"));
}
col.update_notes_for_changed_fields(
nt,
existing_notetype.fields.len(),
@ -336,6 +335,11 @@ impl Collection {
col.update_cards_for_changed_templates(nt, existing_notetype.templates.len())?;
}
if !preserve_usn {
nt.mtime_secs = TimestampSecs::now();
nt.usn = col.usn()?;
}
col.storage.update_notetype_config(&nt)?;
col.storage.update_notetype_fields(nt.id, &nt.fields)?;
col.storage