From edc858b97e8f21f9120d918fe22890baa4d145fe 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 0857fd2ffff..59b46c986ce 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -378,21 +378,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) {