Skip to content

Commit

Permalink
Fix hang during rename-and-move in Zotero 6 (#594)
Browse files Browse the repository at this point in the history
Resulting in not all annotations being transferred and the old
attachment not being deleted

Regression after zotero/zotero@734057ff9b, which added a transaction
requirement to `Zotero.Items.moveChildItems()` but tried to preserve
backwards compatibility with ZotFile. Unfortunately it had a bug, and a
race condition with another transacation during the process results in a
hang anyway if `moveChildItems()` isn't called in a transaction, so just
change ZotFile to follow the new requirement.

This also fixes `saveTx()` being called without an await.

Fixes #593
  • Loading branch information
dstillman authored Mar 23, 2022
1 parent 7f0aa03 commit 688c423
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions chrome/content/zotfile/zotfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,18 +911,21 @@ Zotero.ZotFile = new function() {
win.ZoteroPane.itemsView.selectItems(selection);
}
// update links to attachment file in notes
Zotero.Items.get(item.getNotes()).forEach(note => {
var notes = Zotero.Items.get(item.getNotes());
for (let note of notes) {
var content = note.getNote();
content = content.replace(new RegExp('open-pdf/([\\w\\W\\d]{1,10})_' + att.key, 'g'), 'open-pdf/$1_' + attNew.key);
note.setNote(content);
note.saveTx();
});
yield note.saveTx();
}
// transfer various attachment data
//
// should stay in sync with Zotero.Attachments.convertLinkedFileToStoredFile()
if (this.isZotero6OrLater) {
// move child annotations and embedded-image attachments
yield Zotero.Items.moveChildItems(att, attNew);
yield Zotero.DB.executeTransaction(async function () {
await Zotero.Items.moveChildItems(att, attNew);
});
// copy relations pointing to the old item
yield Zotero.Relations.copyObjectSubjectRelations(att, attNew);
// transfer full-text item index
Expand Down Expand Up @@ -975,18 +978,21 @@ Zotero.ZotFile = new function() {
win.ZoteroPane.itemsView.selectItems(selection);
}
// update links to attachment file in notes
Zotero.Items.get(item.getNotes()).forEach(note => {
var notes = Zotero.Items.get(item.getNotes());
for (let note of notes) {
var content = note.getNote();
content = content.replace(new RegExp('open-pdf/([\\w\\W\\d]{1,10})_' + att.key, 'g'), 'open-pdf/$1_' + attNew.key);
note.setNote(content);
note.saveTx();
});
yield note.saveTx();
}
// transfer various attachment data
//
// should stay in sync with Zotero.Attachments.convertLinkedFileToStoredFile()
if (this.isZotero6OrLater) {
// move child annotations and embedded-image attachments
yield Zotero.Items.moveChildItems(att, attNew);
yield Zotero.DB.executeTransaction(async function () {
await Zotero.Items.moveChildItems(att, attNew);
});
// copy relations pointing to the old item
yield Zotero.Relations.copyObjectSubjectRelations(att, attNew);
// transfer full-text item index
Expand Down

0 comments on commit 688c423

Please sign in to comment.