/**
     * If composer tries to install into a non-empty folder, we risk to effectively erase an existing installation.
     * This is not a composer limitation we can fix - it happens because composer might be using git to download the
     * sources, and git can not clone a repo into a non-empty folder.
     *
     * To prevent this, we adopt the following strategy:
     * - install in a separate, temporary directory
     * - then move over the installed files copying on top of the existing installation
     *
     * @param InstalledRepositoryInterface $repo
     * @param PackageInterface $package
     */
    public function install( InstalledRepositoryInterface $repo, PackageInterface $package )
    {
        $downloadPath = $this->getInstallPath( $package );
        $fileSystem = new Filesystem();
        if ( !is_dir( $downloadPath ) || $fileSystem->isDirEmpty( $downloadPath ) )
        {
            return parent::install( $repo, $package );
        }

        $actualLegacyDir = $this->ezpublishLegacyDir;
        $this->ezpublishLegacyDir = $this->generateTempDirName();
        if ( $this->io->isVerbose() )
        {
            $this->io->write( "Installing in temporary directory." );
        }

        parent::install( $repo, $package );

        /// @todo the following function does not warn of any failures in copying stuff over. We should probably fix it...
        if ( $this->io->isVerbose() )
        {
            $this->io->write( "Updating new code over existing installation." );
        }
        $fileSystem->copyThenRemove( $this->ezpublishLegacyDir, $actualLegacyDir );

        // if parent::install installed binaries, then the resulting shell/bat stubs will not work. We have to redo them
        $this->removeBinaries( $package );
        $this->ezpublishLegacyDir = $actualLegacyDir;
        $this->installBinaries( $package );
    }
 public function getInstallPath(PackageInterface $package)
 {
     $extra = $package->getExtra();
     if (isset($extra['ezpublish-legacy-extension-name'])) {
         $extensionName = $extra['ezpublish-legacy-extension-name'];
     } else {
         list($vendor, $extensionName) = explode('/', $package->getPrettyName(), 2);
     }
     $extensionInstallPath = parent::getInstallPath($package) . '/extension/' . $extensionName;
     if ($this->io->isVerbose()) {
         $this->io->write("eZ Publish legacy extension directory is '{$extensionInstallPath}'");
     }
     return $extensionInstallPath;
 }