From e5a0c197bde58faac49a932807e7dca677beae7b Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 5 May 2018 19:42:35 -0400 Subject: [PATCH] fs: refactor promises version of lchown and lchmod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check for platform support first to save a level of indentation. PR-URL: https://github.com/nodejs/node/pull/20551 Reviewed-By: Сковорода Никита Андреевич Reviewed-By: James M Snell Reviewed-By: Refael Ackermann --- lib/internal/fs/promises.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index eb913adcbf9..a80a5283c52 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -376,21 +376,19 @@ async function chmod(path, mode) { } async function lchmod(path, mode) { - if (O_SYMLINK !== undefined) { - const fd = await open(path, - O_WRONLY | O_SYMLINK); - return fchmod(fd, mode).finally(fd.close.bind(fd)); - } - throw new ERR_METHOD_NOT_IMPLEMENTED(); + if (O_SYMLINK === undefined) + throw new ERR_METHOD_NOT_IMPLEMENTED(); + + const fd = await open(path, O_WRONLY | O_SYMLINK); + return fchmod(fd, mode).finally(fd.close.bind(fd)); } async function lchown(path, uid, gid) { - if (O_SYMLINK !== undefined) { - const fd = await open(path, - O_WRONLY | O_SYMLINK); - return fchown(fd, uid, gid).finally(fd.close.bind(fd)); - } - throw new ERR_METHOD_NOT_IMPLEMENTED(); + if (O_SYMLINK === undefined) + throw new ERR_METHOD_NOT_IMPLEMENTED(); + + const fd = await open(path, O_WRONLY | O_SYMLINK); + return fchown(fd, uid, gid).finally(fd.close.bind(fd)); } async function fchown(handle, uid, gid) {