mercurial/util.py
changeset 1415 c6e6ca96a033
parent 1413 1c64c628d15f
child 1420 b32b3509c7ab
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -310,6 +310,13 @@ def rename(src, dst):
         os.unlink(dst)
         os.rename(src, dst)
 
+def unlink(f):
+    """unlink and remove the directory if it is empty"""
+    os.unlink(f)
+    # try removing directories that might now be empty
+    try: os.removedirs(os.path.dirname(f))
+    except: pass
+
 def copyfiles(src, dst, hardlink=None):
     """Copy a directory tree using hardlinks if possible"""