commit 2b9ef26c61aab43bd08ecec04cc1029f050f5232
parent 021f8e14765f9bc2177aa8d39435406914a29e3f
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 8 Dec 2016 03:57:49 -0500
Fix renaming linked attachment files
Diffstat:
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git 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
@@ -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);
+ })
})