Commit a2172850 authored by Julien Muchembled's avatar Julien Muchembled

default: clean up copyTree/extract and preserve symlinks

parent 30e20b79
......@@ -29,14 +29,15 @@ import linecache
import logging
import os
from platform import uname
import setuptools
import shlex
import shutil
import subprocess
import sys
import tempfile
from setuptools import archive_util
import zc.buildout
from .. import is_true, rmtree, EnvironMixin, Shared
from ..downloadunpacked import extraction_drivers, patched_extraction_drivers
ARCH_MAP = {
'i386': 'x86',
......@@ -161,9 +162,13 @@ class Script(EnvironMixin):
def extract(self, path):
extract_dir = tempfile.mkdtemp(self.name)
self.logger.debug('Created working directory %r' % extract_dir)
setuptools.archive_util.unpack_archive(path, extract_dir)
self.cleanup_list.append(extract_dir)
self.logger.debug('Created working directory: %s', extract_dir)
try:
archive_util.extraction_drivers = patched_extraction_drivers
archive_util.unpack_archive(path, extract_dir)
finally:
archive_util.extraction_drivers = extraction_drivers
return extract_dir
def pipeCommand(self, command_list_list, *args, **kwargs):
......@@ -190,7 +195,7 @@ class Script(EnvironMixin):
raise zc.buildout.UserError('Failed while running:\n '
+ '\n '.join(failed))
def copyTree(self, origin, destination, ignore_dir_list=None):
def copyTree(self, origin, destination, ignore_dir_list=()):
"""Recursively Copy directory.
ignore_dir_list is a list of relative directories you want to exclude.
......@@ -201,21 +206,13 @@ class Script(EnvironMixin):
# that does not belong to us.
if os.path.exists(destination):
raise shutil.Error('Destination already exists: %s' % destination)
self.logger.info("Copying %s to %s" % (origin, destination))
if ignore_dir_list is None:
ignore_dir_list = []
self.logger.info("Copying %r to %r", origin, destination)
try:
shutil.copytree(origin, destination,
shutil.copytree(origin, destination, symlinks=True,
ignore=lambda src, names: ignore_dir_list)
except (shutil.Error, OSError) as error:
# Cleanup in case of failure
try:
shutil.rmtree(destination, ignore_errors=True)
except (shutil.Error, OSError) as strerror:
self.logger.error("Error occurred when cleaning after error: %s",
strerror)
raise error
return True
except:
self.cleanup_list.append(destination)
raise
cleanup_dir_list = cleanup_file_list = property(
lambda self: self.cleanup_list)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment