8000 Properly handle rm -r on links to dirs with a trailing slash · shelljs/shelljs@8000256 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8000256

Browse files
committed
Properly handle rm -r on links to dirs with a trailing slash
1 parent 0ffd22e commit 8000256

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/rm.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ function rmdirSyncRecursive(dir, force, fromSymlink) {
4444

4545
// if was directory was referenced through a symbolic link,
4646
// the contents should be removed, but not the directory itself
47-
if (fromSymlink) return;
47+
if (fromSymlink) {
48+
if (!force) {
49+
common.error("cannot remove '" + dir + "': Not a directory");
50+
}
51+
return;
52+
}
4853

4954
// Now that we know everything in the sub-tree has been deleted, we can delete the main directory.
5055
// Huzzah for the shopkeep.

test/rm.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ test('rm -r, symlink to a dir, trailing slash', t => {
305305
const result = shell.rm('-r', `${t.context.tmp}/rm/link_to_a_dir/`);
306306
t.truthy(shell.error());
307307
t.is(result.code, 1);
308+
t.is(result.stderr, `rm: cannot remove '${t.context.tmp}/rm/link_to_a_dir/': Not a directory`);
308309
// Both the link and original dir should remain, but contents are deleted
309310
t.truthy(fs.existsSync(`${t.context.tmp}/rm/link_to_a_dir`));
310311
t.truthy(fs.existsSync(`${t.context.tmp}/rm/a_dir`));

0 commit comments

Comments
 (0)
0