www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 5c50bb00cfc936013ebd907c09d1437124f9c111
parent bb0fa7389971ba7f979809ba7971d48a01edf0ac
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon, 20 Feb 2017 17:51:37 -0500

Don't save full-text cache files for linked files to linked directory

Regression from 80f888f374. Not entirely sure what I was trying to fix there.

Diffstat:
Mchrome/content/zotero/xpcom/fulltext.js | 10+---------
Mtest/tests/fulltextTest.js | 105+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
2 files changed, 63 insertions(+), 52 deletions(-)

diff --git a/chrome/content/zotero/xpcom/fulltext.js b/chrome/content/zotero/xpcom/fulltext.js @@ -659,15 +659,7 @@ Zotero.Fulltext = Zotero.FullText = new function(){ // If file is stored outside of Zotero, create a directory for the item // in the storage directory and save the cache file there if (linkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE) { - let path = item.getFilePath(); - if (!path) { - Zotero.debug("Invalid path for item " + itemID); - return false; - } - var parentDirPath = OS.Path.dirname(path); - if (!(yield OS.File.exists(parentDirPath))) { - yield Zotero.Attachments.createDirectoryForItem(item); - } + var parentDirPath = yield Zotero.Attachments.createDirectoryForItem(item); } else { var parentDirPath = OS.Path.dirname(filePath); diff --git a/test/tests/fulltextTest.js b/test/tests/fulltextTest.js @@ -14,7 +14,7 @@ describe("Zotero.Fulltext", function () { } }); - describe("#indexItems()", function () { + describe("Indexing", function () { before(function* () { yield Zotero.Fulltext.downloadPDFTool('info', pdfToolsVersion); yield Zotero.Fulltext.downloadPDFTool('converter', pdfToolsVersion); @@ -29,49 +29,68 @@ describe("Zotero.Fulltext", function () { Zotero.Prefs.clear('fulltext.pdfMaxPages'); }); - it("should index a text file by default", function* () { - var item = yield importFileAttachment('test.txt'); - assert.equal( - (yield Zotero.Fulltext.getIndexedState(item)), - Zotero.Fulltext.INDEX_STATE_INDEXED - ); - }) - - it("should skip indexing of a text file if fulltext.textMaxLength is 0", function* () { - Zotero.Prefs.set('fulltext.textMaxLength', 0); - var item = yield importFileAttachment('test.txt'); - assert.equal( - (yield Zotero.Fulltext.getIndexedState(item)), - Zotero.Fulltext.INDEX_STATE_UNINDEXED - ); - }) - - it("should index a PDF by default", function* () { - var item = yield importFileAttachment('test.pdf'); - assert.equal( - (yield Zotero.Fulltext.getIndexedState(item)), - Zotero.Fulltext.INDEX_STATE_INDEXED - ); - }) - - it("should skip indexing of a PDF if fulltext.textMaxLength is 0", function* () { - Zotero.Prefs.set('fulltext.textMaxLength', 0); - var item = yield importFileAttachment('test.pdf'); - assert.equal( - (yield Zotero.Fulltext.getIndexedState(item)), - Zotero.Fulltext.INDEX_STATE_UNINDEXED - ); - }) + describe("#indexItems()", function () { + it("should index a text file by default", function* () { + var item = yield importFileAttachment('test.txt'); + assert.equal( + (yield Zotero.Fulltext.getIndexedState(item)), + Zotero.Fulltext.INDEX_STATE_INDEXED + ); + }) + + it("should skip indexing of a text file if fulltext.textMaxLength is 0", function* () { + Zotero.Prefs.set('fulltext.textMaxLength', 0); + var item = yield importFileAttachment('test.txt'); + assert.equal( + (yield Zotero.Fulltext.getIndexedState(item)), + Zotero.Fulltext.INDEX_STATE_UNINDEXED + ); + }) + + it("should index a PDF by default", function* () { + var item = yield importFileAttachment('test.pdf'); + assert.equal( + (yield Zotero.Fulltext.getIndexedState(item)), + Zotero.Fulltext.INDEX_STATE_INDEXED + ); + }) + + it("should skip indexing of a PDF if fulltext.textMaxLength is 0", function* () { + Zotero.Prefs.set('fulltext.textMaxLength', 0); + var item = yield importFileAttachment('test.pdf'); + assert.equal( + (yield Zotero.Fulltext.getIndexedState(item)), + Zotero.Fulltext.INDEX_STATE_UNINDEXED + ); + }) + + it("should skip indexing of a PDF if fulltext.pdfMaxPages is 0", function* () { + Zotero.Prefs.set('fulltext.pdfMaxPages', 0); + var item = yield importFileAttachment('test.pdf'); + assert.equal( + (yield Zotero.Fulltext.getIndexedState(item)), + Zotero.Fulltext.INDEX_STATE_UNINDEXED + ); + }) + }); - it("should skip indexing of a PDF if fulltext.pdfMaxPages is 0", function* () { - Zotero.Prefs.set('fulltext.pdfMaxPages', 0); - var item = yield importFileAttachment('test.pdf'); - assert.equal( - (yield Zotero.Fulltext.getIndexedState(item)), - Zotero.Fulltext.INDEX_STATE_UNINDEXED - ); - }) - }) + describe("#indexPDF()", function () { + it("should create cache files for linked attachments in storage directory", function* () { + var filename = 'test.pdf'; + var file = OS.Path.join(getTestDataDirectory().path, filename); + var tempDir = yield getTempDirectory(); + var linkedFile = OS.Path.join(tempDir, filename); + yield OS.File.copy(file, linkedFile); + + var item = yield Zotero.Attachments.linkFromFile({ file: linkedFile }); + var storageDir = Zotero.Attachments.getStorageDirectory(item).path; + assert.isTrue(yield OS.File.exists(storageDir)); + assert.isTrue(yield OS.File.exists(OS.Path.join(storageDir, '.zotero-ft-info'))); + assert.isTrue(yield OS.File.exists(OS.Path.join(storageDir, '.zotero-ft-cache'))); + assert.isFalse(yield OS.File.exists(OS.Path.join(storageDir, filename))); + }); + }); + }); describe("#downloadPDFTool()", function () { it("should install the PDF tools", function* () {