diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index d0d83e95e..896546954 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -2470,9 +2470,11 @@ Zotero.Item.prototype.renameAttachmentFile = Zotero.Promise.coroutine(function* yield this.relinkAttachmentFile(destPath); - this.attachmentSyncedHash = null; - this.attachmentSyncState = "to_upload"; - yield this.saveTx({ skipAll: true }); + if (this.isImportedAttachment()) { + this.attachmentSyncedHash = null; + this.attachmentSyncState = "to_upload"; + yield this.saveTx({ skipAll: true }); + } return true; } diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index 97f913d70..bc9c1293c 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -746,6 +746,25 @@ describe("Zotero.Item", function () { assert.equal(item.attachmentSyncState, Zotero.Sync.Storage.Local.SYNC_STATE_TO_UPLOAD); assert.isNull(item.attachmentSyncedHash); }) + + it("should rename a linked file", function* () { + var filename = 'test.png'; + var file = getTestDataDirectory(); + file.append(filename); + var tmpDir = yield getTempDirectory(); + var tmpFile = OS.Path.join(tmpDir, filename); + yield OS.File.copy(file.path, tmpFile); + + var item = yield Zotero.Attachments.linkFromFile({ + file: tmpFile + }); + var newName = 'test2.png'; + yield assert.eventually.isTrue(item.renameAttachmentFile(newName)); + assert.equal(item.attachmentFilename, newName); + var path = yield item.getFilePathAsync(); + assert.equal(OS.Path.basename(path), newName) + yield OS.File.exists(path); + }) })