From 8c464a7a8b4ba9c88b1f6c04eacb87baad413fa9 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 20 Jan 2021 06:36:57 -0500 Subject: [PATCH] Add `options` argument for Zotero.File.createDirectoryIfMissingAsync() To allow passing 'from' argument through to OS.File.makeDir() --- chrome/content/zotero/xpcom/file.js | 13 ++++++++----- test/tests/fileTest.js | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index cc17a2927c..9fe1133b66 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -1010,14 +1010,17 @@ Zotero.File = new function(){ } - this.createDirectoryIfMissingAsync = async function (path) { + this.createDirectoryIfMissingAsync = async function (path, options = {}) { try { await OS.File.makeDir( path, - { - ignoreExisting: false, - unixMode: 0o755 - } + Object.assign( + { + ignoreExisting: false, + unixMode: 0o755 + }, + options + ) ) } catch (e) { diff --git a/test/tests/fileTest.js b/test/tests/fileTest.js index 04f3c8bce9..23df1953fb 100644 --- a/test/tests/fileTest.js +++ b/test/tests/fileTest.js @@ -293,6 +293,13 @@ describe("Zotero.File", function () { assert.ok(e); assert.match(e.message, /^Broken symlink/); }); + + it("should handle 'from' in options", async function () { + var tmpPath = await getTempDirectory(); + var path = OS.Path.join(tmpPath, 'a', 'b'); + await Zotero.File.createDirectoryIfMissingAsync(path, { from: tmpPath }); + assert.isTrue(await OS.File.exists(path)); + }); }); describe("#zipDirectory()", function () {