Commit 1a2cc7b7 authored by Fawzi Mohamed's avatar Fawzi Mohamed
Browse files

atomic write for serviceDumper and templateEvaluer

parent c169a990
......@@ -2,6 +2,7 @@ const yaml = require('js-yaml')
const logger = require('./logger')
const fs = require('fs')
const k8D = require('./k8-data')
const writeFileAtomicSync = require('write-file-atomic').sync
function mergeServices(s1,s2) {
for (let k in s2) {
......@@ -85,7 +86,7 @@ exports.serviceDumper = function(args) {
}
let res = yaml.safeDump(sss, {sortKeys: true})
if (outFile.length > 0)
fs.writeFileSync(outFile, res, {encoding:'utf8'})
writeFileAtomicSync(outFile, res, {encoding:'utf8'})
else
console.log(res)
process.exit(0)
......
......@@ -3,6 +3,7 @@ const logger = require('./logger')
const fs = require('fs')
const stringify = require('json-stringify-safe')
const components = require('./components')
const writeFileAtomicSync = require('write-file-atomic').sync
function mergeServices(s1,s2) {
for (let k in s2) {
......@@ -63,7 +64,7 @@ exports.templateEvaluer = function(args) {
let inF = fs.readFileSync(inFile, {encoding:'utf8'})
let outF = components.templatize(inF)(replacements)
if (outFile.length > 0)
fs.writeFileSync(outFile, outF, { encoding: 'utf8'})
writeFileAtomicSync(outFile, outF, { encoding: 'utf8'})
else
console.log(outF)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment