Skip to content

Commit

Permalink
fs: fix rmsync error swallowing
Browse files Browse the repository at this point in the history
fix rmsync swallowing errors instead of throwing them.

fixes: #38683
  • Loading branch information
Linkgoron committed May 13, 2021
1 parent aefc621 commit c9e77f5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/internal/fs/rimraf.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ function _unlinkSync(path, options) {
i < tries &&
options.retryDelay > 0) {
sleep(i * options.retryDelay);
} else {
// The file is already gone.
if (err.code === 'ENOENT') {
return;
}
throw err;
}
}
}
Expand Down Expand Up @@ -259,10 +265,18 @@ function _rmdirSync(path, options, originalErr) {
i < tries &&
options.retryDelay > 0) {
sleep(i * options.retryDelay);
} else {
// The file is already gone.
if (err.code === 'ENOENT') {
return;
}
throw err;
}
}
}
}

throw originalErr;
}
}

Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,24 @@ function removeAsync(dir) {
message: /^The value of "options\.maxRetries" is out of range\./
});
}

{
// Check that deleting a file that cannot be accessed using rmsync throws
const dirname = nextDirPath();
try {
fs.mkdirSync(dirname, { recursive: true });
fs.writeFileSync(path.join(dirname, 'text.txt'), 'hello');
fs.chmodSync(dirname, '500');
assert.throws(() => {
fs.rmSync(`${dirname}/text.txt`, { force: true });
}, {
code: 'EACCES',
syscall: 'unlink',
name: 'Error',
errno: -13,
});
} finally {
fs.chmodSync(dirname, '777');
fs.rmSync(`${dirname}/text.txt`, { force: true });
}
}

0 comments on commit c9e77f5

Please sign in to comment.