mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
catch attempts to overwrite notetype with older version
This commit is contained in:
parent
36c1d1cf8c
commit
5ff83fad08
1 changed files with 8 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue