Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: cleanup fd lchown and lchownSync #18329

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,20 +1330,16 @@ if (constants.O_SYMLINK !== undefined) {
};

fs.lchmodSync = function(path, mode) {
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK);
const fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK);

// Prefer to return the chmod error, if one occurs,
// but still try to close, and report closing errors if they occur.
var ret;
let ret;
try {
ret = fs.fchmodSync(fd, mode);
} catch (err) {
try {
fs.closeSync(fd);
} catch (ignore) {}
throw err;
} finally {
fs.closeSync(fd);
}
fs.closeSync(fd);
return ret;
};
}
Expand Down Expand Up @@ -1381,13 +1377,25 @@ if (constants.O_SYMLINK !== undefined) {
callback(err);
return;
}
fs.fchown(fd, uid, gid, callback);
// Prefer to return the chown error, if one occurs,
// but still try to close, and report closing errors if they occur.
fs.fchown(fd, uid, gid, function(err) {
fs.close(fd, function(err2) {
callback(err || err2);
});
});
});
};

fs.lchownSync = function(path, uid, gid) {
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK);
return fs.fchownSync(fd, uid, gid);
const fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK);
let ret;
try {
ret = fs.fchownSync(fd, uid, gid);
} finally {
fs.closeSync(fd);
}
return ret;
};
}

Expand Down