mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
fs: fix rmSync error code
Return the correct error code, when a directory_not_empty error occurred. Fixes: https://github.com/nodejs/node/issues/57095 PR-URL: https://github.com/nodejs/node/pull/57103 Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
c864dea910
commit
f52a358217
|
|
@ -1705,7 +1705,8 @@ static void RmSync(const FunctionCallbackInfo<Value>& args) {
|
||||||
return env->ThrowErrnoException(EPERM, "rm", message.c_str(), path_c_str);
|
return env->ThrowErrnoException(EPERM, "rm", message.c_str(), path_c_str);
|
||||||
} else if (error == std::errc::directory_not_empty) {
|
} else if (error == std::errc::directory_not_empty) {
|
||||||
std::string message = "Directory not empty: " + file_path_str;
|
std::string message = "Directory not empty: " + file_path_str;
|
||||||
return env->ThrowErrnoException(EACCES, "rm", message.c_str(), path_c_str);
|
return env->ThrowErrnoException(
|
||||||
|
ENOTEMPTY, "rm", message.c_str(), path_c_str);
|
||||||
} else if (error == std::errc::not_a_directory) {
|
} else if (error == std::errc::not_a_directory) {
|
||||||
std::string message = "Not a directory: " + file_path_str;
|
std::string message = "Not a directory: " + file_path_str;
|
||||||
return env->ThrowErrnoException(ENOTDIR, "rm", message.c_str(), path_c_str);
|
return env->ThrowErrnoException(ENOTDIR, "rm", message.c_str(), path_c_str);
|
||||||
|
|
|
||||||
|
|
@ -481,12 +481,20 @@ if (isGitPresent) {
|
||||||
// IBMi has a different access permission mechanism
|
// IBMi has a different access permission mechanism
|
||||||
// This test should not be run as `root`
|
// This test should not be run as `root`
|
||||||
if (!common.isIBMi && (common.isWindows || process.getuid() !== 0)) {
|
if (!common.isIBMi && (common.isWindows || process.getuid() !== 0)) {
|
||||||
function makeDirectoryReadOnly(dir, mode) {
|
function makeDirectoryReadOnly(dir, allowExecute) {
|
||||||
let accessErrorCode = 'EACCES';
|
let accessErrorCode = 'EACCES';
|
||||||
|
if (common.isMacOS && allowExecute) {
|
||||||
|
accessErrorCode = 'ENOTEMPTY';
|
||||||
|
}
|
||||||
if (common.isWindows) {
|
if (common.isWindows) {
|
||||||
accessErrorCode = 'EPERM';
|
accessErrorCode = 'EPERM';
|
||||||
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(DE,DC)"`);
|
const permissions = ['DE', 'DC'];
|
||||||
|
if (!allowExecute) {
|
||||||
|
permissions.push('X');
|
||||||
|
}
|
||||||
|
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(${permissions.join(',')})"`);
|
||||||
} else {
|
} else {
|
||||||
|
const mode = allowExecute ? 0o555 : 0o444;
|
||||||
fs.chmodSync(dir, mode);
|
fs.chmodSync(dir, mode);
|
||||||
}
|
}
|
||||||
return accessErrorCode;
|
return accessErrorCode;
|
||||||
|
|
@ -510,7 +518,7 @@ if (isGitPresent) {
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(dirname, common.mustNotMutateObjectDeep({ recursive: true }));
|
fs.mkdirSync(dirname, common.mustNotMutateObjectDeep({ recursive: true }));
|
||||||
fs.writeFileSync(filePath, 'hello');
|
fs.writeFileSync(filePath, 'hello');
|
||||||
const code = makeDirectoryReadOnly(dirname, 0o444);
|
const code = makeDirectoryReadOnly(dirname, false);
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
fs.rmSync(filePath, common.mustNotMutateObjectDeep({ force: true }));
|
fs.rmSync(filePath, common.mustNotMutateObjectDeep({ force: true }));
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -532,7 +540,7 @@ if (isGitPresent) {
|
||||||
fs.mkdirSync(middle);
|
fs.mkdirSync(middle);
|
||||||
fs.mkdirSync(path.join(middle, 'leaf')); // Make `middle` non-empty
|
fs.mkdirSync(path.join(middle, 'leaf')); // Make `middle` non-empty
|
||||||
try {
|
try {
|
||||||
const code = makeDirectoryReadOnly(middle, 0o555);
|
const code = makeDirectoryReadOnly(middle, true);
|
||||||
try {
|
try {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
fs.rmSync(root, common.mustNotMutateObjectDeep({ recursive: true }));
|
fs.rmSync(root, common.mustNotMutateObjectDeep({ recursive: true }));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user