Skip to content

Commit

Permalink
test,fs: add fs.rm() tests for .git directories
Browse files Browse the repository at this point in the history
Git for Windows creates read-only files inside the .git directory.
fs.rm() was built in a way, to work around any EPERM error that can
happen while deleting the .git directory by turning the directory
into a writable one. This change adds a regression test for that.

Refs: isaacs/rimraf#21
Refs: nodejs#38810 (comment)
Signed-off-by: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
RaisinTen committed Mar 20, 2022
1 parent 46a0d0d commit 7edad00
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ function removeAsync(dir) {
}));
}

// Removing a .git directory should not throw an EPERM.
// Refs: https://github.com/isaacs/rimraf/issues/21.
{
const gitDirectory = nextDirPath();
fs.mkdirSync(gitDirectory);
execSync(`git -C ${gitDirectory} init`);
fs.rm(gitDirectory, { recursive: true }, common.mustSucceed(() => {
assert.strictEqual(fs.existsSync(gitDirectory), false);
}));
}

// Test the synchronous version.
{
const dir = nextDirPath();
Expand Down Expand Up @@ -179,6 +190,16 @@ function removeAsync(dir) {
assert.throws(() => fs.rmSync(dir), { syscall: 'stat' });
}

// Removing a .git directory should not throw an EPERM.
// Refs: https://github.com/isaacs/rimraf/issues/21.
{
const gitDirectory = nextDirPath();
fs.mkdirSync(gitDirectory);
execSync(`git -C ${gitDirectory} init`);
fs.rmSync(gitDirectory, { recursive: true });
assert.strictEqual(fs.existsSync(gitDirectory), false);
}

// Test the Promises based version.
(async () => {
const dir = nextDirPath();
Expand Down Expand Up @@ -230,6 +251,16 @@ function removeAsync(dir) {
}
})().then(common.mustCall());

// Removing a .git directory should not throw an EPERM.
// Refs: https://github.com/isaacs/rimraf/issues/21.
(async () => {
const gitDirectory = nextDirPath();
fs.mkdirSync(gitDirectory);
execSync(`git -C ${gitDirectory} init`);
await fs.promises.rm(gitDirectory, { recursive: true });
assert.strictEqual(fs.existsSync(gitDirectory), false);
})().then(common.mustCall());

// Test input validation.
{
const dir = nextDirPath();
Expand Down

0 comments on commit 7edad00

Please sign in to comment.