mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Fix ENOENT error on first start when no user dir (#1711)
* Fix ENOENT error on first start when no user dir Write backup using `copySync` and move it below the `fsync` to ensure file is present when backup is made. * Check for path to exist before attempting backup
This commit is contained in:
		
				
					committed by
					
						 Nick O'Leary
						Nick O'Leary
					
				
			
			
				
	
			
			
			
						parent
						
							53e3e08d70
						
					
				
				
					commit
					6fa0d671c0
				
			| @@ -80,28 +80,26 @@ module.exports = { | ||||
|      */ | ||||
|      writeFile: function(path,content,backupPath) { | ||||
|          if (backupPath) { | ||||
|              try { | ||||
|                  fs.renameSync(path,backupPath); | ||||
|              } catch(err) { | ||||
|                  console.log(err); | ||||
|              } | ||||
|          } | ||||
|          return when.promise(function(resolve,reject) { | ||||
|              var stream = fs.createWriteStream(path); | ||||
|              stream.on('open',function(fd) { | ||||
|                  stream.write(content,'utf8',function() { | ||||
|                      fs.fsync(fd,function(err) { | ||||
|                          if (err) { | ||||
|                              log.warn(log._("storage.localfilesystem.fsync-fail",{path: path, message: err.toString()})); | ||||
|                          } | ||||
|                          stream.end(resolve); | ||||
|                      }); | ||||
|                  }); | ||||
|              }); | ||||
|              stream.on('error',function(err) { | ||||
|                  reject(err); | ||||
|              }); | ||||
|          }); | ||||
|             if (fs.existsSync(path)) { | ||||
|                 fs.renameSync(path,backupPath); | ||||
|             } | ||||
|         } | ||||
|         return when.promise(function(resolve,reject) { | ||||
|             var stream = fs.createWriteStream(path); | ||||
|             stream.on('open',function(fd) { | ||||
|                 stream.write(content,'utf8',function() { | ||||
|                     fs.fsync(fd,function(err) { | ||||
|                         if (err) { | ||||
|                             log.warn(log._("storage.localfilesystem.fsync-fail",{path: path, message: err.toString()})); | ||||
|                         } | ||||
|                         stream.end(resolve); | ||||
|                     }); | ||||
|                 }); | ||||
|             }); | ||||
|             stream.on('error',function(err) { | ||||
|                 reject(err); | ||||
|             }); | ||||
|         }); | ||||
|      }, | ||||
|     readFile: readFile, | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user