From 8ec81a80fa9ebcd88eb9bc752d0925b6d1030f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jussi=20R=C3=A4s=C3=A4nen?= Date: Sat, 16 Sep 2017 00:08:11 +0300 Subject: [PATCH] fs: add O_DSYNC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backport-PR-URL: https://github.com/nodejs/node/pull/15653 PR-URL: https://github.com/nodejs/node/pull/15451 Fixes: https://github.com/nodejs/node/issues/15425 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen --- doc/api/fs.md | 5 +++++ src/node_constants.cc | 5 +++++ test/parallel/test-fs-open-flags.js | 12 ++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 729a4c51e46874..fc511bf7fe5585 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2869,6 +2869,11 @@ The following constants are meant for use with `fs.open()`. O_SYNC Flag indicating that the file is opened for synchronous I/O. + + O_DSYNC + Flag indicating that the file is opened for synchronous I/O + with write operations waiting for data integrity. + O_SYMLINK Flag indicating to open the symbolic link itself rather than the diff --git a/src/node_constants.cc b/src/node_constants.cc index 8b074050549ede..1023ada3e61fb5 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -1085,6 +1085,11 @@ void DefineSystemConstants(Local target) { NODE_DEFINE_CONSTANT(target, O_SYNC); #endif +#ifdef O_DSYNC + NODE_DEFINE_CONSTANT(target, O_DSYNC); +#endif + + #ifdef O_SYMLINK NODE_DEFINE_CONSTANT(target, O_SYMLINK); #endif diff --git a/test/parallel/test-fs-open-flags.js b/test/parallel/test-fs-open-flags.js index 742b997e60551d..e4bc8610998eb6 100644 --- a/test/parallel/test-fs-open-flags.js +++ b/test/parallel/test-fs-open-flags.js @@ -21,9 +21,8 @@ // Flags: --expose_internals 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); - const fs = require('fs'); const O_APPEND = fs.constants.O_APPEND || 0; @@ -32,6 +31,7 @@ const O_EXCL = fs.constants.O_EXCL || 0; const O_RDONLY = fs.constants.O_RDONLY || 0; const O_RDWR = fs.constants.O_RDWR || 0; const O_SYNC = fs.constants.O_SYNC || 0; +const O_DSYNC = fs.constants.O_DSYNC || 0; const O_TRUNC = fs.constants.O_TRUNC || 0; const O_WRONLY = fs.constants.O_WRONLY || 0; @@ -79,6 +79,14 @@ assert.throws( /^Error: Unknown file open flag: null$/ ); +if (common.isLinux === true) { + const file = `${__dirname}/../fixtures/a.js`; + + fs.open(file, O_DSYNC, common.mustCall(function(err, fd) { + assert.ifError(err); + })); +} + function escapeRegExp(string) { return string.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); }