~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-05-05 08:15:28 UTC
  • mfrom: (1692.7.8 bzr.mbp.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060505081528-8c0368b718fd7933
(mbp,alexander) rmtree forces deletion of readonly files on win32

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import os
25
25
import re
26
26
import sha
 
27
import shutil
27
28
import string
28
29
import sys
29
30
import time
171
172
            else:
172
173
                rename_func(tmp_name, new)
173
174
 
174
 
# Default is to just use the python builtins
 
175
# Default is to just use the python builtins, but these can be rebound on
 
176
# particular platforms.
175
177
abspath = os.path.abspath
176
178
realpath = os.path.realpath
177
179
pathjoin = os.path.join
181
183
rename = os.rename
182
184
dirname = os.path.dirname
183
185
basename = os.path.basename
 
186
rmtree = shutil.rmtree
184
187
 
185
188
MIN_ABS_PATHLENGTH = 1
186
189
 
222
225
 
223
226
    MIN_ABS_PATHLENGTH = 3
224
227
 
 
228
    def _win32_delete_readonly(function, path, excinfo):
 
229
        """Error handler for shutil.rmtree function [for win32]
 
230
        Helps to remove files and dirs marked as read-only.
 
231
        """
 
232
        type_, value = excinfo[:2]
 
233
        if function in (os.remove, os.rmdir) \
 
234
            and type_ == OSError \
 
235
            and value.errno == errno.EACCES:
 
236
            bzrlib.osutils.make_writable(path)
 
237
            function(path)
 
238
        else:
 
239
            raise
 
240
 
 
241
    def rmtree(path, ignore_errors=False, onerror=_win32_delete_readonly):
 
242
        """Replacer for shutil.rmtree: could remove readonly dirs/files"""
 
243
        return shutil.rmtree(path, ignore_errors, onerror)
 
244
 
 
245
 
225
246
def normalizepath(f):
226
247
    if hasattr(os.path, 'realpath'):
227
248
        F = realpath