Comparing version 2.0.4 to 2.0.5
73
index.js
@@ -31,12 +31,16 @@ // this entire module is depressing. i should have spent my time learning | ||
var configpath = path.join(userHome || os.tmpdir(), configfile); | ||
// open file for reading and appending. if the filesize is zero | ||
// we will spawn node with --v8-options and write the parsed | ||
// options to a file. if it is larger than zero, we'll just read | ||
// the file and be done. | ||
fs.open(configpath, 'a+', function (err, fd) { | ||
if (err) { | ||
return cb(fail(err)); | ||
} | ||
return cb(null, fd); | ||
}); | ||
var content; | ||
try { | ||
content = require(configpath); | ||
process.nextTick(function () { | ||
cb(null, content); | ||
}); | ||
} catch (e) { | ||
fs.open(configpath, 'w+', function (err, fd) { | ||
if (err) { | ||
return cb(fail(err)); | ||
} | ||
return cb(null, fd); | ||
}); | ||
} | ||
} | ||
@@ -57,15 +61,9 @@ | ||
fs.write(fd, buf, 0, buf.length, 0, function (writeErr, bytesWritten, buffer) { | ||
// linux ignores positional arguments when files are open in append mode. | ||
// the truncate call below ensures that multiple concurrent processes | ||
// trying to write to this config will not result in a file with the | ||
// contents appended multiple times. | ||
fs.ftruncate(fd, buf.length, function (truncErr) { | ||
fs.close(fd, function (closeErr) { | ||
var err = truncErr || writeErr || closeErr; | ||
if (err) { | ||
return cb(fail(err)); | ||
} | ||
return cb(null, JSON.parse(buffer.toString())); | ||
}); | ||
}) | ||
fs.close(fd, function (closeErr) { | ||
var err = writeErr || closeErr; | ||
if (err) { | ||
return cb(fail(err)); | ||
} | ||
return cb(null, JSON.parse(buffer.toString())); | ||
}); | ||
}); | ||
@@ -75,30 +73,11 @@ }); | ||
function readConfig (fd, filesize, cb) { | ||
var buf = new Buffer(filesize); | ||
fs.read(fd, buf, 0, filesize, 0, function (readErr, bytesRead, buffer) { | ||
fs.close(fd, function (closeErr) { | ||
var err = readErr || closeErr; | ||
if (err) { | ||
return cb(fail(err)); | ||
} | ||
return cb(null, JSON.parse(buffer.toString())); | ||
}); | ||
}); | ||
} | ||
module.exports = function (cb) { | ||
openConfig(function (err, fd) { | ||
openConfig(function (err, result) { | ||
if (err) { | ||
return cb(fail(err)); | ||
} | ||
fs.fstat(fd, function (statErr, stats) { | ||
var filesize = stats.size; | ||
if (statErr) { | ||
return cb(fail(statErr)); | ||
} | ||
if (filesize === 0) { | ||
return writeConfig(fd, cb); | ||
} | ||
return readConfig(fd, filesize, cb); | ||
}); | ||
if (typeof result === 'number') { | ||
return writeConfig(result, cb); | ||
} | ||
return cb(null, result); | ||
}); | ||
@@ -105,0 +84,0 @@ }; |
{ | ||
"name": "v8flags", | ||
"description": "Get available v8 flags.", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"homepage": "https://github.com/tkellen/node-v8flags", | ||
@@ -24,3 +24,3 @@ "author": { | ||
"scripts": { | ||
"test": "mocha -R spec test.js" | ||
"test": "_mocha -R spec test.js" | ||
}, | ||
@@ -27,0 +27,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# v8flags [![Build Status](https://secure.travis-ci.org/tkellen/js-v8flags.png)](http://travis-ci.org/tkellen/js-v8flags) [![Build status](https://ci.appveyor.com/api/projects/status/5jpe6yawxdllrok4?svg=true)](https://ci.appveyor.com/project/tkellen/js-v8flags) | ||
# v8flags [![Build Status](https://secure.travis-ci.org/tkellen/js-v8flags.png)](http://travis-ci.org/tkellen/js-v8flags) [![Build status](https://ci.appveyor.com/api/projects/status/9psgmwayx9kpol1a?svg=true)](https://ci.appveyor.com/project/tkellen/js-v8flags) | ||
> Get available v8 flags. | ||
@@ -26,2 +26,3 @@ | ||
* 2015-04-18 - v2.0.5 - attempt to require config file, if this throws for any reason, fopen w+ and re-create | ||
* 2015-04-16 - v2.0.4 - when concurrent processes are run and no config exists, don't append to the cached config. | ||
@@ -28,0 +29,0 @@ * 2015-03-31 - v2.0.3 - prefer to store config files in user home over tmp |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43
6439
76
3