Skip to content

Commit

Permalink
fix: Ensure synchronous tmpfile writes, deletes
Browse files Browse the repository at this point in the history
Ensure synchronous tmpfile writes, deletes
  • Loading branch information
Dexus committed Apr 9, 2018
2 parents 371cc25 + 85a00fb commit 37d7cdd
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/openssl.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,25 @@ function spawnWrapper (params, tmpfiles, binary, callback) {

if (tmpfiles) {
tmpfiles = [].concat(tmpfiles)
params.forEach(function (value, i) {
var fpath
if (value === '--TMPFILE--') {
var fpath, i
for (i = 0; i < params.length; i++) {
if (params[i] === '--TMPFILE--') {
fpath = pathlib.join(tempDir, crypto.randomBytes(20).toString('hex'))
files.push({
path: fpath,
contents: tmpfiles.shift()
})
params[i] = fpath
delTempPWFiles[delTempPWFiles.length] = fpath
delTempPWFiles.push(fpath)
}
})
}
}

// TODO: need to refactored
files.forEach(function (file) {
var file
for (i = 0; i < files.length; i++) {
file = files[i]
fs.writeFileSync(file.path, file.contents)
})
}

spawn(params, binary, function (err, code, stdout, stderr) {
helper.deleteTempFiles(delTempPWFiles, function (fsErr) {
Expand Down

0 comments on commit 37d7cdd

Please sign in to comment.