Skip to content

Commit fbd88e6

Browse files
authored
Merge pull request #4921 from lexming/fix-remove-link
fix handling of broken symlinks in filetools.remove
2 parents 4c9e8ec + 7c1aa96 commit fbd88e6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

easybuild/tools/filetools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def remove(paths):
418418
_log.info("Removing %d files & directories", len(paths))
419419

420420
for path in paths:
421-
if os.path.isfile(path):
421+
if os.path.isfile(path) or os.path.islink(path):
422422
remove_file(path)
423423
elif os.path.isdir(path):
424424
remove_dir(path)

test/framework/filetools.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,12 +2555,24 @@ def test_remove(self):
25552555
"""Test remove_file, remove_dir and join remove functions."""
25562556
testfile = os.path.join(self.test_prefix, 'foo')
25572557
test_dir = os.path.join(self.test_prefix, 'test123')
2558+
test_link = os.path.join(self.test_prefix, 'foolink')
25582559

25592560
for remove_file_function in (ft.remove_file, ft.remove):
25602561
ft.write_file(testfile, 'bar')
25612562
self.assertExists(testfile)
2563+
# remove symlink
2564+
ft.symlink(testfile, test_link)
2565+
self.assertTrue(os.path.islink(test_link))
2566+
remove_file_function(test_link)
2567+
self.assertNotExists(test_link)
2568+
# remove file
25622569
remove_file_function(testfile)
25632570
self.assertNotExists(testfile)
2571+
# remove broken symlink
2572+
ft.symlink(testfile, test_link)
2573+
self.assertTrue(os.path.islink(test_link))
2574+
remove_file_function(test_link)
2575+
self.assertNotExists(test_link)
25642576

25652577
for remove_dir_function in (ft.remove_dir, ft.remove):
25662578
ft.mkdir(test_dir)

0 commit comments

Comments
 (0)