Skip to content

Commit

Permalink
Fix renaming linked attachment files
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Dec 8, 2016
1 parent 021f8e1 commit 2b9ef26
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions chrome/content/zotero/xpcom/data/item.js
Expand Up @@ -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;
}
Expand Down
19 changes: 19 additions & 0 deletions test/tests/itemTest.js
Expand Up @@ -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);
})
})


Expand Down

0 comments on commit 2b9ef26

Please sign in to comment.