~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Aaron Bentley
  • Date: 2005-10-03 19:50:36 UTC
  • mfrom: (1399)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: abentley@panoramicfeedback.com-20051003195036-28dbd56f0e852b08
Merged latest from Robert Collins

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
    else:
96
96
        raise BzrError('invalid file kind %r' % kind)
97
97
 
 
98
def lexists(f):
 
99
    try:
 
100
        if hasattr(os, 'lstat'):
 
101
            os.lstat(f)
 
102
        else:
 
103
            os.stat(f)
 
104
        return True
 
105
    except OSError,e:
 
106
        if e.errno == errno.ENOENT:
 
107
            return False;
 
108
        else:
 
109
            raise BzrError("lstat/stat of (%r): %r" % (f, e))
 
110
 
 
111
def normalizepath(f):
 
112
    if hasattr(os.path, 'realpath'):
 
113
        F = os.path.realpath
 
114
    else:
 
115
        F = os.path.abspath
 
116
    [p,e] = os.path.split(f)
 
117
    if e == "" or e == "." or e == "..":
 
118
        return F(f)
 
119
    else:
 
120
        return os.path.join(F(p), e)
 
121
    
98
122
 
99
123
def backup_file(fn):
100
124
    """Copy a file to a backup.
141
165
    except OSError:
142
166
        return False
143
167
 
 
168
def islink(f):
 
169
    """True if f is a symlink."""
 
170
    try:
 
171
        return S_ISLNK(os.lstat(f)[ST_MODE])
 
172
    except OSError:
 
173
        return False
144
174
 
145
175
def is_inside(dir, fname):
146
176
    """True if fname is inside dir.