Skip to content

Commit

Permalink
Fixed updating of config
Browse files Browse the repository at this point in the history
  • Loading branch information
Download committed Feb 13, 2021
1 parent 5eee698 commit f52ed9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 14 additions & 12 deletions mods/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ var read = require('./read')
var update = require('./update')
var notify = require('./notify')
var watch = require('./watch')

module.exports = {
var config = module.exports = {
use: [
require('../settings'),
],
Expand All @@ -22,23 +21,26 @@ module.exports = {
},

get: function(result, name) {
var ulog = this
if (!ulog.config) {
ulog.config = {};
var newCfg = read(ulog)
var changed = update(ulog.config, newCfg)
if (changed.length) notify(ulog, changed)
watch(ulog)
if (! this.config) {
config.update(this)
}
if (!result) {
var settings = grab(ulog, 'settings', {})
var settings = grab(this, 'settings', {})
name = settings[name] && settings[name].config || name
result = ulog.config[name]
result = this.config[name]
}
return result
},

update: function(ulog) {
ulog.config = ulog.config || {}
var newCfg = read(ulog)
var changed = update(ulog.config, newCfg)
if (changed.length) notify(ulog, changed)
watch(ulog)
},

set: function(name) {
if (name === 'log_config') this.config = read(this)
if (name === 'log_config') config.update(this)
}
}
2 changes: 2 additions & 0 deletions mods/config/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ var notify = require('./notify')

module.exports = function(ulog) {
var filename = path.resolve(ulog.get('log_config') || 'log.config')
console.info('watching ' + filename)
try {
fs.watch(filename, { persistent: false }, function() {
console.info(filename + ' changed. reading it again')
read(ulog, function(cfg){
var changed = update(ulog.config, cfg)
if (changed.length) notify(ulog, changed)
Expand Down

0 comments on commit f52ed9e

Please sign in to comment.