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

Catch readonly write errors more cleanly

Fail more cleanly when run from a readonly files system without setting readOnly true.
This commit is contained in:
Dave Conway-Jones 2018-08-26 10:49:53 +01:00
parent 3169f93cc2
commit ffa65afbb2
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
3 changed files with 15 additions and 3 deletions

11
red.js
View File

@ -101,8 +101,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. Is file system Read Only ?");
console.log("You may want to set readOnly: true, in settings.js");
process.exit(1);
}
} else { } else {
// Use default settings.js as it has been modified // Use default settings.js as it has been modified
settingsFile = defaultSettings; settingsFile = defaultSettings;

View File

@ -142,6 +142,7 @@
"restore": "Restoring __type__ file backup : __path__", "restore": "Restoring __type__ file backup : __path__",
"restore-fail": "Restoring __type__ file backup failed : __message__", "restore-fail": "Restoring __type__ file backup failed : __message__",
"fsync-fail": "Flushing file __path__ to disk failed : __message__", "fsync-fail": "Flushing file __path__ to disk failed : __message__",
"fwrite-fail": "Writing backup file __path__ to disk failed.",
"projects": { "projects": {
"changing-project": "Setting active project : __project__", "changing-project": "Setting active project : __project__",
"active-project": "Active project : __project__", "active-project": "Active project : __project__",

View File

@ -81,7 +81,11 @@ module.exports = {
writeFile: function(path,content,backupPath) { writeFile: function(path,content,backupPath) {
if (backupPath) { if (backupPath) {
if (fs.existsSync(path)) { if (fs.existsSync(path)) {
fs.renameSync(path,backupPath); try {
fs.renameSync(path,backupPath);
} catch(e) {
log.warn(log._("storage.localfilesystem.fwrite-fail",{path:path}));
}
} }
} }
return when.promise(function(resolve,reject) { return when.promise(function(resolve,reject) {