~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Robert Collins
  • Date: 2005-09-07 10:47:36 UTC
  • mto: (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050907104736-8e592b72108c577d
symlink support updated to work

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
    else:
79
79
        raise BzrError('invalid file kind %r' % kind)
80
80
 
 
81
def lexists(f):
 
82
    try:
 
83
        if hasattr(os, 'lstat'):
 
84
            os.lstat(f)
 
85
        else:
 
86
            os.stat(f)
 
87
        return True
 
88
    except OSError,e:
 
89
        if e.errno == errno.ENOENT:
 
90
            return False;
 
91
        else:
 
92
            raise BzrError("lstat/stat of (%r): %r" % (f, e))
81
93
 
 
94
def normalizepath(f):
 
95
    if hasattr(os.path, 'realpath'):
 
96
        F = os.path.realpath
 
97
    else:
 
98
        F = os.path.abspath
 
99
    [p,e] = os.path.split(f)
 
100
    if e == "" or e == "." or e == "..":
 
101
        return F(f)
 
102
    else:
 
103
        return os.path.join(F(p), e)
 
104
    
82
105
 
83
106
def backup_file(fn):
84
107
    """Copy a file to a backup.
134
157
    except OSError:
135
158
        return False
136
159
 
 
160
def islink(f):
 
161
    """True if f is a symlink."""
 
162
    try:
 
163
        return S_ISLNK(os.lstat(f)[ST_MODE])
 
164
    except OSError:
 
165
        return False
137
166
 
138
167
def is_inside(dir, fname):
139
168
    """True if fname is inside dir.