protected function addCopies(PackageInterface $package, $targetRoot, array $pathMap, $mode = self::DUPLICATE_FAIL)
    {
        if (empty($pathMap)) {
            return;
        }

        $packageRoot = $this->getInstallPath($package);
        $actions     = [];

        // Check the file map first and make sure nothing exists.
        foreach ($pathMap as $sourcePath => $targetPath) {
            $source = $this->filesystem->normalizePath($packageRoot . (empty($sourcePath) ? '' : ('/'.$sourcePath)));
            $target = $this->filesystem->normalizePath($targetRoot . '/' . $targetPath);

            if (!is_readable($source)) {
                throw new \RuntimeException(
                    sprintf('Installation source "%s" does not exist', $sourcePath)
                );
            }

            if (file_exists($target) && !$this->canAddTarget($target, $mode)) {
                continue;
            }

            $actions[$source] = $target;
        }

        // Only actually create the links if the checks are successful to prevent orphans.
        foreach ($actions as $source => $target) {
            $this->logCopy($source, $target);
            $this->copyRecursive($source, $target);
        }
    }