From 383eac465731aba582379eace47a72c8ec8ce9bd Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 22 Feb 2017 19:53:48 -0500 Subject: [PATCH] Use same directory for OS.File.moveAtomic() temp file Using the main temp directory was causing writes to fail when storage was on another filesystem. --- chrome/content/zotero/xpcom/file.js | 8 +------- test/tests/fileTest.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 237b1181b8..b9289e7009 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -381,13 +381,7 @@ Zotero.File = new function(){ path, data, { - // Note: this will fail on Windows if the temp - // directory is on a different drive from - // destination path - tmpPath: OS.Path.join( - Zotero.getTempDirectory().path, - OS.Path.basename(path) + ".tmp" - ), + tmpPath: path + ".tmp", encoding: charset ? charset.toLowerCase() : 'utf-8' } )); diff --git a/test/tests/fileTest.js b/test/tests/fileTest.js index d8c2cc99cf..939076c529 100644 --- a/test/tests/fileTest.js +++ b/test/tests/fileTest.js @@ -82,6 +82,20 @@ describe("Zotero.File", function () { }); }); + describe("#putContentsAsync()", function () { + it("should save via .tmp file", function* () { + var tmpDir = yield getTempDirectory(); + var destFile = OS.Path.join(tmpDir, 'test.txt') + var tmpFile = destFile + ".tmp"; + yield Zotero.File.putContentsAsync(tmpFile, 'A'); + assert.isTrue(yield OS.File.exists(tmpFile)); + yield Zotero.File.putContentsAsync(destFile, 'B'); + assert.isFalse(yield OS.File.exists(tmpFile)); + // Make sure .tmp file created when creating temp file was deleted too + assert.isFalse(yield OS.File.exists(tmpFile + '.tmp')); + }); + }); + describe("#copyDirectory()", function () { it("should copy all files within a directory", function* () { var tmpDir = Zotero.getTempDirectory().path;