Call fsync() before closing file

This commit is contained in:
Jim Turner
2017-11-06 10:19:13 -08:00
parent 2b9aa94f3a
commit da708adcbd
2 changed files with 9 additions and 3 deletions

View File

@@ -114,8 +114,13 @@ function writeFile(path,content) {
return when.promise(function(resolve,reject) {
var stream = fs.createWriteStream(path);
stream.on('open',function(fd) {
stream.end(content,'utf8',function() {
fs.fsync(fd,resolve);
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) {