fs: fix fsPromises.lchmod error on non-Mac
On non-macOS, fsPromises.lchmod throws AssertionError. Expected behavior is `Error [ERR_METHOD_NOT_IMPLEMENTED]`. `ERR_METHOD_NOT_IMPLEMENTED()` requires argument, but it wasn't set. Fixes `ERR_METHOD_NOT_IMPLEMENTED()` to `ERR_METHOD_NOT_IMPLEMENTED('lchmod()')`. PR-URL: https://github.com/nodejs/node/pull/21435 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
This commit is contained in:
parent
094346c955
commit
f54958ef2f
@ -371,7 +371,7 @@ async function chmod(path, mode) {
|
|||||||
|
|
||||||
async function lchmod(path, mode) {
|
async function lchmod(path, mode) {
|
||||||
if (O_SYMLINK === undefined)
|
if (O_SYMLINK === undefined)
|
||||||
throw new ERR_METHOD_NOT_IMPLEMENTED();
|
throw new ERR_METHOD_NOT_IMPLEMENTED('lchmod()');
|
||||||
|
|
||||||
const fd = await open(path, O_WRONLY | O_SYMLINK);
|
const fd = await open(path, O_WRONLY | O_SYMLINK);
|
||||||
return fchmod(fd, mode).finally(fd.close.bind(fd));
|
return fchmod(fd, mode).finally(fd.close.bind(fd));
|
||||||
|
@ -140,15 +140,26 @@ function verifyStatObject(stat) {
|
|||||||
(await realpath(newLink)).toLowerCase());
|
(await realpath(newLink)).toLowerCase());
|
||||||
assert.strictEqual(newPath.toLowerCase(),
|
assert.strictEqual(newPath.toLowerCase(),
|
||||||
(await readlink(newLink)).toLowerCase());
|
(await readlink(newLink)).toLowerCase());
|
||||||
|
|
||||||
|
const newMode = 0o666;
|
||||||
if (common.isOSX) {
|
if (common.isOSX) {
|
||||||
// lchmod is only available on macOS
|
// lchmod is only available on macOS
|
||||||
const newMode = 0o666;
|
|
||||||
await lchmod(newLink, newMode);
|
await lchmod(newLink, newMode);
|
||||||
stats = await lstat(newLink);
|
stats = await lstat(newLink);
|
||||||
assert.strictEqual(stats.mode & 0o777, newMode);
|
assert.strictEqual(stats.mode & 0o777, newMode);
|
||||||
|
} else {
|
||||||
|
await Promise.all([
|
||||||
|
assert.rejects(
|
||||||
|
lchmod(newLink, newMode),
|
||||||
|
common.expectsError({
|
||||||
|
code: 'ERR_METHOD_NOT_IMPLEMENTED',
|
||||||
|
type: Error,
|
||||||
|
message: 'The lchmod() method is not implemented'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await unlink(newLink);
|
await unlink(newLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user