~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-22 07:28:09 UTC
  • mfrom: (1551.2.56 win32fixes)
  • Revision ID: pqm@pqm.ubuntu.com-20060422072809-b06e742274a4e9f4
Misc fixes for win32

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
                           BzrBadParameterNotUnicode,
36
36
                           NoSuchFile,
37
37
                           PathNotChild,
 
38
                           IllegalPath,
38
39
                           )
39
40
from bzrlib.trace import mutter
40
41
 
181
182
dirname = os.path.dirname
182
183
basename = os.path.basename
183
184
 
 
185
MIN_ABS_PATHLENGTH = 1
 
186
 
184
187
if os.name == "posix":
185
188
    # In Python 2.4.2 and older, os.path.abspath and os.path.realpath
186
189
    # choke on a Unicode string containing a relative path if
217
220
    def rename(old, new):
218
221
        fancy_rename(old, new, rename_func=os.rename, unlink_func=os.unlink)
219
222
 
 
223
    MIN_ABS_PATHLENGTH = 3
220
224
 
221
225
def normalizepath(f):
222
226
    if hasattr(os.path, 'realpath'):
599
603
    on string prefixes, assuming that '/u' is a prefix of '/u2'.  This
600
604
    avoids that problem.
601
605
    """
602
 
    if sys.platform != "win32":
603
 
        minlength = 1
604
 
    else:
605
 
        minlength = 3
606
 
    assert len(base) >= minlength, ('Length of base must be equal or exceed the'
607
 
        ' platform minimum length (which is %d)' % minlength)
 
606
 
 
607
    assert len(base) >= MIN_ABS_PATHLENGTH, ('Length of base must be equal or'
 
608
        ' exceed the platform minimum length (which is %d)' % 
 
609
        MIN_ABS_PATHLENGTH)
608
610
    rp = abspath(path)
609
611
 
610
612
    s = []
657
659
 
658
660
def supports_executable():
659
661
    return sys.platform != "win32"
 
662
 
 
663
 
 
664
def strip_trailing_slash(path):
 
665
    """Strip trailing slash, except for root paths.
 
666
    The definition of 'root path' is platform-dependent.
 
667
    """
 
668
    if len(path) != MIN_ABS_PATHLENGTH and path[-1] == '/':
 
669
        return path[:-1]
 
670
    else:
 
671
        return path
 
672
 
 
673
 
 
674
_validWin32PathRE = re.compile(r'^([A-Za-z]:[/\\])?[^:<>*"?\|]*$')
 
675
 
 
676
 
 
677
def check_legal_path(path):
 
678
    """Check whether the supplied path is legal.  
 
679
    This is only required on Windows, so we don't test on other platforms
 
680
    right now.
 
681
    """
 
682
    if sys.platform != "win32":
 
683
        return
 
684
    if _validWin32PathRE.match(path) is None:
 
685
        raise IllegalPath(path)