Commit 98073738664294ded7f111ec6d6a62529686182e
Merge pull request #585 from ssbc/fix-config-file-read
Fix config file readChristian 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.js | changed |
plugins/plugins.js | ||
---|---|---|
@@ -60,16 +60,30 @@ | ||
60 | 60 | // write the plugin config to ~/.ssb/config |
61 | 61 | function writePluginConfig (pluginName, value) { |
62 | 62 | var cfgPath = path.join(config.path, 'config') |
63 | 63 | // 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 | + } | |
65 | 76 | |
66 | - // update the plugins config | |
67 | - existingConfig.plugins = existingConfig.plugins || {} | |
68 | - existingConfig.plugins[pluginName] = value | |
69 | 77 | |
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 | + | |
72 | 86 | } |
73 | 87 | |
74 | 88 | return { |
75 | 89 | install: valid.source(function (pluginName, opts) { |
Built with git-ssb-web