From a5e139940b2b70cb6b5867a26441ab3c7f5a217a Mon Sep 17 00:00:00 2001 From: Liviu Ionescu Date: Fri, 15 Apr 2022 14:42:46 +0300 Subject: [PATCH 1/4] [#41591] define S_IWUSR & S_IRUSR for Windows --- src/node_constants.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/node_constants.cc b/src/node_constants.cc index 38c8f2738b4bad..3269e3003acd4d 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -47,6 +47,16 @@ #include #endif +#if defined(_WIN32) +#include // _S_IREAD _S_IWRITE +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif // S_IRUSR +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif // S_IWUSR +#endif + #include #include #include From 62e3b8f053215971d4e9f32699235cd7178dc011 Mon Sep 17 00:00:00 2001 From: Liviu Ionescu Date: Fri, 15 Apr 2022 14:48:41 +0300 Subject: [PATCH 2/4] src: define S_IWUSR & S_IRUSR for Windows On Windows, most of the POSIX file mode definitions are not available. However, functionally equivalent read/write definitions exists, and `chmod()` can use them. This patch defines two aliases, so that these definintions are issued in `fs.constants`. https://github.com/nodejs/node/issues/41591 --- src/node_constants.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/node_constants.cc b/src/node_constants.cc index 38c8f2738b4bad..3269e3003acd4d 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -47,6 +47,16 @@ #include #endif +#if defined(_WIN32) +#include // _S_IREAD _S_IWRITE +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif // S_IRUSR +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif // S_IWUSR +#endif + #include #include #include From 71fbff0bf8849b26a838c7a6650b17d649424044 Mon Sep 17 00:00:00 2001 From: Liviu Ionescu Date: Fri, 15 Apr 2022 14:48:41 +0300 Subject: [PATCH 3/4] src: define S_IWUSR & S_IRUSR for Windows On Windows, most of the POSIX file mode definitions are not available. However, functionally equivalent read/write definitions exists, and `chmod()` can use them. This patch defines two aliases, so that these definintions are issued in `fs.constants`. https://github.com/nodejs/node/issues/41591 --- src/node_constants.cc | 10 ++++++++++ test/parallel/test-fs-constants-windows.js | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/parallel/test-fs-constants-windows.js diff --git a/src/node_constants.cc b/src/node_constants.cc index 38c8f2738b4bad..3269e3003acd4d 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -47,6 +47,16 @@ #include #endif +#if defined(_WIN32) +#include // _S_IREAD _S_IWRITE +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif // S_IRUSR +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif // S_IWUSR +#endif + #include #include #include diff --git a/test/parallel/test-fs-constants-windows.js b/test/parallel/test-fs-constants-windows.js new file mode 100644 index 00000000000000..ed22095fc2acd5 --- /dev/null +++ b/test/parallel/test-fs-constants-windows.js @@ -0,0 +1,10 @@ +'use strict'; +const common = require('../common'); +const fs = require('fs'); +const { assert } = require('console'); + +// Check if the two constants accepted by chmod() on Windows are defined. +if (common.isWindows) { + assert(fs.constants.S_IRUSR !== undefined) + assert(fs.constants.S_IWUSR !== undefined) +} From fbe9542ba010dd37440804f41fc3a438b307d21b Mon Sep 17 00:00:00 2001 From: Liviu Ionescu Date: Fri, 15 Apr 2022 14:48:41 +0300 Subject: [PATCH 4/4] src: define fs.constants.S_IWUSR & S_IRUSR for Win On Windows, most of the POSIX file mode definitions are not available. However, functionally equivalent read/write definitions exists, and `chmod()` can use them. This patch defines two aliases, so that these definintions are issued in `fs.constants`. refs: https://github.com/nodejs/node/issues/41591 --- src/node_constants.cc | 10 ++++++++++ test/parallel/test-fs-constants-windows.js | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/parallel/test-fs-constants-windows.js diff --git a/src/node_constants.cc b/src/node_constants.cc index 38c8f2738b4bad..3269e3003acd4d 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -47,6 +47,16 @@ #include #endif +#if defined(_WIN32) +#include // _S_IREAD _S_IWRITE +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif // S_IRUSR +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif // S_IWUSR +#endif + #include #include #include diff --git a/test/parallel/test-fs-constants-windows.js b/test/parallel/test-fs-constants-windows.js new file mode 100644 index 00000000000000..8ca3ac562d7b62 --- /dev/null +++ b/test/parallel/test-fs-constants-windows.js @@ -0,0 +1,10 @@ +'use strict'; +const common = require('../common'); +const fs = require('fs'); +const assert = require('assert'); + +// Check if the two constants accepted by chmod() on Windows are defined. +if (common.isWindows) { + assert(fs.constants.S_IRUSR !== undefined) + assert(fs.constants.S_IWUSR !== undefined) +}