From f54958ef2f6f66213f300f4fd2322e8d8c802e28 Mon Sep 17 00:00:00 2001 From: Masashi Hirano Date: Thu, 21 Jun 2018 13:02:54 +0900 Subject: [PATCH] fs: fix fsPromises.lchmod error on non-Mac MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Weijia Wang Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Trivikram Kamat Reviewed-By: Yuta Hiroto --- lib/internal/fs/promises.js | 2 +- test/parallel/test-fs-promises.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index bf8a1f2f6a0..fac430bbe22 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -371,7 +371,7 @@ async function chmod(path, mode) { async function lchmod(path, mode) { 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); return fchmod(fd, mode).finally(fd.close.bind(fd)); diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index 6871a6762b6..602f1191b7a 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -140,15 +140,26 @@ function verifyStatObject(stat) { (await realpath(newLink)).toLowerCase()); assert.strictEqual(newPath.toLowerCase(), (await readlink(newLink)).toLowerCase()); + + const newMode = 0o666; if (common.isOSX) { // lchmod is only available on macOS - const newMode = 0o666; await lchmod(newLink, newMode); stats = await lstat(newLink); 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); }