~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: John Arbash Meinel
  • Date: 2005-12-01 17:11:25 UTC
  • mto: (1185.50.19 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1532.
  • Revision ID: john@arbash-meinel.com-20051201171125-5e1f0970246c4925
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
        else:
110
110
            raise BzrError("lstat/stat of (%r): %r" % (f, e))
111
111
 
112
 
def normalizepath(f):
113
 
    if hasattr(os.path, 'realpath'):
114
 
        F = os.path.realpath
115
 
    else:
116
 
        F = os.path.abspath
117
 
    [p,e] = os.path.split(f)
118
 
    if e == "" or e == "." or e == "..":
119
 
        return F(f)
120
 
    else:
121
 
        return os.path.join(F(p), e)
122
 
 
123
112
if os.name == "posix":
124
113
    # In Python 2.4.2 and older, os.path.abspath and os.path.realpath
125
114
    # choke on a Unicode string containing a relative path if
130
119
        return os.path.abspath(path.encode(_fs_enc)).decode(_fs_enc)
131
120
    def realpath(path):
132
121
        return os.path.realpath(path.encode(_fs_enc)).decode(_fs_enc)
 
122
    pathjoin = os.path.join
133
123
else:
134
124
    # We need to use the Unicode-aware os.path.abspath and
135
125
    # os.path.realpath on Windows systems.
136
 
    abspath = os.path.abspath
137
 
    realpath = os.path.realpath
 
126
    def abspath(path):
 
127
        return os.path.abspath(path).replace('\\', '/')
 
128
    def realpath(path):
 
129
        return os.path.realpath(path).replace('\\', '/')
 
130
    def pathjoin(*args):
 
131
        return os.path.join(*args).replace('\\', '/')
 
132
 
 
133
def normalizepath(f):
 
134
    if hasattr(os.path, 'realpath'):
 
135
        F = realpath
 
136
    else:
 
137
        F = abspath
 
138
    [p,e] = os.path.split(f)
 
139
    if e == "" or e == "." or e == "..":
 
140
        return F(f)
 
141
    else:
 
142
        return pathjoin(F(p), e)
 
143
 
138
144
 
139
145
def backup_file(fn):
140
146
    """Copy a file to a backup.
202
208
    The empty string as a dir name is taken as top-of-tree and matches 
203
209
    everything.
204
210
    
205
 
    >>> is_inside('src', os.path.join('src', 'foo.c'))
 
211
    >>> is_inside('src', pathjoin('src', 'foo.c'))
206
212
    True
207
213
    >>> is_inside('src', 'srccontrol')
208
214
    False
209
 
    >>> is_inside('src', os.path.join('src', 'a', 'a', 'a', 'foo.c'))
 
215
    >>> is_inside('src', pathjoin('src', 'a', 'a', 'a', 'foo.c'))
210
216
    True
211
217
    >>> is_inside('foo.c', 'foo.c')
212
218
    True
407
413
    for f in p:
408
414
        if (f == '..') or (f == None) or (f == ''):
409
415
            raise BzrError("sorry, %r not allowed in path" % f)
410
 
    return os.path.join(*p)
 
416
    return pathjoin(*p)
411
417
 
412
418
 
413
419
def appendpath(p1, p2):
414
420
    if p1 == '':
415
421
        return p2
416
422
    else:
417
 
        return os.path.join(p1, p2)
 
423
        return pathjoin(p1, p2)
418
424
    
419
425
 
420
426
def split_lines(s):