Skip to content

Commit

Permalink
Ensure synchronous tmpfile writes, deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldtilma committed Apr 9, 2018
1 parent 371cc25 commit 85a00fb
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 85a00fb

Please sign in to comment.