From bd8fef3767985e077acf345a7d2992b56e77a5f7 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Fri, 1 Feb 2013 12:35:59 +1100 Subject: [PATCH] Improve mkdir and rmdir. Testing on various hosts shows a few problems. These changes seem to help resolve them. --- source-builder/sb/build.py | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/source-builder/sb/build.py b/source-builder/sb/build.py index 3de616a..e4595b5 100644 --- a/source-builder/sb/build.py +++ b/source-builder/sb/build.py @@ -44,6 +44,14 @@ import path # version = '0.1' +def removeall(path): + + def _onerror(function, path, excinfo): + print 'removeall error: (%r) %s' % (function, path) + + shutil.rmtree(path, onerror = _onerror) + return + def _notice(opts, text): if not opts.quiet() and not log.default.has_stdout(): print text @@ -107,22 +115,27 @@ class build: self._output('removing: %s' % (path.host(rmpath))) if not self.opts.dry_run(): if path.exists(rmpath): - try: - shutil.rmtree(path.host(rmpath)) - except IOError, err: - raise error.error('error removing: %s' % (rmpath)) - except WindowsError, err: - _notice(self.opts, 'warning: cannot remove: %s' % (rmpath)) + removeall(rmpath) def mkdir(self, mkpath): self._output('making dir: %s' % (path.host(mkpath))) if not self.opts.dry_run(): - try: - os.makedirs(path.host(mkpath)) - except IOError, err: - _notice(self.opts, 'warning: cannot make directory: %s' % (mkpath)) - except WindowsError, err: - _notice(self.opts, 'warning: cannot make directory: %s' % (mkpath)) + if os.name == 'nt': + try: + os.makedirs(path.host(mkpath)) + except IOError, err: + _notice(self.opts, 'warning: cannot make directory: %s' % (mkpath)) + except OSError, err: + _notice(self.opts, 'warning: cannot make directory: %s' % (mkpath)) + except WindowsError, err: + _notice(self.opts, 'warning: cannot make directory: %s' % (mkpath)) + else: + try: + os.makedirs(path.host(mkpath)) + except IOError, err: + _notice(self.opts, 'warning: cannot make directory: %s' % (mkpath)) + except OSError, err: + _notice(self.opts, 'warning: cannot make directory: %s' % (mkpath)) def get_file(self, url, local): if local is None: