diff --git a/atomic_reactor/plugins/cachi2_postprocess.py b/atomic_reactor/plugins/cachi2_postprocess.py index bc0c4da4e..4f18e1a82 100644 --- a/atomic_reactor/plugins/cachi2_postprocess.py +++ b/atomic_reactor/plugins/cachi2_postprocess.py @@ -9,11 +9,14 @@ import json import os.path import shlex +import shutil from dataclasses import dataclass from pathlib import Path from shutil import copytree from typing import Any, Optional, List, Dict +import reflink + from atomic_reactor.constants import ( CACHITO_ENV_ARG_ALIAS, CACHITO_ENV_FILENAME, @@ -24,7 +27,7 @@ REMOTE_SOURCE_TARBALL_FILENAME, REMOTE_SOURCE_JSON_ENV_FILENAME, ) -from atomic_reactor.dirs import BuildDir +from atomic_reactor.dirs import BuildDir, reflink_copy from atomic_reactor.plugin import Plugin from atomic_reactor.utils.cachi2 import generate_request_json @@ -176,9 +179,18 @@ def inject_into_build_dir( created_dirs.append(dest_dir) # copy app and deps generated by cachito into build_dir - # TODO: reflink? - copytree(remote_source.sources_path/'app', dest_dir/'app', symlinks=True) - copytree(remote_source.sources_path/'deps', dest_dir/'deps', symlinks=True) + copy_method = shutil.copy2 + if reflink.supported_at(dest_dir): + copy_method = reflink_copy + self.log.debug( + "copy method used for cachi2 build_dir_injecting: %s", copy_method.__name__) + + copytree( + remote_source.sources_path/'app', dest_dir/'app', + symlinks=True, copy_function=copy_method) + copytree( + remote_source.sources_path/'deps', dest_dir/'deps', + symlinks=True, copy_function=copy_method) # Create cachito.env file with environment variables received from cachito request self.generate_cachito_env_file(dest_dir, remote_source.build_args)