mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-24 19:37:15 +00:00
Bug 1760886: Make mozfile.remove remove broken symlinks r=gbrown
Differential Revision: https://phabricator.services.mozilla.com/D141798
This commit is contained in:
parent
b9b8c7c39b
commit
5af4b01268
@ -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
|
||||
|
||||
"""
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user