commit fc4d7fa4bff1b9d639d67c0dd829e7893901f316
parent 37063f639ff6e324f391598718c6a57c344a6ac1
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 2 Jun 2016 00:59:32 -0400
Fix infinite loop in Zotero.File.zipDirectory() on subdirectory
But subdirectories shouldn't actually be used yet, because they won't
extract properly on 4.0.
Diffstat:
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js
@@ -731,7 +731,7 @@ Zotero.File = new function(){
return;
}
if (entry.isDir) {
- entries.concat(yield _addZipEntries(rootPath, path, zipWriter));
+ entries.concat(yield _addZipEntries(rootPath, entry.path, zipWriter));
return;
}
if (entry.name.startsWith('.')) {
diff --git a/test/tests/fileTest.js b/test/tests/fileTest.js
@@ -69,4 +69,41 @@ describe("Zotero.File", function () {
);
})
})
+
+ describe("#zipDirectory()", function () {
+ it("should compress a directory recursively", function* () {
+ var tmpPath = Zotero.getTempDirectory().path;
+ var path = OS.Path.join(tmpPath, Zotero.Utilities.randomString());
+ yield OS.File.makeDir(path);
+ yield Zotero.File.putContentsAsync(OS.Path.join(path, '.zotero-ft-cache'), '');
+ yield Zotero.File.putContentsAsync(OS.Path.join(path, 'a.txt'), 'A');
+ // Create subdirectory
+ var subPath = OS.Path.join(path, 'sub');
+ yield OS.File.makeDir(subPath);
+ yield Zotero.File.putContentsAsync(OS.Path.join(subPath, 'b.txt'), 'B');
+
+ var zipFile = OS.Path.join(tmpPath, 'test.zip');
+ yield Zotero.File.zipDirectory(path, zipFile);
+
+ var zr = Components.classes["@mozilla.org/libjar/zip-reader;1"]
+ .createInstance(Components.interfaces.nsIZipReader);
+ zr.open(Zotero.File.pathToFile(zipFile));
+ var entries = zr.findEntries('*');
+ var files = {};
+ var is = Components.classes['@mozilla.org/scriptableinputstream;1']
+ .createInstance(Components.interfaces.nsIScriptableInputStream);
+ while (entries.hasMore()) {
+ let entryPointer = entries.getNext();
+ let entry = zr.getEntry(entryPointer);
+ let inputStream = zr.getInputStream(entryPointer);
+ is.init(inputStream);
+ files[entryPointer] = is.read(entry.realSize);
+ }
+ zr.close();
+
+ assert.notProperty(files, '.zotero-ft-cache');
+ assert.propertyVal(files, 'a.txt', 'A');
+ assert.propertyVal(files, 'sub/b.txt', 'B');
+ });
+ });
})