Commits

Joel Rosdahl committed eb64462

Fix Path.remove and Path.rmtree for broken symlinks

  • Participants
  • Parent commits 74b4a17

Comments (0)

Files changed (3)

 tip
+ - Fix Path.remove and Path.rmtree for broken symlinks.
 
 0.2.1, released 2008-05-19 by MSO
  - Delete spurious references to deleted ``unipath.platform`` package.
             os.rmdir(self)
 
     def remove(self):
-        if self.exists():
+        if self.lexists():
             os.remove(self)
 
     def rename(self, new, parents=False):
            doesn't exist, do nothing.
            If you're looking for a 'rmtree' method, this is what you want.
         """
-        if self.isfile():
+        if self.isfile() or self.islink():
            os.remove(self)
         elif self.isdir():
            shutil.rmtree(self)
         assert not self.a_file.exists()
         self.missing.remove()  # Removing a nonexistent file should succeed.
 
+    if hasattr(os, 'symlink'):
+        def test_remove_broken_symlink(self):
+            symlink = Path(self.d, "symlink")
+            symlink.write_link("broken")
+            assert symlink.lexists()
+            symlink.remove()
+            assert not symlink.lexists()
+
+        def test_rmtree_broken_symlink(self):
+            symlink = Path(self.d, "symlink")
+            symlink.write_link("broken")
+            assert symlink.lexists()
+            symlink.rmtree()
+            assert not symlink.lexists()
+
     def test_rename(self):
         a_file = self.a_file
         b_file = Path(a_file.parent, "b_file")