Skip to content

Commit e5a0c19

Browse files
cjihrigMylesBorins
authored andcommitted
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 6ce589f commit e5a0c19

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
@@ -376,21 +376,19 @@ async function chmod(path, mode) {
376376
}
377377

378378
async function lchmod(path, mode) {
379-
if (O_SYMLINK !== undefined) {
380-
const fd = await open(path,
381-
O_WRONLY | O_SYMLINK);
382-
return fchmod(fd, mode).finally(fd.close.bind(fd));
383-
}
384-
throw new ERR_METHOD_NOT_IMPLEMENTED();
379+
if (O_SYMLINK === undefined)
380+
throw new ERR_METHOD_NOT_IMPLEMENTED();
381+
382+
const fd = await open(path, O_WRONLY | O_SYMLINK);
383+
return fchmod(fd, mode).finally(fd.close.bind(fd));
385384
}
386385

387386
async function lchown(path, uid, gid) {
388-
if (O_SYMLINK !== undefined) {
389-
const fd = await open(path,
390-
O_WRONLY | O_SYMLINK);
391-
return fchown(fd, uid, gid).finally(fd.close.bind(fd));
392-
}
393-
throw new ERR_METHOD_NOT_IMPLEMENTED();
387+
if (O_SYMLINK === undefined)
388+
throw new ERR_METHOD_NOT_IMPLEMENTED();
389+
390+
const fd = await open(path, O_WRONLY | O_SYMLINK);
391+
return fchown(fd, uid, gid).finally(fd.close.bind(fd));
394392
}
395393

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

0 commit comments

Comments
 (0)