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

Commit

Permalink
Merge branch 'beta' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmurdoch committed Jan 17, 2020
2 parents 82b3bb8 + e2c10cb commit 4cf4338
Show file tree
Hide file tree
Showing 8 changed files with 1,470 additions and 859 deletions.
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
version: ~> 1.0
language: node_js
node_js:
- "8"
- "10"
- "12"
os:
- linux
- osx
- windows
# using xcode9.2 forces osx 10.12, which is WAAAYYYYYY faster than 10.13
# in fact, we couldn't get osx 10.13 to ever finish the running the tests
osx_image: xcode9.2
git:
autocrlf: false

addons:
apt:
Expand All @@ -19,11 +29,6 @@ before_install:
export LINK="gcc-5";
export LINKXX="g++-5";
fi
- nvm --version
- node --version
- npm --version
- gcc --version
- g++ --version

after_success:
npm run coverage
32 changes: 26 additions & 6 deletions lib/database/filedown.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,46 @@ 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((err, path, fd) => {
tmp.file((err, path, fd, cleanupTmpFile) => {
if (err) {
callback(err);
accessQueue.next(lKey);
return;
}

// write the contents to that temp file
// write the value to our temporary file
fs.writeFile(fd, value, "utf8", (err) => {
if (err) {
cleanupTmpFile();
callback(err);
accessQueue.next(lKey);
return;
}
// move the temp file to its final destination

// It worked! Move the temporary file to its final destination
fs.rename(path, lKey, (err) => {
callback(err);
if (err) {
cleanupTmpFile();
callback(err);
accessQueue.next(lKey);
return;
}

// if there is more work to be done on this key, do it.
accessQueue.next(lKey);
// make sure we close this file descriptor now that the file is no
// longer "temporary" (because we successfully moved it)
fs.close(fd, (err) => {
if (err) {
// at this point things seem to have worked, but juuuussttt in
// case `fs.close` fails, let's log some info so we can try to
// debug it
console.warn("An unexpected file descriptor close error occured: ", err);
cleanupTmpFile();
}
callback();

// if there is more work to be done on this key, do it.
accessQueue.next(lKey);
});
});
});
});
Expand Down

0 comments on commit 4cf4338

Please sign in to comment.