Skip to content

Commit edc858b

Browse files
committed
fs: refactor promises version of lchown and lchmod
Check for platform support first to save a level of indentation. PR-URL: #20551 Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 1e98787 commit edc858b

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

lib/internal/fs/promises.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,19 @@ async function chmod(path, mode) {
378378
}
379379

380380
async function lchmod(path, mode) {
381-
if (O_SYMLINK !== undefined) {
382-
const fd = await open(path,
383-
O_WRONLY | O_SYMLINK);
384-
return fchmod(fd, mode).finally(fd.close.bind(fd));
385-
}
386-
throw new ERR_METHOD_NOT_IMPLEMENTED();
381+
if (O_SYMLINK === undefined)
382+
throw new ERR_METHOD_NOT_IMPLEMENTED();
383+
384+
const fd = await open(path, O_WRONLY | O_SYMLINK);
385+
return fchmod(fd, mode).finally(fd.close.bind(fd));
387386
}
388387

389388
async function lchown(path, uid, gid) {
390-
if (O_SYMLINK !== undefined) {
391-
const fd = await open(path,
392-
O_WRONLY | O_SYMLINK);
393-
return fchown(fd, uid, gid).finally(fd.close.bind(fd));
394-
}
395-
throw new ERR_METHOD_NOT_IMPLEMENTED();
389+
if (O_SYMLINK === undefined)
390+
throw new ERR_METHOD_NOT_IMPLEMENTED();
391+
392+
const fd = await open(path, O_WRONLY | O_SYMLINK);
393+
return fchown(fd, uid, gid).finally(fd.close.bind(fd));
396394
}
397395

398396
async function fchown(handle, uid, gid) {

0 commit comments

Comments
 (0)