diff --git a/testing/mozbase/mozfile/mozfile/mozfile.py b/testing/mozbase/mozfile/mozfile/mozfile.py index 694ab61b7232..e2a82eda22f0 100644 --- a/testing/mozbase/mozfile/mozfile/mozfile.py +++ b/testing/mozbase/mozfile/mozfile/mozfile.py @@ -231,7 +231,7 @@ def remove(path): _call_with_windows_retry(os.chmod, (path, mode)) - if not os.path.exists(path): + if not os.path.lexists(path): return """ diff --git a/testing/mozbase/mozfile/tests/test_move_remove.py b/testing/mozbase/mozfile/tests/test_move_remove.py index 1ef05a721f53..5229fa0f1d34 100644 --- a/testing/mozbase/mozfile/tests/test_move_remove.py +++ b/testing/mozbase/mozfile/tests/test_move_remove.py @@ -181,6 +181,26 @@ class MozfileRemoveTestCase(unittest.TestCase): self.assertFalse(os.path.exists(symlink_path)) self.assertTrue(os.path.exists(file_path)) + @unittest.skipIf(mozinfo.isWin, "Symlinks are not supported on Windows") + def test_remove_broken_symlink(self): + """Test removing a folder with an contained symlink""" + file_path = os.path.join(self.tempdir, "readonly.txt") + working_link = os.path.join(self.tempdir, "link_to_readonly.txt") + broken_link = os.path.join(self.tempdir, "broken_link") + os.symlink(file_path, working_link) + os.symlink(os.path.join(self.tempdir, "broken.txt"), broken_link) + + self.assertTrue(os.path.exists(file_path)) + self.assertTrue(os.path.islink(working_link)) + self.assertTrue(os.path.islink(broken_link)) + + mozfile.remove(working_link) + self.assertFalse(os.path.lexists(working_link)) + self.assertTrue(os.path.exists(file_path)) + + mozfile.remove(broken_link) + self.assertFalse(os.path.lexists(broken_link)) + @unittest.skipIf( mozinfo.isWin or not os.geteuid(), "Symlinks are not supported on Windows and cannot run test as root",