diff --git a/easybuild/tools/filetools.py b/easybuild/tools/filetools.py index 8e891a0c5a..4c99b97ecb 100644 --- a/easybuild/tools/filetools.py +++ b/easybuild/tools/filetools.py @@ -418,7 +418,7 @@ def remove(paths): _log.info("Removing %d files & directories", len(paths)) for path in paths: - if os.path.isfile(path): + if os.path.isfile(path) or os.path.islink(path): remove_file(path) elif os.path.isdir(path): remove_dir(path) diff --git a/test/framework/filetools.py b/test/framework/filetools.py index 3f30aa88dd..7067186df9 100644 --- a/test/framework/filetools.py +++ b/test/framework/filetools.py @@ -2555,12 +2555,24 @@ def test_remove(self): """Test remove_file, remove_dir and join remove functions.""" testfile = os.path.join(self.test_prefix, 'foo') test_dir = os.path.join(self.test_prefix, 'test123') + test_link = os.path.join(self.test_prefix, 'foolink') for remove_file_function in (ft.remove_file, ft.remove): ft.write_file(testfile, 'bar') self.assertExists(testfile) + # remove symlink + ft.symlink(testfile, test_link) + self.assertTrue(os.path.islink(test_link)) + remove_file_function(test_link) + self.assertNotExists(test_link) + # remove file remove_file_function(testfile) self.assertNotExists(testfile) + # remove broken symlink + ft.symlink(testfile, test_link) + self.assertTrue(os.path.islink(test_link)) + remove_file_function(test_link) + self.assertNotExists(test_link) for remove_dir_function in (ft.remove_dir, ft.remove): ft.mkdir(test_dir)