~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Aaron Bentley
  • Date: 2005-10-04 04:32:32 UTC
  • mfrom: (1185.12.6)
  • mto: (1185.12.13)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: aaron.bentley@utoronto.ca-20051004043231-40302a149769263b
merged my own changes

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.