Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix: fix db write error on partitioned drives #548

Merged
merged 2 commits into from
Feb 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/database/filedown.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ util.inherits(FileDown, AbstractLevelDOWN);

function FileDown(location) {
this.location = location;
const tmpDir = path.join(location, "_tmp");
try {
// Fixes https://github.com/trufflesuite/ganache/issues/1617
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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
davidmurdoch marked this conversation as resolved.
Show resolved Hide resolved
if (e.code !== "EEXIST") {
throw e;
}
}
this.tmpOptions = { keep: true, dir: tmpDir };
AbstractLevelDOWN.call(this, location);
}

Expand Down Expand Up @@ -79,7 +92,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);
Expand Down