[PATCH 5 of 7 VFS] util: add removedirs as platform depending function

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Apr 10 10:54:27 CDT 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1428680829 -32400
#      Sat Apr 11 00:47:09 2015 +0900
# Node ID 633efbe1f1f387191d2633c83f2159c116f0143c
# Parent  32763865ec3c39afd639714865e8f0d9f358694e
util: add removedirs as platform depending function

According to fa901423ac23 introducing "windows._removedirs()":

    If a hg repository including working directory is a reparse point
    (directory symlinked or a junction point), then using
    os.removedirs will remove the reparse point erroneously.

"windows._removedirs()" should be used instead of "os.removedirs()" on
Windows.

This patch adds "removedirs" as platform depending function to replace
"os.removedirs()" invocations for portability and safety

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -16,6 +16,7 @@ samestat = os.path.samestat
 oslink = os.link
 unlink = os.unlink
 rename = os.rename
+removedirs = os.removedirs
 expandglobs = False
 
 umask = os.umask(0)
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -59,6 +59,7 @@ posixfile = platform.posixfile
 quotecommand = platform.quotecommand
 readpipe = platform.readpipe
 rename = platform.rename
+removedirs = platform.removedirs
 samedevice = platform.samedevice
 samefile = platform.samefile
 samestat = platform.samestat
diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -270,7 +270,7 @@ def groupname(gid=None):
     If gid is None, return the name of the current group."""
     return None
 
-def _removedirs(name):
+def removedirs(name):
     """special version of os.removedirs that does not remove symlinked
     directories or junction points if they actually contain files"""
     if osutil.listdir(name):
@@ -297,7 +297,7 @@ def unlinkpath(f, ignoremissing=False):
             raise
     # try removing directories that might now be empty
     try:
-        _removedirs(os.path.dirname(f))
+        removedirs(os.path.dirname(f))
     except OSError:
         pass
 


More information about the Mercurial-devel mailing list