From 17cece5c606db00d47c0fddf33129a152f0d7389 Mon Sep 17 00:00:00 2001 From: David Murdoch Date: Sat, 8 Feb 2020 15:21:47 -0500 Subject: [PATCH 1/2] Fix db write error on paritioned drives --- lib/database/filedown.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/database/filedown.js b/lib/database/filedown.js index 637d7e0f35..786c5252ae 100644 --- a/lib/database/filedown.js +++ b/lib/database/filedown.js @@ -9,6 +9,18 @@ util.inherits(FileDown, AbstractLevelDOWN); function FileDown(location) { this.location = location; + const tmpDir = path.join(location, "_tmp"); + try { + fs.mkdirSync(tmpDir, { recursive: true, mode: 0o1777 }); + } catch (e) { + // `recursive` doesn't throw if the file exists, but `recursive` doesn't + // exist in Node 8, so we catch the EEXISTS error in that case and ignore it. + // once we drop node 8 suport we can remove this try/catch + if (e.code !== "EEXIST") { + throw e; + } + } + this.tmpOptions = { keep: true, dir: tmpDir }; AbstractLevelDOWN.call(this, location); } @@ -79,7 +91,7 @@ FileDown.prototype._put = function(key, value, options, callback) { // leveldb implementation that doesn't use a separate file for every key Soon(TM). accessQueue.execute(lKey, () => { // get a tmp file to write the contents to... - tmp.file({ keep: true }, (err, path, fd, cleanupTmpFile) => { + tmp.file(this.tmpOptions, (err, path, fd, cleanupTmpFile) => { if (err) { callback(err); accessQueue.next(lKey); From d6698aaef20b7648c97c8e51a64a00ba22a20d88 Mon Sep 17 00:00:00 2001 From: David Murdoch Date: Wed, 12 Feb 2020 17:31:32 -0500 Subject: [PATCH 2/2] Add comment about what bug the tmpDir fixes --- lib/database/filedown.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/database/filedown.js b/lib/database/filedown.js index 786c5252ae..5c7f195a11 100644 --- a/lib/database/filedown.js +++ b/lib/database/filedown.js @@ -11,6 +11,7 @@ function FileDown(location) { this.location = location; const tmpDir = path.join(location, "_tmp"); try { + // Fixes https://github.com/trufflesuite/ganache/issues/1617 fs.mkdirSync(tmpDir, { recursive: true, mode: 0o1777 }); } catch (e) { // `recursive` doesn't throw if the file exists, but `recursive` doesn't