made sure the var dir can be created if needed

looks like the var directory is not present when goldilocks is npm installed
This commit is contained in:
tigerbot 2017-06-01 13:06:52 -06:00
parent dda3dffb17
commit d5dee498f5
3 changed files with 25 additions and 6 deletions

View File

@ -94,7 +94,13 @@ module.exports = function (myDeps, conf, overrideHttp) {
obj.id = id;
owners[id] = obj;
return fs.writeFileAsync(ownersPath, JSON.stringify(owners), 'utf8');
return fs.mkdirAsync(path.dirname(ownersPath)).catch(function (err) {
if (err.code !== 'EEXIST') {
console.error('failed to mkdir', path.dirname(ownersPath), err.toString());
}
}).then(function () {
return fs.writeFileAsync(ownersPath, JSON.stringify(owners), 'utf8');
});
}
};

View File

@ -2,7 +2,8 @@
var PromiseA = require('bluebird');
var fs = PromiseA.promisifyAll(require('fs'));
var idFilename = require('path').join(__dirname, '..', 'var', 'mdns-id');
var path = require('path');
var idFilename = path.join(__dirname, '..', 'var', 'mdns-id');
var queryName = '_cloud._tcp.local';
var randomId = {
@ -18,10 +19,15 @@ var randomId = {
}
, set: function (value) {
return fs.writeFileAsync(idFilename, value)
.then(function () {
return fs.mkdirAsync(path.dirname(idFilename)).catch(function (err) {
if (err.code !== 'EEXIST') {
console.error('failed to mkdir', path.dirname(idFilename), err.toString());
}
}).then(function () {
return fs.writeFileAsync(idFilename, value).then(function () {
return value;
});
});
}
};

View File

@ -6,7 +6,8 @@ module.exports.create = function (deps, config) {
var stunnel = require('stunnel');
var activeTunnels = {};
var tokensPath = require('path').join(__dirname, '..', 'var', 'tokens.json');
var path = require('path');
var tokensPath = path.join(__dirname, '..', 'var', 'tokens.json');
var storage = {
_read: function () {
var tokens;
@ -18,7 +19,13 @@ module.exports.create = function (deps, config) {
return tokens;
}
, _write: function (tokens) {
return fs.writeFileAsync(tokensPath, JSON.stringify(tokens), 'utf8');
return fs.mkdirAsync(path.dirname(tokensPath)).catch(function (err) {
if (err.code !== 'EEXIST') {
console.error('failed to mkdir', path.dirname(tokensPath), err.toString());
}
}).then(function () {
return fs.writeFileAsync(tokensPath, JSON.stringify(tokens), 'utf8');
});
}
, all: function () {