Commit a2172850 authored by Julien Muchembled's avatar Julien Muchembled

default: clean up copyTree/extract and preserve symlinks

parent 30e20b79
Pipeline #17532 failed with stage
in 0 seconds
...@@ -29,14 +29,15 @@ import linecache ...@@ -29,14 +29,15 @@ import linecache
import logging import logging
import os import os
from platform import uname from platform import uname
import setuptools
import shlex import shlex
import shutil import shutil
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
from setuptools import archive_util
import zc.buildout import zc.buildout
from .. import is_true, rmtree, EnvironMixin, Shared from .. import is_true, rmtree, EnvironMixin, Shared
from ..downloadunpacked import extraction_drivers, patched_extraction_drivers
ARCH_MAP = { ARCH_MAP = {
'i386': 'x86', 'i386': 'x86',
...@@ -161,9 +162,13 @@ class Script(EnvironMixin): ...@@ -161,9 +162,13 @@ class Script(EnvironMixin):
def extract(self, path): def extract(self, path):
extract_dir = tempfile.mkdtemp(self.name) 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.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 return extract_dir
def pipeCommand(self, command_list_list, *args, **kwargs): def pipeCommand(self, command_list_list, *args, **kwargs):
...@@ -190,7 +195,7 @@ class Script(EnvironMixin): ...@@ -190,7 +195,7 @@ class Script(EnvironMixin):
raise zc.buildout.UserError('Failed while running:\n ' raise zc.buildout.UserError('Failed while running:\n '
+ '\n '.join(failed)) + '\n '.join(failed))
def copyTree(self, origin, destination, ignore_dir_list=None): def copyTree(self, origin, destination, ignore_dir_list=()):
"""Recursively Copy directory. """Recursively Copy directory.
ignore_dir_list is a list of relative directories you want to exclude. ignore_dir_list is a list of relative directories you want to exclude.
...@@ -201,21 +206,13 @@ class Script(EnvironMixin): ...@@ -201,21 +206,13 @@ class Script(EnvironMixin):
# that does not belong to us. # that does not belong to us.
if os.path.exists(destination): if os.path.exists(destination):
raise shutil.Error('Destination already exists: %s' % destination) raise shutil.Error('Destination already exists: %s' % destination)
self.logger.info("Copying %s to %s" % (origin, destination)) self.logger.info("Copying %r to %r", origin, destination)
if ignore_dir_list is None:
ignore_dir_list = []
try: try:
shutil.copytree(origin, destination, shutil.copytree(origin, destination, symlinks=True,
ignore=lambda src, names: ignore_dir_list) ignore=lambda src, names: ignore_dir_list)
except (shutil.Error, OSError) as error: except:
# Cleanup in case of failure self.cleanup_list.append(destination)
try: raise
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
cleanup_dir_list = cleanup_file_list = property( cleanup_dir_list = cleanup_file_list = property(
lambda self: self.cleanup_list) 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