Skip to content

Commit 8326823

Browse files
[lit] Add support for deleting symlinks to directories without -r
Before this change, rm would assume that a symlink to a directory was actually a directory and require the recursive flag to be passed, differing from other shells. Given the change in lit is about the same length as the test change would be (minus tests), I think it makes sense to just support this in the internal shell. Reviewers: cmtice, petrhosek, ilovepi Reviewed By: petrhosek, cmtice, ilovepi Pull Request: #158464
1 parent 8d6470f commit 8326823

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,9 @@ def on_rm_error(func, path, exc_info):
516516
if force and not os.path.exists(path):
517517
continue
518518
try:
519-
if os.path.isdir(path):
519+
if os.path.islink(path):
520+
os.remove(path)
521+
elif os.path.isdir(path):
520522
if not recursive:
521523
stderr.write("Error: %s is a directory\n" % path)
522524
exitCode = 1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import lit.formats
2+
3+
config.name = "shtest-shell"
4+
config.suffixes = [".txt"]
5+
config.test_format = lit.formats.ShTest()
6+
config.test_source_root = None
7+
config.test_exec_root = None
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Check that we can delete a symlink to a folder without -r
2+
#
3+
# RUN: mkdir %t.dir
4+
# RUN: ln -s %t.dir %t.symlink
5+
# RUN: rm %t.symlink
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Check that the internal shell builtins correctly handle cases involving
2+
# symlinks.
3+
4+
# REQUIRES: symlinks
5+
# RUN: echo test
6+
# RUN: %{lit} -v %{inputs}/shtest-shell-symlinks | FileCheck %s
7+
8+
# CHECK: -- Testing: 1 test{{.*}}
9+
# CHECK: PASS: shtest-shell :: rm-symlink-dir.txt

0 commit comments

Comments
 (0)