Skip to content
Merged
Changes from 1 commit
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
Next Next commit
test,fs: add fs.rm() tests for .git directories
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: #38810 (comment)
Signed-off-by: Darshan Sen <[email protected]>
  • Loading branch information
RaisinTen committed Mar 20, 2022
commit 7edad00f11a682fbffa6636f3c7a1300b6d79e41
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