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
        if( method_exists($this,'removeBinaries') )
        {
            $this->removeBinaries( $package );
        }
        else
        {
            $this->binaryInstaller->removeBinaries( $package );
        }

        $this->ezpublishLegacyDir = $actualLegacyDir;
        if( method_exists($this,'installBinaries') )
        {
            $this->installBinaries( $package );
        }
        else
        {
            $this->binaryInstaller->installBinaries( $package, $this->getInstallPath( $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
        if( method_exists($this,'removeBinaries') )
        {
            $this->removeBinaries( $package );
        }
        else
        {
            $this->binaryInstaller->removeBinaries( $package );
        }

        $this->ezpublishLegacyDir = $actualLegacyDir;
        if( method_exists($this,'installBinaries') )
        {
            $this->installBinaries( $package );
        }
        else
        {
            $this->binaryInstaller->installBinaries( $package, $this->getInstallPath( $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 if ( method_exists ( $ this , 'removeBinaries' ) ) { $ this -> removeBinaries ( $ package ) ; } else { $ this -> binaryInstaller -> removeBinaries ( $ package ) ; } $ this -> ezpublishLegacyDir = $ actualLegacyDir ; if ( method_exists ( $ this , 'installBinaries' ) ) { $ this -> installBinaries ( $ package ) ; } else { $ this -> binaryInstaller -> installBinaries ( $ package , $ this -> getInstallPath ( $ package ) ) ; } }
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
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 .