1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

simplistic detect can't write settings and set readOnly flag

This commit is contained in:
Dave Conway-Jones 2018-04-06 17:00:34 +01:00
parent 3f41036919
commit c256e27a83
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4

16
red.js
View File

@ -31,6 +31,7 @@ var app = express();
var settingsFile; var settingsFile;
var flowFile; var flowFile;
var readonly;
var knownOpts = { var knownOpts = {
"credentialSecret": String, "credentialSecret": String,
@ -105,8 +106,15 @@ if (parsedArgs.settings) {
var settingsStat = fs.statSync(defaultSettings); var settingsStat = fs.statSync(defaultSettings);
if (settingsStat.mtime.getTime() <= settingsStat.ctime.getTime()) { if (settingsStat.mtime.getTime() <= settingsStat.ctime.getTime()) {
// Default settings file has not been modified - safe to copy // Default settings file has not been modified - safe to copy
fs.copySync(defaultSettings,userSettingsFile); try {
settingsFile = userSettingsFile; fs.copySync(defaultSettings,userSettingsFile);
settingsFile = userSettingsFile;
}
catch (err) {
console.log("Can't copy settings file.");
settingsFile = defaultSettings;
readonly = true;
}
} else { } else {
// Use default settings.js as it has been modified // Use default settings.js as it has been modified
settingsFile = defaultSettings; settingsFile = defaultSettings;
@ -118,6 +126,10 @@ if (parsedArgs.settings) {
try { try {
var settings = require(settingsFile); var settings = require(settingsFile);
settings.settingsFile = settingsFile; settings.settingsFile = settingsFile;
if (readonly === true) {
console.log("Setting to read Only mode.");
settings.readOnly = true;
}
} catch(err) { } catch(err) {
console.log("Error loading settings file: "+settingsFile) console.log("Error loading settings file: "+settingsFile)
if (err.code == 'MODULE_NOT_FOUND') { if (err.code == 'MODULE_NOT_FOUND') {