mercurial/pathutil.py
changeset 23602 a4679a74df14
parent 23139 e53f6b72a0e4
parent 23599 6dad422ecc5a
child 25011 7d6a507a4c53
equal deleted inserted replaced
23591:414374cfb531 23602:a4679a74df14
     1 import os, errno, stat
     1 import os, errno, stat
     2 
     2 
       
     3 import encoding
     3 import util
     4 import util
     4 from i18n import _
     5 from i18n import _
       
     6 
       
     7 def _lowerclean(s):
       
     8     return encoding.hfsignoreclean(s.lower())
     5 
     9 
     6 class pathauditor(object):
    10 class pathauditor(object):
     7     '''ensure that a filesystem path contains no banned components.
    11     '''ensure that a filesystem path contains no banned components.
     8     the following properties of a path are checked:
    12     the following properties of a path are checked:
     9 
    13 
    37         # AIX ignores "/" at end of path, others raise EISDIR.
    41         # AIX ignores "/" at end of path, others raise EISDIR.
    38         if util.endswithsep(path):
    42         if util.endswithsep(path):
    39             raise util.Abort(_("path ends in directory separator: %s") % path)
    43             raise util.Abort(_("path ends in directory separator: %s") % path)
    40         parts = util.splitpath(path)
    44         parts = util.splitpath(path)
    41         if (os.path.splitdrive(path)[0]
    45         if (os.path.splitdrive(path)[0]
    42             or parts[0].lower() in ('.hg', '.hg.', '')
    46             or _lowerclean(parts[0]) in ('.hg', '.hg.', '')
    43             or os.pardir in parts):
    47             or os.pardir in parts):
    44             raise util.Abort(_("path contains illegal component: %s") % path)
    48             raise util.Abort(_("path contains illegal component: %s") % path)
    45         if '.hg' in path.lower():
    49         # Windows shortname aliases
    46             lparts = [p.lower() for p in parts]
    50         for p in parts:
       
    51             if "~" in p:
       
    52                 first, last = p.split("~", 1)
       
    53                 if last.isdigit() and first.upper() in ["HG", "HG8B6C"]:
       
    54                     raise util.Abort(_("path contains illegal component: %s")
       
    55                                      % path)
       
    56         if '.hg' in _lowerclean(path):
       
    57             lparts = [_lowerclean(p.lower()) for p in parts]
    47             for p in '.hg', '.hg.':
    58             for p in '.hg', '.hg.':
    48                 if p in lparts[1:]:
    59                 if p in lparts[1:]:
    49                     pos = lparts.index(p)
    60                     pos = lparts.index(p)
    50                     base = os.path.join(*parts[:pos])
    61                     base = os.path.join(*parts[:pos])
    51                     raise util.Abort(_("path '%s' is inside nested repo %r")
    62                     raise util.Abort(_("path '%s' is inside nested repo %r")