Mercurial > public > mercurial-scm > hg
comparison mercurial/scmutil.py @ 24689:ca3a90096c95
vfs: add rmtree
This duplicates "onerror()" function from "svnsubrepo.remove()" for
equivalence of replacing in subsequent patch.
This "onerror()" function for "shutil.rmtree()" was introduced by
92b0d669637f, which avoids failure of removing svn repository on
Windows.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 11 Apr 2015 00:47:09 +0900 |
parents | 21e1ece30f8c |
children | 0d28b0df77ea |
comparison
equal
deleted
inserted
replaced
24688:897a0715ee71 | 24689:ca3a90096c95 |
---|---|
8 from i18n import _ | 8 from i18n import _ |
9 from mercurial.node import nullrev | 9 from mercurial.node import nullrev |
10 import util, error, osutil, revset, similar, encoding, phases | 10 import util, error, osutil, revset, similar, encoding, phases |
11 import pathutil | 11 import pathutil |
12 import match as matchmod | 12 import match as matchmod |
13 import os, errno, re, glob, tempfile | 13 import os, errno, re, glob, tempfile, shutil, stat |
14 | 14 |
15 if os.name == 'nt': | 15 if os.name == 'nt': |
16 import scmwindows as scmplatform | 16 import scmwindows as scmplatform |
17 else: | 17 else: |
18 import scmposix as scmplatform | 18 import scmposix as scmplatform |
313 def rename(self, src, dst): | 313 def rename(self, src, dst): |
314 return util.rename(self.join(src), self.join(dst)) | 314 return util.rename(self.join(src), self.join(dst)) |
315 | 315 |
316 def readlink(self, path): | 316 def readlink(self, path): |
317 return os.readlink(self.join(path)) | 317 return os.readlink(self.join(path)) |
318 | |
319 def rmtree(self, path=None, ignore_errors=False, forcibly=False): | |
320 """Remove a directory tree recursively | |
321 | |
322 If ``forcibly``, this tries to remove READ-ONLY files, too. | |
323 """ | |
324 if forcibly: | |
325 def onerror(function, path, excinfo): | |
326 if function is not os.remove: | |
327 raise | |
328 # read-only files cannot be unlinked under Windows | |
329 s = os.stat(path) | |
330 if (s.st_mode & stat.S_IWRITE) != 0: | |
331 raise | |
332 os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE) | |
333 os.remove(path) | |
334 else: | |
335 onerror = None | |
336 return shutil.rmtree(self.join(path), | |
337 ignore_errors=ignore_errors, onerror=onerror) | |
318 | 338 |
319 def setflags(self, path, l, x): | 339 def setflags(self, path, l, x): |
320 return util.setflags(self.join(path), l, x) | 340 return util.setflags(self.join(path), l, x) |
321 | 341 |
322 def stat(self, path=None): | 342 def stat(self, path=None): |