git ssb

4+

Dominic / scuttlebot



Commit 98073738664294ded7f111ec6d6a62529686182e

Merge pull request #585 from ssbc/fix-config-file-read

Fix config file read
Christian Bundy authored on 12/5/2018, 7:45:58 PM
GitHub committed on 12/5/2018, 7:45:58 PM
Parent: 578b2a34c0687eb0fd2d81aab441cd58b94d3414
Parent: 569d06ffa593490456dc62fd1e9046dae46c26c3

Files changed

plugins/plugins.jschanged
plugins/plugins.jsView
@@ -60,16 +60,30 @@
6060 // write the plugin config to ~/.ssb/config
6161 function writePluginConfig (pluginName, value) {
6262 var cfgPath = path.join(config.path, 'config')
6363 // load ~/.ssb/config
64- var existingConfig = JSON.parse(fs.readFileSync(cfgPath, 'utf-8'))
64+ let existingConfig
65+ fs.readFile(cfgPath, 'utf-8', (err, data) => {
66+ if (err) {
67+ if (err.code === 'ENOENT') {
68+ // only catch "file not found"
69+ existingConfig = {}
70+ } else {
71+ throw err
72+ }
73+ } else {
74+ existingConfig = JSON.parse(data)
75+ }
6576
66- // update the plugins config
67- existingConfig.plugins = existingConfig.plugins || {}
68- existingConfig.plugins[pluginName] = value
6977
70- // write to disc
71- fs.writeFileSync(cfgPath, JSON.stringify(existingConfig, null, 2), 'utf-8')
78+ // update the plugins config
79+ existingConfig.plugins = existingConfig.plugins || {}
80+ existingConfig.plugins[pluginName] = value
81+
82+ // write to disc
83+ fs.writeFileSync(cfgPath, JSON.stringify(existingConfig, null, 2), 'utf-8')
84+ })
85+
7286 }
7387
7488 return {
7589 install: valid.source(function (pluginName, opts) {

Built with git-ssb-web